Sha256: 6138455fb6aee2815c5c9fec14895e4061c0b447bfb2e14559323032f9c5bb18

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

Contents

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

  it 'finds overwriten `let`' do
    expect_offense(<<-RUBY)
      RSpec.describe User do
        let(:a) { a }
        let(:a) { b }
        ^^^^^^^^^^^^^ `a` is already defined.
      end
    RUBY
  end

  it 'finds overwriten `subject`' do
    expect_offense(<<-RUBY)
      RSpec.describe User do
        subject(:a) { a }

        let(:a) { b }
        ^^^^^^^^^^^^^ `a` is already defined.
      end
    RUBY
  end

  it 'finds `let!` overwriting `let`' do
    expect_offense(<<-RUBY)
      RSpec.describe User do
        let(:a) { b }
        let!(:a) { b }
        ^^^^^^^^^^^^^^ `a` is already defined.
      end
    RUBY
  end

  it 'ignores overwriting in different context' do
    expect_no_offenses(<<-RUBY)
      RSpec.describe User do
        let(:a) { a }

        context `different` do
          let(:a) { b }
        end
      end
    RUBY
  end

  it 'does not encounter an error when handling an empty describe' do
    expect { inspect_source('RSpec.describe(User) do end', 'a_spec.rb') }
      .not_to raise_error
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/overwriting_setup_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/overwriting_setup_spec.rb