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

Conversation

gjtorikian
Copy link
Contributor

There's a slight logical error in the recent DuplicateTestRun addition.

Totally legit Ruby code can be marked as unparseable by this test:

         parent_class_node = class_node_parent.each_child_node(:class).detect do |klass|
                              ^^^^^^^^^^^^^^^^^
Did you mean?  class_node
    /Users/gjtorikian/Development/rubocop-minitest/lib/rubocop/cop/minitest/duplicate_test_run.rb:69:in `parent_class_has_test_methods?'
    /Users/gjtorikian/Development/rubocop-minitest/lib/rubocop/cop/minitest/duplicate_test_run.rb:56:in `on_class'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:100:in `public_send'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:98:in `each'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:69:in `on_class'
    /Users/gjtorikian/.gem/gems/rubocop-ast-1.16.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
    /Users/gjtorikian/.gem/gems/rubocop-ast-1.16.0/lib/rubocop/ast/traversal.rb:136:in `each'
    /Users/gjtorikian/.gem/gems/rubocop-ast-1.16.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
    /Users/gjtorikian/.gem/gems/rubocop-ast-1.16.0/lib/rubocop/ast/traversal.rb:20:in `walk'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/commissioner.rb:86:in `investigate'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/team.rb:155:in `investigate_partial'
    /Users/gjtorikian/.gem/bundler/gems/rubocop-2d3a972cb12b/lib/rubocop/cop/team.rb:83:in `investigate'
    /Users/gjtorikian/Development/rubocop-minitest/lib/rubocop/minitest/assert_offense.rb:114:in `_investigate'
    /Users/gjtorikian/Development/rubocop-minitest/lib/rubocop/minitest/assert_offense.rb:105:in `assert_offense'
    /Users/gjtorikian/Development/rubocop-minitest/test/rubocop/cop/minitest/duplicate_test_run_test.rb:23:in `test_registers_offense_when_parent_and_children_have_tests_methods'

The solution to this is to not assume that every test file has a parent class. I added a failing test case to demonstrate this bug, and then the second commit is the change to fix it.

@koic
Copy link
Member

koic commented Apr 9, 2022

Can you add a changelog entry and squash your commits into one?

@gjtorikian gjtorikian force-pushed the protect-against-missing-parents branch from d1c4ab2 to fa108c4 Compare April 9, 2022 12:44
@gjtorikian
Copy link
Contributor Author

@koic Done!

@gjtorikian gjtorikian force-pushed the protect-against-missing-parents branch from fa108c4 to 6b281b4 Compare April 9, 2022 12:45
@gjtorikian gjtorikian force-pushed the protect-against-missing-parents branch from 90a7a5c to 72c0d65 Compare April 9, 2022 13:20
@koic
Copy link
Member

koic commented Apr 9, 2022

This looks good. Can you squash commits into one?

@gjtorikian gjtorikian force-pushed the protect-against-missing-parents branch from 76da0f1 to 059d225 Compare April 9, 2022 18:58
@gjtorikian
Copy link
Contributor Author

This looks good. Can you squash commits into one?

Yes, done!

@koic koic merged commit 36a9730 into rubocop:master Apr 10, 2022
@koic
Copy link
Member

koic commented Apr 10, 2022

Thanks!

@gjtorikian gjtorikian deleted the protect-against-missing-parents branch April 10, 2022 04:44
@gjtorikian
Copy link
Contributor Author

Thank you! Any chance for a patch version bump?

@koic
Copy link
Member

koic commented Apr 10, 2022

@gjtorikian Yeah, RuboCop Minitest 0.19.1 has been released.
https://github.com/rubocop/rubocop-minitest/releases/tag/v0.19.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants