Class: RuboCop::Cop::Minitest::RefutePathExists

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/minitest/refute_path_exists.rb

Overview

Enforces the test to use ‘refute_path_exists` instead of using `refute(File.exist?(path))`.

Examples:

# bad
refute(File.exist?(path))
refute(File.exist?(path), 'message')

# good
refute_path_exists(path)
refute_path_exists(path, 'message')

Constant Summary collapse

MSG =
'Prefer using `%<good_method>s`.'
RESTRICT_ON_SEND =
%i[refute].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/minitest/refute_path_exists.rb', line 30

def on_send(node)
  refute_file_exists(node) do |path, failure_message|
    failure_message = failure_message.first
    good_method = build_good_method(node, path, failure_message)
    message = format(MSG, good_method: good_method)

    add_offense(node, message: message) do |corrector|
      corrector.replace(node.loc.selector, 'refute_path_exists')
      corrector.replace(node.first_argument, path.source)
    end
  end
end