Sha256: bba51380e8090909ccf6066a0de3f4947cea4068a26af18c5b8066fdcb4e40ad

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 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
  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
  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
  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
  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

  include_examples 'autocorrect',
                   'expect(foo).to receive(:bar).with(0).never',
                   'expect(foo).not_to receive(:bar).with(0)'
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/receive_never_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/receive_never_spec.rb