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

Minitest/MultipleAssertions crashes when using ActiveSupport test "name" do ... end syntax #131

Closed
mattbrictson opened this issue Apr 24, 2021 · 0 comments · Fixed by #132
Labels
bug Something isn't working

Comments

@mattbrictson
Copy link

mattbrictson commented Apr 24, 2021

Expected behavior

I should be able to use rubocop-minitest, specifically the Minitest/MultipleAssertions rule, on a Rails project that uses ActiveSupport::TestCase block syntax.

Actual behavior

rubocop crashes:

1 error occurred:
An error occurred while Minitest/MultipleAssertions cop was inspecting 
test/models/example_test.rb:3:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.13.0 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 3.0.1 x86_64-darwin20)
Finished in 0.5184599999920465 seconds
An error occurred while Minitest/MultipleAssertions cop was inspecting test/models/example_test.rb:3:0.
undefined method `name' for #<Parser::Source::Map::Collection:0x000000010b5b5c78 @end=#<Parser::Source::Range test/models/example_test.rb 221...224>, @begin=#<Parser::Source::Range test/models/example_test.rb 86...88>, @expression=#<Parser::Source::Range test/models/example_test.rb 69...224>, @node=s(:block,
  s(:send, nil, :test,
    s(:str, "something")),
  s(:args),
  s(:begin,
    s(:send, nil, :refute_equal,
      s(:str, "a"),
      s(:str, "")),
    s(:send, nil, :refute_equal,
      s(:str, "b"),
      s(:str, "")),
    s(:send, nil, :refute_equal,
      s(:str, "c"),
      s(:str, "")),
    s(:send, nil, :refute_equal,
      s(:str, "d"),
      s(:str, "")),
    s(:send, nil, :refute_equal,
      s(:str, "e"),
      s(:str, ""))))>
/Users/mbrictson/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.12.0/lib/rubocop/cop/minitest/multiple_assertions.rb:46:in `block in on_class'
/Users/mbrictson/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.12.0/lib/rubocop/cop/minitest/multiple_assertions.rb:38:in `each'
/Users/mbrictson/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/rubocop-minitest-0.12.0/lib/rubocop/cop/minitest/multiple_assertions.rb:38:in `on_class'

Steps to reproduce the problem

Create a trivial ActiveSupport::TestCase using the test block syntax, that fails the Minitest/MultipleAssertions rule. Like this:

require "test_helper"

class ExampleTest < ActiveSupport::TestCase
  test "something" do
    refute_equal("a", "")
    refute_equal("b", "")
    refute_equal("c", "")
    refute_equal("d", "")
    refute_equal("e", "")
  end
end

Run rubocop:

$ bundle exec rubocop -d test/models/example_test.rb

RuboCop version

$ bundle exec rubocop -V
1.13.0 (using Parser 3.0.1.0, rubocop-ast 1.4.1, running on ruby 3.0.1 x86_64-darwin20)
  - rubocop-minitest 0.12.0
  - rubocop-performance 1.11.0
  - rubocop-rails 2.9.1
  - rubocop-rspec 2.2.0
@koic koic added the bug Something isn't working label Apr 24, 2021
koic added a commit to koic/rubocop-minitest that referenced this issue Apr 24, 2021
Fixes rubocop#131.

This PR fixes an error for `Minitest/MultipleAssertions` and fixes
a false positive for `test` block.

Since RuboCop Minitest is a gem for Minitest, it should not support
`ActiveSupport::TestCase` feature `test` block.
@koic koic closed this as completed in #132 Apr 25, 2021
koic added a commit that referenced this issue Apr 25, 2021
[Fix #131] Fix an error for `Minitest/MultipleAssertions`
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

Successfully merging a pull request may close this issue.

2 participants