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_or_numblock_pattern, #block_pattern, #numblock_pattern, #send_pattern

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



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

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

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

  repeated_its(node).each do |its|
    add_offense(its)
  end
end