Sha256: f9e586c879663bdc5988d2d6c5f13240a62e90403991c3d87e1580b86d1e396b

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

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

  it 'registers an offense for repeated example' do
    expect_violation(<<-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_violations(<<-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_violations(<<-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_violations(<<-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_violations(<<-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

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-rspec-1.12.0 spec/rubocop/cop/rspec/repeated_example_spec.rb
rubocop-rspec-1.11.0 spec/rubocop/cop/rspec/repeated_example_spec.rb