Sha256: 4c3dcd51a5531a323742b196c84789fe52aaa45b848ad8bb80a57ca2c0397751

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

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

  context 'with configuration' do
    let(:cop_config) do
      {
        'CustomTransform' => { 'have' => 'has', 'not' => 'does not' },
        'IgnoredWords' => %w(only really)
      }
    end

    it 'ignores non-example blocks' do
      expect_no_violations('foo "should do something" do; end')
    end

    it 'finds description with `should` at the beginning' do
      expect_violation(<<-RUBY)
        it 'should do something' do
            ^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
        end
      RUBY
    end

    it 'finds description with `Should` at the beginning' do
      expect_violation(<<-RUBY)
        it 'Should do something' do
            ^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
        end
      RUBY
    end

    it 'finds description with `shouldn\'t` at the beginning' do
      expect_violation(<<-RUBY)
        it "shouldn't do something" do
            ^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
        end
      RUBY
    end

    it 'skips descriptions without `should` at the beginning' do
      expect_no_violations(<<-RUBY)
        it 'finds no should here' do
        end
      RUBY
    end

    include_examples 'autocorrect',
                     'it "should only have trait" do end',
                     'it "only has trait" do end'
  end

  context 'when configuration is empty' do
    include_examples 'autocorrect',
                     'it "should have trait" do end',
                     'it "haves trait" do end'

    include_examples 'autocorrect',
                     'it "should only fail" do end',
                     'it "onlies fail" do end'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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