Skip to content

Commit

Permalink
Merge pull request #288 from G-Rath/fix-error
Browse files Browse the repository at this point in the history
[Fix #287] don't error on empty blocks when linting `assert_raises`
  • Loading branch information
koic committed Dec 30, 2023
2 parents de7824c + c907e1c commit d0b6912
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_don_t_error_on_empty_blocks_when_linting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#287](https://github.com/rubocop/rubocop-minitest/issues/287): Don't error on empty blocks when linting `assert_raises`. ([@G-Rath][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/minitest/assert_raises_compound_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
private

def multi_statement_begin?(node)
node.begin_type? && node.children.size > 1
node&.begin_type? && node.children.size > 1
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/rubocop/cop/minitest/assert_raises_compound_body_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def test_registers_offense_when_multi_statement_bodies
RUBY
end

def test_does_not_register_offense_when_empty_bodies
assert_no_offenses(<<~RUBY)
assert_raises(MyError) do
# nothing to see here...
end
RUBY
end

def test_does_not_register_offense_when_single_statement_bodies
assert_no_offenses(<<~RUBY)
assert_raises(MyError) do
Expand Down

0 comments on commit d0b6912

Please sign in to comment.