Class: Rubocop::Cop::RSpec::ExampleStartingCharacter

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

Overview

Checks for common mistakes in example descriptions.

This cop will correct docstrings that begin/end with space or words that start with a capital letter.

Examples:

# bad
it 'Does something' do
end

# good
it 'does nothing' do
end
# bad
it ' does something' do
end

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

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

# good
it 'does something' do
end

See Also:

Constant Summary collapse

MSG =
'Only start words with lowercase alpha with no leading/trailing spaces when describing your tests.'

Instance Method Summary collapse

Instance Method Details

#it_description(node) ⇒ Object



56
57
58
59
60
61
# File 'lib/rubocop/cop/rspec/example_starting_character.rb', line 56

def_node_matcher :it_description, <<-PATTERN
      (block (send _ :it ${
(str $_)
(dstr (str $_ ) ...)
      } ...) ...)
PATTERN

#on_block(node) ⇒ Object Also known as: on_numblock



63
64
65
66
67
# File 'lib/rubocop/cop/rspec/example_starting_character.rb', line 63

def on_block(node)
  it_description(node) do |description_node, _message|
    add_wording_offense(description_node, MSG) if invalid_description?(text(description_node))
  end
end