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::EmptyLineBeforeAssertionMethods errors on assertions with block arguments #187

Closed
petergoldstein opened this issue Oct 30, 2022 · 0 comments · Fixed by #188
Closed
Labels
bug Something isn't working

Comments

@petergoldstein
Copy link

Minitest::EmptyLineBeforeAssertionMethods does not properly handle assertions that are invoked with a block argument. Passing a block argument results in an error - undefined method args_type?' for ...`


Expected behavior

RuboCop Minitest should treat an assertion with a block argument identically to one where the block is explicitly specified.

Actual behavior

RuboCop Minitest generates an error when it processes this line

An error occurred while Minitest/EmptyLineBeforeAssertionMethods cop was inspecting ...
undefined method args_type?' for ...`

Steps to reproduce the problem

Consider the example from Minitest::Assertions#assert_raises

error = assert_raises(CustomError) do
  raise CustomError, 'This is really bad'
end

assert_equal 'This is really bad', error.message

A file with this code is parsed without error by RuboCop Minitest. But if we alter this code slightly to read:

blk = ~> { raise CustomError, 'This is really bad' }
error = assert_raises(CustomError, &blk)

assert_equal 'This is really bad', error.message

then RuboCop Minitest generates an error undefined method args_type?' for ...`

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You see extension cop versions (e.g. rubocop-minitest, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.37.1 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.0.4) [x86_64-darwin21]
  - rubocop-minitest 0.23.0
  - rubocop-performance 1.15.0
  - rubocop-rake 0.6.0
@koic koic added the bug Something isn't working label Oct 30, 2022
koic added a commit to koic/rubocop-minitest that referenced this issue Oct 31, 2022
…Methods`

Fixes rubocop#187.

This PR fixes an error for `Minitest/EmptyLineBeforeAssertionMethods`
when using method call with block.
@koic koic closed this as completed in #188 Oct 31, 2022
koic added a commit that referenced this issue Oct 31, 2022
…e_before_assertion_methods

[Fix #187] Fix an error for `Minitest/EmptyLineBeforeAssertionMethods`
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