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_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

#example_description(node) ⇒ Object


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

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

#on_send(node) ⇒ Object


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

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