Skip to content

Commit

Permalink
Merge pull request #316 from Earlopain/error-skip-ensure
Browse files Browse the repository at this point in the history
Fix an error for `Minitest/SkipEnsure` when only `ensure` has a body
  • Loading branch information
koic committed Aug 27, 2024
2 parents 859751a + e901adf commit 4f75dc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_error_skip_ensure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#314](https://github.com/rubocop/rubocop-minitest/pull/314): Fix an error for `Minitest/SkipEnsure` when only `ensure` has a body. ([@earlopain][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/minitest/skip_ensure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def on_ensure(node)
private

def find_skip(node)
node.node_parts.first.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
return unless (body = node.node_parts.first)

body.descendants.detect { |n| n.send_type? && n.receiver.nil? && n.method?(:skip) }
end

def use_skip_in_rescue?(skip_method)
Expand Down
9 changes: 9 additions & 0 deletions test/rubocop/cop/minitest/skip_ensure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,13 @@ def test_skip_with_receiver
end
RUBY
end

def test_registers_no_offese_when_ensure_only
assert_no_offenses(<<~RUBY)
def test_ensure_only
ensure
do_something
end
RUBY
end
end

0 comments on commit 4f75dc5

Please sign in to comment.