Sha256: 64d9f024300cbf546e7ac425f6639bce592d559560b6965cd63f9f8974073fd0

Contents?: true

Size: 1.28 KB

Versions: 28

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::MessageExpectation, :config do
  subject(:cop) { described_class.new(config) }

  context 'when EnforcedStyle is allow' do
    let(:cop_config) do
      { 'EnforcedStyle' => 'allow' }
    end

    it 'flags expect(...).to receive' do
      expect_offense(<<-RUBY)
        expect(foo).to receive(:bar)
        ^^^^^^ Prefer `allow` for setting message expectations.
      RUBY
    end

    it 'approves of allow(...).to receive' do
      expect_no_offenses('allow(foo).to receive(:bar)')
    end

    include_examples 'detects style', 'allow(foo).to receive(:bar)',  'allow'
    include_examples 'detects style', 'expect(foo).to receive(:bar)', 'expect'
  end

  context 'when EnforcedStyle is expect' do
    let(:cop_config) do
      { 'EnforcedStyle' => 'expect' }
    end

    it 'flags allow(...).to receive' do
      expect_offense(<<-RUBY)
        allow(foo).to receive(:bar)
        ^^^^^ Prefer `expect` for setting message expectations.
      RUBY
    end

    it 'approves of expect(...).to receive' do
      expect_no_offenses('expect(foo).to receive(:bar)')
    end

    include_examples 'detects style', 'expect(foo).to receive(:bar)', 'expect'
    include_examples 'detects style', 'allow(foo).to receive(:bar)',  'allow'
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.27.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/message_expectation_spec.rb