Sha256: dd897c1853fba47825872a19a215e32fdbe620d4454013106f2db0ffe94a1dac

Contents?: true

Size: 1.79 KB

Versions: 24

Compression:

Stored size: 1.79 KB

Contents

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

  it 'registers an offense for `eql` when argument is a boolean' do
    expect_offense(<<-RUBY)
      it { expect(foo).to eql(true) }
                          ^^^ Prefer `be` over `eql`.
      it { expect(foo).to eql(false) }
                          ^^^ Prefer `be` over `eql`.
    RUBY
  end

  it 'registers an offense for `eql` when argument is an integer' do
    expect_offense(<<-RUBY)
      it { expect(foo).to eql(0) }
                          ^^^ Prefer `be` over `eql`.
      it { expect(foo).to eql(123) }
                          ^^^ Prefer `be` over `eql`.
    RUBY
  end

  it 'registers an offense for `eql` when argument is a float' do
    expect_offense(<<-RUBY)
      it { expect(foo).to eql(1.0) }
                          ^^^ Prefer `be` over `eql`.
      it { expect(foo).to eql(1.23) }
                          ^^^ Prefer `be` over `eql`.
    RUBY
  end

  it 'registers an offense for `eql` when argument is a symbol' do
    expect_offense(<<-RUBY)
      it { expect(foo).to eql(:foo) }
                          ^^^ Prefer `be` over `eql`.
    RUBY
  end

  it 'registers an offense for `eql` when argument is nil' do
    expect_offense(<<-RUBY)
      it { expect(foo).to eql(nil) }
                          ^^^ Prefer `be` over `eql`.
    RUBY
  end

  it 'does not register an offense for `eql` when argument is a string' do
    expect_no_offenses(<<-RUBY)
      it { expect(foo).to eql('foo') }
    RUBY
  end

  it 'does not register an offense for `eql` when expectation is negated' do
    expect_no_offenses(<<-RUBY)
      it { expect(foo).to_not eql(1) }
    RUBY
  end

  include_examples 'autocorrect',
                   'it { expect(foo).to eql(1) }',
                   'it { expect(foo).to be(1) }'
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.27.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/be_eql_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/be_eql_spec.rb