Class: RuboCop::Cop::RSpec::UndescriptiveLiteralsDescription

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

Overview

Description should be descriptive.

If example group or example contains only ‘execute string`, numbers and regular expressions, the description is not clear.

Examples:

# bad
describe `time` do
 # ...
end

# bad
context /when foo/ do
  # ...
end

# bad
it 10000 do
  # ...
end

# good
describe Foo do
  # ...
end

# good
describe '#foo' do
  # ...
end

# good
context "when #{foo} is bar" do
  # ...
end

# good
it 'does something' do
  # ...
end

Constant Summary collapse

MSG =
'Description should be descriptive.'

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

#example_groups_or_example?(node) ⇒ Object



51
52
53
# File 'lib/rubocop/cop/rspec/undescriptive_literals_description.rb', line 51

def_node_matcher :example_groups_or_example?, <<~PATTERN
  (block (send #rspec? {#ExampleGroups.all #Examples.all} $_) ...)
PATTERN

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



55
56
57
58
59
# File 'lib/rubocop/cop/rspec/undescriptive_literals_description.rb', line 55

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  example_groups_or_example?(node) do |arg|
    add_offense(arg) if offense?(arg)
  end
end