Class: RuboCop::Cop::RSpec::ExcessiveDocstringSpacing

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rspec/excessive_docstring_spacing.rb

Overview

Checks for excessive whitespace in example descriptions.

Examples:

# bad
it '  has  excessive   spacing  ' do
end

# good
it 'has excessive spacing' do
end
# bad
context '  when a condition   is met  ' do
end

# good
context 'when a condition is met' do
end

Constant Summary collapse

MSG =
'Excessive whitespace.'

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

#example_description(node) ⇒ Object



32
33
34
35
36
37
# File 'lib/rubocop/cop/rspec/excessive_docstring_spacing.rb', line 32

def_node_matcher :example_description, <<~PATTERN
  (send _ {#Examples.all #ExampleGroups.all} ${
    $str
    $(dstr ({str dstr `sym} ...) ...)
  } ...)
PATTERN

#on_send(node) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/rspec/excessive_docstring_spacing.rb', line 39

def on_send(node)
  example_description(node) do |description_node, message|
    return if description_node.heredoc?

    text = text(message)

    return unless excessive_whitespace?(text)

    add_whitespace_offense(description_node, text)
  end
end