Class: RuboCop::Cop::RSpec::RepeatedDescription

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

Overview

Check for repeated description strings in example groups.

Examples:


# bad
RSpec.describe User do
  it 'is valid' do
    # ...
  end

  it 'is valid' do
    # ...
  end
end

# good
RSpec.describe User do
  it 'is valid when first and last name are present' do
    # ...
  end

  it 'is valid when last name only is present' do
    # ...
  end
end

# good
RSpec.describe User do
  it 'is valid' do
    # ...
  end

  it 'is valid', :flag do
    # ...
  end
end

Constant Summary collapse

MSG =
"Don't repeat descriptions within an example group."

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Methods included from RSpec::Language

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

Instance Method Details

#on_block(node) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/rubocop/cop/rspec/repeated_description.rb', line 46

def on_block(node)
  return unless example_group?(node)

  repeated_descriptions(node).each do |repeated_description|
    add_offense(repeated_description)
  end
end