Skip to content

Commit 4f75dc5

Browse files
authored
Merge pull request #316 from Earlopain/error-skip-ensure
Fix an error for `Minitest/SkipEnsure` when only `ensure` has a body
2 parents 859751a + e901adf commit 4f75dc5

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

changelog/fix_error_skip_ensure.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#314](https://github.com/rubocop/rubocop-minitest/pull/314): Fix an error for `Minitest/SkipEnsure` when only `ensure` has a body. ([@earlopain][])

lib/rubocop/cop/minitest/skip_ensure.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def on_ensure(node)
7575
private
7676

7777
def find_skip(node)
78-
node.node_parts.first.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
78+
return unless (body = node.node_parts.first)
79+
80+
body.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
7981
end
8082

8183
def use_skip_in_rescue?(skip_method)

test/rubocop/cop/minitest/skip_ensure_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,13 @@ def test_skip_with_receiver
119119
end
120120
RUBY
121121
end
122+
123+
def test_registers_no_offese_when_ensure_only
124+
assert_no_offenses(<<~RUBY)
125+
def test_ensure_only
126+
ensure
127+
do_something
128+
end
129+
RUBY
130+
end
122131
end

0 commit comments

Comments
 (0)