Sha256: 3361111afd7da5bc0b4a6f37090aa5f3bfbe409b69cb74885c3d73037e41b958

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

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

  it 'registers an offense for repeated descriptions' do
    expect_violation(<<-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_violation(<<-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_violations(<<-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_violations(<<-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_violations(<<-RUBY)
      describe 'doing x' do
        it { foo }
        it { bar }
      end
    RUBY
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-rspec-1.12.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.11.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.10.0 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.9.1 spec/rubocop/cop/rspec/repeated_description_spec.rb
rubocop-rspec-1.9.0 spec/rubocop/cop/rspec/repeated_description_spec.rb