class RuboCop::Cop::Minitest::RefutePathExists
This cop enforces the test to use `refute_path_exists` instead of using `refute(File.exist?(path))`.
@example
# bad refute(File.exist?(path)) refute(File.exist?(path), 'message') # good refute_path_exists(path) refute_path_exists(path, 'message')
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/minitest/refute_path_exists.rb, line 31 def on_send(node) refute_file_exists(node) do |path, failure_message| failure_message = failure_message.first good_method = build_good_method(path, failure_message) message = format(MSG, good_method: good_method, bad_method: node.source) add_offense(node, message: message) do |corrector| corrector.replace(node, good_method) end end end
Private Instance Methods
build_good_method(path, message)
click to toggle source
# File lib/rubocop/cop/minitest/refute_path_exists.rb, line 45 def build_good_method(path, message) args = [path.source, message&.source].compact.join(', ') "refute_path_exists(#{args})" end