Sha256: 018c84ecb0d04c0be7bd4f51fd97ee28f604b607b5429f752bb28e12593ec0d5

Contents?: true

Size: 1.74 KB

Versions: 18

Compression:

Stored size: 1.74 KB

Contents

RSpec.describe RuboCop::Cop::RSpec::ContextWording, :config do
  subject(:cop) { described_class.new(config) }

  let(:cop_config) { { 'Prefixes' => %w[when with] } }

  it 'skips describe blocks' do
    expect_no_offenses(<<-RUBY)
      describe 'the display name not present' do
      end
    RUBY
  end

  it 'finds context without `when` at the beginning' do
    expect_offense(<<-RUBY)
      context 'the display name not present' do
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
      end
    RUBY
  end

  it 'finds shared_context without `when` at the beginning' do
    expect_offense(<<-RUBY)
      shared_context 'the display name not present' do
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
      end
    RUBY
  end

  it "skips descriptions beginning with 'when'" do
    expect_no_offenses(<<-RUBY)
      context 'when the display name is not present' do
      end
    RUBY
  end

  it 'finds context without separate `when` at the beginning' do
    expect_offense(<<-RUBY)
      context 'whenever you do' do
              ^^^^^^^^^^^^^^^^^ Start context description with 'when', or 'with'.
      end
    RUBY
  end

  context 'when configured' do
    let(:cop_config) { { 'Prefixes' => %w[if] } }

    it 'finds context without whitelisted prefixes at the beginning' do
      expect_offense(<<-RUBY)
        context 'when display name is present' do
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Start context description with 'if'.
        end
      RUBY
    end

    it 'skips descriptions with whitelisted prefixes at the beginning' do
      expect_no_offenses(<<-RUBY)
        context 'if display name is present' do
        end
      RUBY
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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