Skip to content

Commit

Permalink
Use simple lookup table for replacements in StubbedMock
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Nov 2, 2024
1 parent e80d28c commit bdd66fa
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lib/rubocop/cop/rspec/stubbed_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ class StubbedMock < Base
}
PATTERN

REPLACEMENTS = {
expect: :allow,
is_expected: 'allow(subject)',
expect_any_instance_of: :allow_any_instance_of
}.freeze
RESTRICT_ON_SEND = %i[to].freeze

def on_send(node)
Expand All @@ -157,18 +162,7 @@ def on_expectation(expectation, method_name, matcher)
def msg(method_name)
format(MSG,
method_name: method_name,
replacement: replacement(method_name))
end

def replacement(method_name)
case method_name
when :expect
:allow
when :is_expected
'allow(subject)'
when :expect_any_instance_of
:allow_any_instance_of
end
replacement: REPLACEMENTS[method_name])
end
end
end
Expand Down

0 comments on commit bdd66fa

Please sign in to comment.