class RuboCop::Cop::RSpec::MessageExpectation
Checks for consistent message expectation style.
This cop can be configured in your configuration using the ‘EnforcedStyle` option and supports `–auto-gen-config`.
@example ‘EnforcedStyle: allow` (default)
# bad expect(foo).to receive(:bar) # good allow(foo).to receive(:bar)
@example ‘EnforcedStyle: expect`
# bad allow(foo).to receive(:bar) # good expect(foo).to receive(:bar)
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/rspec/message_expectation.rb, line 42 def on_send(node) message_expectation(node) do |match| return correct_style_detected if preferred_style?(match) message = format(MSG, style: style) add_offense(match.loc.selector, message: message) do opposite_style_detected end end end
Private Instance Methods
preferred_style?(expectation)
click to toggle source
# File lib/rubocop/cop/rspec/message_expectation.rb, line 55 def preferred_style?(expectation) expectation.method_name.equal?(style) end