Skip to content

Commit

Permalink
Merge pull request #144 from koic/fix_error_for_minitest_literal_as_a…
Browse files Browse the repository at this point in the history
…ctual_argument

[Fix #143] Fix an error for `Minitest/LiteralAsActualArgumentTest`
  • Loading branch information
koic authored Sep 24, 2021
2 parents 292df25 + 630a7f3 commit a666891
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#143](https://github.com/rubocop/rubocop-minitest/issues/143): Fix an error for `Minitest/LiteralAsActualArgumentTest` when expected and actual arguments are literals. ([@koic][])

## 0.15.0 (2021-08-09)

### New features
Expand Down
9 changes: 4 additions & 5 deletions lib/rubocop/cop/minitest/literal_as_actual_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ class LiteralAsActualArgument < Base
def on_send(node)
return unless node.method?(:assert_equal)

actual = node.arguments[1]
expected, actual, message = *node.arguments
return unless actual&.recursive_basic_literal?
return if expected.recursive_basic_literal?

add_offense(all_arguments_range(node)) do |corrector|
autocorrect(corrector, node)
autocorrect(corrector, node, expected, actual, message)
end
end

def autocorrect(corrector, node)
expected, actual, message = *node.arguments

def autocorrect(corrector, node, expected, actual, message)
new_actual_source = if actual.hash_type? && !actual.braces?
"{#{actual.source}}"
else
Expand Down
10 changes: 10 additions & 0 deletions test/rubocop/cop/minitest/literal_as_actual_argument_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ def test_do_something
end
RUBY
end

def test_does_not_register_offense_when_expected_and_actual_are_basic_literals
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_do_something
assert_equal 0, 1, 'message'
end
end
RUBY
end
end

0 comments on commit a666891

Please sign in to comment.