Sha256: d3eb060a175270d37749338200ccab90920447fcd950e11a2d6acefb0ea0a6ca

Contents?: true

Size: 2 KB

Versions: 7

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpec::EmptyLineAfterExampleGroup do
  subject(:cop) { described_class.new }

  it 'checks for empty line after describe' do
    expect_offense(<<-RUBY)
      RSpec.describe Foo do
        describe '#bar' do
        end
        ^^^ Add an empty line after `describe`.
        describe '#baz' do
        end
      end
    RUBY
  end

  it 'highlights single line formulations correctly' do
    expect_offense(<<-RUBY)
      RSpec.describe Foo do
        describe('#bar') { }
        ^^^^^^^^^^^^^^^^^^^^ Add an empty line after `describe`.
        describe '#baz' do
        end
      end
    RUBY
  end

  it 'checks for empty line after context' do
    expect_offense(<<-RUBY)
      RSpec.context 'foo' do
        context 'bar' do
        end
        ^^^ Add an empty line after `context`.
        context 'baz' do
        end
      end
    RUBY
  end

  it 'approves empty line after describe' do
    expect_no_offenses(<<-RUBY)
      RSpec.describe Foo do
        describe '#bar' do
        end

        describe '#baz' do
        end
      end
    RUBY
  end

  it 'approves empty line after context' do
    expect_no_offenses(<<-RUBY)
      RSpec.context 'foo' do
        context 'bar' do
        end

        context 'baz' do
        end
      end
    RUBY
  end

  it 'handles describes in an if block' do
    expect_offense(<<-RUBY)
      if RUBY_VERSION < 2.3
        describe 'skips checks under old ruby' do
        end
      else
        describe 'first check' do
        end
        ^^^ Add an empty line after `describe`.
        describe 'second check' do
        end
      end
    RUBY
  end

  bad_example = <<-RUBY
    RSpec.describe Foo do
      describe '#bar' do
      end
      describe '#baz' do
      end
    end
  RUBY

  good_example = <<-RUBY
    RSpec.describe Foo do
      describe '#bar' do
      end

      describe '#baz' do
      end
    end
  RUBY

  include_examples 'autocorrect',
                   bad_example,
                   good_example
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-rspec-1.32.0 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.31.0 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.30.1 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.30.0 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.29.1 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.29.0 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
rubocop-rspec-1.28.0 spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb