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

RuboCop Minitest 0.17.1 Minitest/UnreachableAssertion offenses may be false positive #159

Closed
yahonda opened this issue Feb 11, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@yahonda
Copy link
Contributor

yahonda commented Feb 11, 2022

I'd like to know if RuboCop Minitest 0.17.1 Minitest/UnreachableAssertion offenses are false positive or not.

Expected behavior

No offenses are reported as RuboCop Minitest 0.17.0 does.

Actual behavior

It reports 22 offenses.

Offenses:

actioncable/test/test_helper_test.rb:111:7: C: Minitest/UnreachableAssertion: Unreachable assert_broadcast_on detected.
      assert_broadcast_on("test", "world")
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:36:13: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
            assert_response :unauthorized
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:46:11: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
          assert_response :unauthorized
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:50:11: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
          assert_response 500
          ^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:59:11: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
          assert_response :ok
          ^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:63:11: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
          assert_response :success
          ^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:71:11: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
          assert_response :succezz
          ^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:79:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response :success }
                                                     ^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:89:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response 200 }
                                                     ^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:100:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response :success }
                                                     ^^^^^^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:112:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response 301 }
                                                     ^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:123:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response 200 }
                                                     ^^^^^^^^^^^^^^^^^^^
actionpack/test/assertions/response_assertions_test.rb:134:54: C: Minitest/UnreachableAssertion: Unreachable assert_response detected.
        error = assert_raises(Minitest::Assertion) { assert_response 200 }
                                                     ^^^^^^^^^^^^^^^^^^^
actionpack/test/controller/resources_test.rb:1101:9: C: Minitest/UnreachableAssertion: Unreachable assert_routing detected.
        assert_routing({ method: "all", path: "/products" }, { controller: "products", action: "show" })
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activejob/test/cases/test_helper_test.rb:593:9: C: Minitest/UnreachableAssertion: Unreachable assert_enqueued_with detected.
        assert_enqueued_with(**{ facet => refuser })
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activejob/test/cases/test_helper_test.rb:1912:9: C: Minitest/UnreachableAssertion: Unreachable assert_performed_with detected.
        assert_performed_with(**{ facet => refuser })
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activesupport/test/share_lock_test.rb:530:11: C: Minitest/UnreachableAssertion: Unreachable assert_threads_not_stuck detected.
          assert_threads_not_stuck @thread
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activesupport/test/share_lock_test.rb:537:11: C: Minitest/UnreachableAssertion: Unreachable assert_threads_stuck detected.
          assert_threads_stuck @thread
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activesupport/test/share_lock_test.rb:544:11: C: Minitest/UnreachableAssertion: Unreachable assert_threads_stuck_but_releasable_by_latch detected.
          assert_threads_stuck_but_releasable_by_latch @thread, @latch
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activesupport/test/share_lock_test.rb:551:11: C: Minitest/UnreachableAssertion: Unreachable assert_threads_stuck_but_releasable_by_latch detected.
          assert_threads_stuck_but_releasable_by_latch @thread, another_latch
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
activesupport/test/test_case_test.rb:24:46: C: Minitest/UnreachableAssertion: Unreachable assert_not detected.
    e = assert_raises(Minitest::Assertion) { assert_not true }
                                             ^^^^^^^^^^^^^^^
activesupport/test/test_case_test.rb:27:46: C: Minitest/UnreachableAssertion: Unreachable assert_not detected.
    e = assert_raises(Minitest::Assertion) { assert_not true, "custom" }
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^

2996 files inspected, 22 offenses detected
%

Steps to reproduce the problem

The latest Gemfile.lock at Rails repository says rubocop-minitest (0.17.0) then update rubocop-minitest gem to the latest version 0.17.1 as follows.

git clone https://github.com/rails/rails
cd rails
bundle update rubocop-minitest --conservative
bundle exec rubocop

RuboCop version

% bundle exec rubocop -V
1.24.1 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.0.3 arm64-darwin21)
  - rubocop-minitest 0.17.1
  - rubocop-packaging 0.5.1
  - rubocop-performance 1.13.1
  - rubocop-rails 2.13.0
%
@koic koic added the bug Something isn't working label Feb 11, 2022
@koic
Copy link
Member

koic commented Feb 11, 2022

Yeah, this is an unexpected behavior. I will tackle this issue.

@koic
Copy link
Member

koic commented Feb 11, 2022

I've opened #160 and tested it in rails/rails repo.

@yahonda
Copy link
Contributor Author

yahonda commented Feb 12, 2022

I have confirmed #160 resolves this issue.

$ git diff
diff --git a/Gemfile b/Gemfile
index 2b4a635004..778ff6683b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -37,7 +37,7 @@ gem "json", ">= 2.0.0"

 group :rubocop do
   gem "rubocop", ">= 0.90", require: false
-  gem "rubocop-minitest", require: false
+  gem "rubocop-minitest", github: "koic/rubocop-minitest", branch: "fix_false_positive_for_minitest_unreachable_assertion", require: false
   gem "rubocop-packaging", require: false
   gem "rubocop-performance", require: false
   gem "rubocop-rails", require: false
$

@koic koic closed this as completed in d5c7c12 Feb 12, 2022
koic added a commit that referenced this issue Feb 12, 2022
…eachable_assertion

[Fix #159] Fix a false positive for `Minitest/UnreachableAssertion`
@koic
Copy link
Member

koic commented Feb 12, 2022

RuboCop Minitest 0.17.2 has been released. Thank you!
https://github.com/rubocop/rubocop-minitest/releases/tag/v0.17.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants