Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against missing parents #167

Merged
merged 1 commit into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#167](https://github.com/rubocop/rubocop-minitest/pull/167): Fix potential for valid Ruby code to be unparsable 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