Skip to content

Commit

Permalink
Increase branch coverage of RSpec/Focus
Browse files Browse the repository at this point in the history
The corrector logic for pair_type/str_type/sym_type seems like a
"generic" implementation, so I move things around to let that be a
"default" case in the if/else block.

Also, inlining `#focus_metadata` into `#on_send` means we don't even
need to check the type.

Co-authored-by: Phil Pirozhkov <[email protected]>
  • Loading branch information
bquorning and pirj committed Feb 10, 2025
1 parent 3d46503 commit a78f6c7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/rubocop/cop/rspec/focus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,27 @@ class Focus < Base
def on_send(node)
return if node.chained? || node.each_ancestor(:def, :defs).any?

focus_metadata(node) do |focus|
add_offense(focus) do |corrector|
if focus.pair_type? || focus.str_type? || focus.sym_type?
corrector.remove(with_surrounding(focus))
elsif focus.send_type?
correct_send(corrector, focus)
end
if focused_block?(node)
on_focused_block(node)
else
metadata(node) do |focus|
on_metadata(focus)
end
end
end

private

def focus_metadata(node, &block)
yield(node) if focused_block?(node)
def on_focused_block(node)
add_offense(node) do |corrector|
correct_send(corrector, node)
end
end

metadata(node, &block)
def on_metadata(node)
add_offense(node) do |corrector|
corrector.remove(with_surrounding(node))
end
end

def with_surrounding(focus)
Expand Down

0 comments on commit a78f6c7

Please sign in to comment.