Sha256: ed76ecfb5ff8f6483e0a6963efdd43f1780d6d8dcaecbf12e87a974b8ef4cde6

Contents?: true

Size: 1.69 KB

Versions: 28

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

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

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

        it "does x" do
        ^^^^^^^^^^^ Don't repeat descriptions within an example group.
        end
      end
    RUBY
  end

  it 'registers offense for repeated descriptions separated by a context' do
    expect_offense(<<-RUBY)
      describe 'doing x' do
        it "does x" do
        ^^^^^^^^^^^ Don't repeat descriptions within an example group.
        end

        context 'during some use case' do
          it "does x" do
            # this should be fine
          end
        end

        it "does x" do
        ^^^^^^^^^^^ Don't repeat descriptions within an example group.
        end
      end
    RUBY
  end

  it 'ignores descriptions repeated in a shared context' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it "does x" do
        end

        shared_context 'shared behavior' do
          it "does x" do
          end
        end
      end
    RUBY
  end

  it 'ignores repeated descriptions in a nested context' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it "does x" do
        end

        context 'in a certain use case' do
          it "does x" do
          end
        end
      end
    RUBY
  end

  it 'does not flag tests which do not contain description strings' do
    expect_no_offenses(<<-RUBY)
      describe 'doing x' do
        it { foo }
        it { bar }
      end
    RUBY
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/repeated_description_spec.rb