Sha256: 34d528626c272163f919c67b92b9f801c087ce32de4aca7fbbd9bf091ac70643

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

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

  it 'flags an empty context' do
    expect_offense(<<-RUBY)
      describe Foo do
        context 'when bar' do
        ^^^^^^^^^^^^^^^^^^ Empty example group detected.

          let(:foo) { bar }
        end

        describe '#thingy?' do
          specify do
            expect(whatever.thingy?).to be(true)
          end
        end

        it { should be_true }
      end
    RUBY
  end

  it 'flags an empty top level describe' do
    expect_offense(<<-RUBY)
      describe Foo do
      ^^^^^^^^^^^^ Empty example group detected.
      end
    RUBY
  end

  it 'does not flag include_examples' do
    expect_no_offenses(<<-RUBY)
      describe Foo do
        context "when something is true" do
          include_examples "some expectations"
        end

        context "when something else is true" do
          include_context "some expectations"
        end

        context "when a third thing is true" do
          it_behaves_like "some thingy"
        end
      end
    RUBY
  end

  it 'does not recognize custom include methods by default' do
    expect_offense(<<-RUBY)
      describe Foo do
      ^^^^^^^^^^^^ Empty example group detected.
        context "when I do something clever" do
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Empty example group detected.
          it_has_special_behavior
        end
      end
    RUBY
  end

  context 'when a custom include method is specified' do
    let(:cop_config) do
      { 'CustomIncludeMethods' => %w[it_has_special_behavior] }
    end

    it 'does not flag an otherwise empty example group' do
      expect_no_offenses(<<-RUBY)
        describe Foo do
          context "when I do something clever" do
            it_has_special_behavior
          end
        end
      RUBY
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubocop-rspec-1.25.1 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.25.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.24.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.23.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.22.2 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.22.1 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.22.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.21.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.20.1 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.20.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.19.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.18.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.17.1 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.17.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb
rubocop-rspec-1.16.0 spec/rubocop/cop/rspec/empty_example_group_spec.rb