Skip to content

Commit

Permalink
Fix an error for Minitest/SkipEnsure when only ensure has a body
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Aug 23, 2024
1 parent 859751a commit e901adf
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 e901adf

Please sign in to comment.