Skip to content

Commit c907e1c

Browse files
committed
[Fix #287] don't error on empty blocks when linting assert_raises
1 parent e4eb3a4 commit c907e1c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#287](https://github.com/rubocop/rubocop-minitest/issues/287): Don't error on empty blocks when linting `assert_raises`. ([@G-Rath][])

lib/rubocop/cop/minitest/assert_raises_compound_body.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
3737
private
3838

3939
def multi_statement_begin?(node)
40-
node.begin_type? && node.children.size > 1
40+
node&.begin_type? && node.children.size > 1
4141
end
4242
end
4343
end

test/rubocop/cop/minitest/assert_raises_compound_body_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def test_registers_offense_when_multi_statement_bodies
1313
RUBY
1414
end
1515

16+
def test_does_not_register_offense_when_empty_bodies
17+
assert_no_offenses(<<~RUBY)
18+
assert_raises(MyError) do
19+
# nothing to see here...
20+
end
21+
RUBY
22+
end
23+
1624
def test_does_not_register_offense_when_single_statement_bodies
1725
assert_no_offenses(<<~RUBY)
1826
assert_raises(MyError) do

0 commit comments

Comments
 (0)