lib/rubocop/cop/rspec/stubbed_mock.rb in rubocop-rspec-3.2.0 vs lib/rubocop/cop/rspec/stubbed_mock.rb in rubocop-rspec-3.3.0
- old
+ new
@@ -12,12 +12,13 @@
# # good (without spies)
# allow(foo).to receive(:bar).with(42).and_return("hello world")
# expect(foo).to receive(:bar).with(42)
#
class StubbedMock < Base
- MSG = 'Prefer `%<replacement>s` over `%<method_name>s` when ' \
+ MSG = 'Prefer %<replacement>s over `%<method_name>s` when ' \
'configuring a response.'
+ RESTRICT_ON_SEND = %i[to].freeze
# @!method message_expectation?(node)
# Match message expectation matcher
#
# @example source that matches
@@ -131,12 +132,10 @@
(send nil? { :receive :receive_message_chain } ... block_pass) # receive(:foo, &canned)
(send (send nil? :receive ...) :with ... block_pass) # receive(:foo).with('foo', &canned)
}
PATTERN
- RESTRICT_ON_SEND = %i[to].freeze
-
def on_send(node)
expectation(node) do |expectation, method_name, matcher|
on_expectation(expectation, method_name, matcher)
end
end
@@ -153,22 +152,26 @@
matcher_with_hash(matcher, &flag_expectation)
matcher_with_blockpass(matcher, &flag_expectation)
end
def msg(method_name)
- format(MSG,
- method_name: method_name,
- replacement: replacement(method_name))
+ format(
+ MSG,
+ method_name: method_name,
+ replacement: replacement(method_name)
+ )
end
def replacement(method_name)
case method_name
when :expect
- :allow
+ '`allow`'
when :is_expected
- 'allow(subject)'
+ '`allow(subject)`'
when :expect_any_instance_of
- :allow_any_instance_of
+ '`allow_any_instance_of`'
+ else
+ 'an allow statement'
end
end
end
end
end