Sha256: 9b9412b56fa48c155d60d50e097610c17f7d43571ddf5a38046afbf015a27100

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::ReceiveNever do
  subject(:cop) { described_class.new }

  it 'flags usage of `never`' do
    expect_offense(<<-RUBY)
      expect(foo).to receive(:bar).never
                                   ^^^^^ Use `not_to receive` instead of `never`.
    RUBY

    expect_correction(<<-RUBY)
      expect(foo).not_to receive(:bar)
    RUBY
  end

  it 'flags usage of `never` after `with`' do
    expect_offense(<<-RUBY)
      expect(foo).to receive(:bar).with(baz).never
                                             ^^^^^ Use `not_to receive` instead of `never`.
    RUBY

    expect_correction(<<-RUBY)
      expect(foo).not_to receive(:bar).with(baz)
    RUBY
  end

  it 'flags usage of `never` with `is_expected`' do
    expect_offense(<<-RUBY)
      is_expected.to receive(:bar).with(baz).never
                                             ^^^^^ Use `not_to receive` instead of `never`.
    RUBY

    expect_correction(<<-RUBY)
      is_expected.not_to receive(:bar).with(baz)
    RUBY
  end

  it 'flags usage of `never` with `expect_any_instance_of`' do
    expect_offense(<<-RUBY)
      expect_any_instance_of(Foo).to receive(:bar).with(baz).never
                                                             ^^^^^ Use `not_to receive` instead of `never`.
    RUBY

    expect_correction(<<-RUBY)
      expect_any_instance_of(Foo).not_to receive(:bar).with(baz)
    RUBY
  end

  it 'allows method called `never`' do
    expect_no_offenses(<<-RUBY)
      expect(foo).to receive(:bar).with(Value.never)
      expect(foo.never).to eq(bar.never)
      is_expected.to be never
    RUBY
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/cop/rspec/receive_never_spec.rb