Sha256: 14c51748f5bf6056688e21f63f3d7b1da8c305c76cc8f9b90106f411c0d919e6

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

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

  it 'flags nested contexts' do
    expect_offense(<<-RUBY)
      describe MyClass do
        context 'when foo' do
          context 'when bar' do
            context 'when baz' do
            ^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [4/3].
            end
          end
        end

        context 'when qux' do
          context 'when norf' do
          end
        end
      end
    RUBY
  end

  it 'ignores non-spec context methods' do
    expect_no_offenses(<<-RUBY)
      class MyThingy
        context 'this is not rspec' do
          context 'but it uses contexts' do
          end
        end
      end
    RUBY
  end

  context 'when Max is configured as 2' do
    let(:cop_config) { { 'Max' => '2' } }

    it 'flags two levels of nesting' do
      expect_offense(<<-RUBY)
        describe MyClass do
          context 'when foo' do
            context 'when bar' do
            ^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [3/2].
              context 'when baz' do
              ^^^^^^^^^^^^^^^^^^ Maximum example group nesting exceeded [4/2].
              end
            end
          end
        end
      RUBY
    end
  end

  context 'when configured with MaxNesting' do
    let(:cop_config) { { 'MaxNesting' => '1' } }

    it 'emits a deprecation warning' do
      expect { inspect_source('describe(Foo) { }', 'foo_spec.rb') }
        .to output(
          'Configuration key `MaxNesting` for RSpec/NestedGroups is ' \
          "deprecated in favor of `Max`. Please use that instead.\n"
        ).to_stderr
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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