Class: RuboCop::Cop::Salsify::RspecDotNotSelfDot

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

Overview

Use “.<class method>” instead of “self.<class method>” in RSpec example group descriptions.

Examples:


# good
describe ".does_stuff" do
  ...
end

# bad
describe "self.does_stuff" do
  ...
end

Constant Summary collapse

SELF_DOT_REGEXP =
/["']self\./.freeze
MSG =
'Use ".<class method>" instead of "self.<class method>" for example group description.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/salsify/rspec_dot_not_self_dot.rb', line 30

def on_send(node)
  example_group_match(node) do |doc|
    next unless SELF_DOT_REGEXP.match?(doc.source)

    add_offense(doc) do |corrector|
      corrector.remove(Parser::Source::Range.new(doc.source_range.source_buffer,
                                                 doc.source_range.begin_pos + 1,
                                                 doc.source_range.begin_pos + 5))
    end
  end
end