Sha256: 4d8cc38e98f15dff1a55571fedce9d9f44d1e939b11092fa3ed19618ba1117c3

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

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

      expect_correction(<<-RUBY)
        it_behaves_like 'a foo'
      RUBY
    end

    it 'does not flag a violation for it_behaves_like' do
      expect_no_offenses("it_behaves_like 'a foo'")
    end
  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

      expect_correction(<<-RUBY)
        it_should_behave_like 'a foo'
      RUBY
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-1.35.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.34.1 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.34.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb
rubocop-rspec-1.33.0 spec/rubocop/cop/rspec/it_behaves_like_spec.rb