Sha256: 7fe9c129a733f07d9366c3d76799b59b8ccce797ea625ed9524907e284dcbd36

Contents?: true

Size: 1.35 KB

Versions: 25

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

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

  it 'complains when let! is used and not referenced' do
    expect_offense(<<-RUBY)
      describe Foo do
        let!(:foo) { bar }
        ^^^^^^^^^^ Do not use `let!` for test setup.

        it 'does not use foo' do
          expect(baz).to eq(qux)
        end
      end
    RUBY
  end

  it 'ignores let! when used in `before`' do
    expect_no_offenses(<<-RUBY)
      describe Foo do
        let!(:foo) { bar }

        before do
          foo
        end

        it 'does not use foo' do
          expect(baz).to eq(qux)
        end
      end
    RUBY
  end

  it 'ignores let! when used in example' do
    expect_no_offenses(<<-RUBY)
      describe Foo do
        let!(:foo) { bar }

        it 'uses foo' do
          foo
          expect(baz).to eq(qux)
        end
      end
    RUBY
  end

  it 'complains when let! is used and not referenced within nested group' do
    expect_offense(<<-RUBY)
      describe Foo do
        context 'when something special happens' do
          let!(:foo) { bar }
          ^^^^^^^^^^ Do not use `let!` for test setup.

          it 'does not use foo' do
            expect(baz).to eq(qux)
          end
        end

        it 'references some other foo' do
          foo
        end
      end
    RUBY
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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