Skip to content

Commit

Permalink
Fix a false positive for Minitest/UselessAssertion when using comma…
Browse files Browse the repository at this point in the history
…nd execution
  • Loading branch information
fatkodima committed Jan 29, 2023
1 parent c4a7bdb commit 0c52ec4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_useless_assertion_for_commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#237](https://github.com/rubocop/rubocop-minitest/pull/237): Fix a false positive for `Minitest/UselessAssertion` when using command execution. ([@fatkodima][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/useless_assertion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def offense?(node)

case node.method_name
when *SINGLE_ASSERTION_ARGUMENT_METHODS
actual.nil? && expected&.literal?
actual.nil? && expected&.literal? && !expected.xstr_type?
when *TWO_ASSERTION_ARGUMENTS_METHODS
return false unless expected || actual
return false if expected.source != actual.source
Expand Down
7 changes: 7 additions & 0 deletions test/rubocop/cop/minitest/useless_assertion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class UselessAssertionTest < Minitest::Test
#{matcher} false, "My message"
RUBY
end

define_method("test_#{matcher}_no_offenses_when_executing_command") do
assert_no_offenses(<<~RUBY)
#{matcher} `ls`
#{matcher} %x{ls}
RUBY
end
end

%i[
Expand Down

0 comments on commit 0c52ec4

Please sign in to comment.