Sha256: ab7fe0a15aa1b2b92f9c7165a4471b6ede6fd6052130c18b3e93ccfca47bd903

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 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_violation(<<-RUBY)
        expect(foo).to receive(:bar)
        ^^^^^^ Prefer `allow` for setting message expectations.
      RUBY
    end

    it 'approves of allow(...).to receive' do
      expect_no_violations('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_violation(<<-RUBY)
        allow(foo).to receive(:bar)
        ^^^^^ Prefer `expect` for setting message expectations.
      RUBY
    end

    it 'approves of expect(...).to receive' do
      expect_no_violations('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

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.1 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.15.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.14.0 spec/rubocop/cop/rspec/message_expectation_spec.rb
rubocop-rspec-1.13.0 spec/rubocop/cop/rspec/message_expectation_spec.rb