Class: RuboCop::Cop::RSpec::RepeatedExample

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

Overview

Check for repeated examples within example groups.

Examples:


it 'is valid' do
  expect(user).to be_valid
end

it 'validates the user' do
  expect(user).to be_valid
end

Constant Summary collapse

MSG =
"Don't repeat examples within an example group. " \
'Repeated on line(s) %<lines>s.'

Instance Method Summary collapse

Methods included from RepeatedItems

#add_repeated_lines, #find_repeated_groups

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler



24
25
26
27
28
29
30
# File 'lib/rubocop/cop/rspec/repeated_example.rb', line 24

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
  return unless example_group?(node)

  find_repeated_examples(node).each do |repeated_examples|
    add_offenses_for_repeated_group(repeated_examples)
  end
end