Class: RuboCop::Cop::Salsify::RspecDocString

Inherits:
RSpec::Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ConfigurableEnforcedStyle
Defined in:
lib/rubocop/cop/salsify/rspec_doc_string.rb

Overview

Check that doc strings for example groups and examples use either single-quoted or double-quoted strings based on the enforced style.

Examples:


# When EnforcedStyle is double_quotes
# Good
it "does something" do
  ...
end

# When EnforcedStyle is single_quotes
# Good
it 'does something' do
  ...
end

Constant Summary collapse

SINGLE_QUOTE_MSG =
'Example Group/Example doc strings must be single-quoted.'
DOUBLE_QUOTE_MSG =
'Example Group/Example doc strings must be double-quoted.'
DOCUMENTED_METHODS =
RuboCop::ConfigLoader.default_configuration.for_department('RSpec')
.fetch('Language')
.values_at('ExampleGroups', 'Examples', 'SharedGroups', 'Includes')
.flat_map { |element| element.values.flatten }
.map(&:to_sym)

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object


48
49
50
51
52
53
# File 'lib/rubocop/cop/salsify/rspec_doc_string.rb', line 48

def on_send(node)
  _receiver, _method_name, *args = *node
  return unless documented_method?(node) && args.first&.str_type?

  check_quotes(args.first)
end