Sha256: 162527bff6532c8cb881cf560b13277ed7b931ef7e70dcbee67db6202302a2f5

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

# encoding: utf-8

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

  let(:cop_config) do
    { 'EnforcedStyle' => enforced_style }
  end

  context 'when the enforced style is `it_behaves_like`' do
    let(:enforced_style) { :it_behaves_like }

    it 'flags a violation for it_should_behave_like' do
      expect_violation(<<-RUBY)
        it_should_behave_like 'a foo'
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_behaves_like` over `it_should_behave_like` when including examples in a nested context.
      RUBY
    end

    it 'does not flag a violation for it_behaves_like' do
      expect_no_violations("it_behaves_like 'a foo'")
    end

    include_examples(
      'autocorrect',
      "foo(); it_should_behave_like 'a foo'",
      "foo(); it_behaves_like 'a foo'"
    )
  end

  context 'when the enforced style is `it_should_behave_like`' do
    let(:enforced_style) { :it_should_behave_like }

    it 'flags a violation for it_behaves_like' do
      expect_violation(<<-RUBY)
        it_behaves_like 'a foo'
        ^^^^^^^^^^^^^^^^^^^^^^^ Prefer `it_should_behave_like` over `it_behaves_like` when including examples in a nested context.
      RUBY
    end

    it 'does not flag a violation for it_behaves_like' do
      expect_no_violations("it_should_behave_like 'a foo'")
    end

    include_examples(
      'autocorrect',
      "foo(); it_behaves_like 'a foo'",
      "foo(); it_should_behave_like 'a foo'"
    )
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.15.1 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.15.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.14.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.13.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb