Class: RuboCop::Cop::RSpec::RepeatedExampleGroupDescription

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/repeated_example_group_description.rb

Overview

Check for repeated example group descriptions.

Examples:


# bad
describe 'cool feature' do
  # example group
end

describe 'cool feature' do
  # example group
end

# bad
context 'when case x' do
  # example group
end

describe 'when case x' do
  # example group
end

# good
describe 'cool feature' do
  # example group
end

describe 'another cool feature' do
  # example group
end

# good
context 'when case x' do
  # example group
end

context 'when another case' do
  # example group
end

Constant Summary collapse

MSG =
'Repeated %<group>s block description on line(s) %<loc>s'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_begin(node) ⇒ Object


63
64
65
66
67
68
69
# File 'lib/rubocop/cop/rspec/repeated_example_group_description.rb', line 63

def on_begin(node)
  return unless several_example_groups?(node)

  repeated_group_descriptions(node).each do |group, repeats|
    add_offense(group, message: message(group, repeats))
  end
end