Skip to content

Commit

Permalink
Merge pull request #285 from koic/fix_an_error_for_minitest_multiple_…
Browse files Browse the repository at this point in the history
…assertions

[Fix #283] Fix an error for `Minitest/MultipleAssertions`
  • Loading branch information
koic committed Dec 22, 2023
2 parents 9335ecb + fba823a commit b11fd1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_minitest_multiple_assertions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#283](https://github.com/rubocop/rubocop-minitest/issues/283): Fix an error for `Minitest/MultipleAssertions` when using `||` assigning a value to a variable. ([@koic][])
5 changes: 3 additions & 2 deletions lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def assertions_count(node)
end
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def assertion_method?(node)
return false unless node
return assertion_method?(node.expression) if node.assignment? && node.respond_to?(:expression)
return false if !node.send_type? && !node.block_type? && !node.numblock_type?

Expand All @@ -110,7 +111,7 @@ def assertion_method?(node)
method_name.start_with?(prefix) || node.method?(:flunk)
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

def lifecycle_hook_method?(node)
node.def_type? && LIFECYCLE_HOOK_METHODS.include?(node.method_name)
Expand Down
12 changes: 12 additions & 0 deletions test/rubocop/cop/minitest/multiple_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ def test_asserts_once
RUBY
end

def test_does_not_register_offense_when_using_or_assigning_a_value_to_an_object_attribute
assert_no_offenses(<<~RUBY)
class FooTest < Minitest::Test
def test_asserts_once
var ||= :value
assert_equal(foo, bar)
end
end
RUBY
end

def test_generates_a_todo_based_on_the_worst_violation
inspect_source(<<-RUBY, @cop, 'test/foo_test.rb')
class FooTest < Minitest::Test
Expand Down

0 comments on commit b11fd1c

Please sign in to comment.