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

Inherits:
Base
  • Object
show all
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 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



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

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

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