Sha256: 6d1145eb464231f7fac2d25b9abcdbf3c66ef8cfac32fd0e3e379109072982b3

Contents?: true

Size: 1.73 KB

Versions: 28

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

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

  it 'registers an offense for repeated example' do
    expect_offense(<<-RUBY)
      describe 'doing x' do
        it "does x" do
        ^^^^^^^^^^^^^^ Don't repeat examples within an example group.
          expect(foo).to be(bar)
        end

        it "does y" do
        ^^^^^^^^^^^^^^ Don't repeat examples within an example group.
          expect(foo).to be(bar)
        end
      end
    RUBY
  end

  it 'does not register a violation if rspec tag magic is involved' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it "does x" do
          expect(foo).to be(bar)
        end

        it "does y", :focus do
          expect(foo).to be(bar)
        end
      end
    RUBY
  end

  it 'does not flag examples with different implementations' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it "does x" do
          expect(foo).to have_attribute(foo: 1)
        end

        it "does y" do
          expect(foo).to have_attribute(bar: 2)
        end
      end
    RUBY
  end

  it 'does not flag examples when different its arguments are used' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        its(:x) { is_expected.to be_present }
        its(:y) { is_expected.to be_present }
      end
    RUBY
  end

  it 'does not flag repeated examples in different scopes' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it "does x" do
          expect(foo).to be(bar)
        end

        context 'when the scope changes' do
          it 'does not flag anything' do
            expect(foo).to be(bar)
          end
        end
      end
    RUBY
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.27.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.26.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/repeated_example_spec.rb