Sha256: 36917ea4e258303894e735a7dd980a6a7cb2865335d47ada7c63a39e5203f610

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 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[without] } }

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/context_wording_spec.rb