Skip to content

Commit

Permalink
Protect against missing parent node
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Apr 9, 2022
1 parent baa5b61 commit 6b281b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#174](https://github.com/rubocop/rubocop-minitest/pull/167): Fix potential for valid Ruby code to be unparseable in `Minitest/DuplicateTestRun` cop. ([@gjtorikian][])
5 changes: 4 additions & 1 deletion lib/rubocop/cop/minitest/duplicate_test_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def on_class(class_node)

def parent_class_has_test_methods?(class_node)
parent_class = class_node.parent_class
parent_class_node = class_node.parent.each_child_node(:class).detect do |klass|

return false unless (class_node_parent = class_node.parent)

parent_class_node = class_node_parent.each_child_node(:class).detect do |klass|
klass.identifier == parent_class
end

Expand Down
13 changes: 13 additions & 0 deletions test/rubocop/cop/minitest/duplicate_test_run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ def test_child_asserts_twice
end
RUBY
end

def test_does_not_throw_error_if_missing_parent_test_class
assert_no_offenses(<<~RUBY)
class PostmarkAccountServiceTest < ActionDispatch::IntegrationTest
test "it handles missing payloads from Postmark Account API errors'"do
Postmark::AccountApiClient.any_instance.stubs(:create_server).raises(StandardError)
Rails.logger.expects(:error)
PostmarkAccountService.create_server({})
end
end
RUBY
end
end

0 comments on commit 6b281b4

Please sign in to comment.