Sha256: fb2b89b3f64c46d75a306643cc318b141c7a0a94c8761284f98cbb81c11e3cac

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'rubocop-rspec'
require_relative 'base'

module Rubocop
  module Cop
    module RSpec
      # Checks if there is an empty line after shared example blocks.
      #
      # @example
      #   # bad
      #   RSpec.describe Foo do
      #     it_behaves_like 'do this first'
      #     it_behaves_like 'does this' do
      #     end
      #     it_behaves_like 'does that' do
      #     end
      #     it_behaves_like 'do some more'
      #   end
      #
      #   # good
      #   RSpec.describe Foo do
      #     it_behaves_like 'do this first'
      #     it_behaves_like 'does this' do
      #     end
      #
      #     it_behaves_like 'does that' do
      #     end
      #
      #     it_behaves_like 'do some more'
      #   end
      #
      #   # fair - it's ok to have non-separated without blocks
      #   RSpec.describe Foo do
      #     it_behaves_like 'do this first'
      #     it_behaves_like 'does this'
      #   end
      #
      class EmptyLineAfterSharedExample < Base
        extend RuboCop::Cop::AutoCorrector
        include RuboCop::Cop::RSpec::EmptyLineSeparation

        MSG = 'Add an empty line after `%<example>s` block.'

        # @!method shared_examples(node)
        def_node_matcher :shared_examples,
                         block_pattern('{#SharedGroups.all #Includes.all}')

        def on_block(node)
          shared_examples(node) do
            break if last_child?(node)

            missing_separating_line_offense(node) do |method|
              format(MSG, example: method)
            end
          end
        end
        alias_method :on_numblock, :on_block
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gitlab-styles-9.1.0 lib/rubocop/cop/rspec/empty_line_after_shared_example.rb
gitlab-styles-9.0.0 lib/rubocop/cop/rspec/empty_line_after_shared_example.rb