class RuboCop::Cop::RSpec::MessageExpectation
expect(foo).to receive(:bar)
# good
allow(foo).to receive(:bar)
# bad
@example ‘EnforcedStyle: expect`
allow(foo).to receive(:bar)
# good
expect(foo).to receive(:bar)
# bad
@example `EnforcedStyle: allow`
`EnforcedStyle` option and supports `–auto-gen-config`.
This cop can be configured in your configuration using the
Checks for consistent message expectation style.
def on_send(node)
def on_send(node) message_expectation(node) do |match| return correct_style_detected if preferred_style?(match) add_offense(match, :selector, MSG % style) do opposite_style_detected end end end
def preferred_style?(expectation)
def preferred_style?(expectation) expectation.method_name.equal?(style) end