Sha256: 23dc75090d6ed7c84db4bf4effb6000eb9aa37241f4da2d47a1e3cfb80a11fdc

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

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_offense(<<-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_offenses("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_offense(<<-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_offenses("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

23 entries across 23 versions & 1 rubygems

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