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`

# 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
SUPPORTED_STYLES

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/rspec/message_expectation.rb, line 40
def on_send(node)
  message_expectation(node) do |match|
    return correct_style_detected if preferred_style?(match)

    add_offense(match, location: :selector, message: MSG % style) 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 52
def preferred_style?(expectation)
  expectation.method_name.equal?(style)
end