Class: RuboCop::Cop::RSpec::EnforceDescription

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/enforce_description.rb

Constant Summary collapse

MSG_CONTEXT =
"Context description should end with [場合].".freeze
MSG_IT =
"Example description should end with [こと].".freeze
RESTRICT_ON_SEND =
%i(context it).freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/rspec/enforce_description.rb', line 18

def on_send(node)
  context_with_description?(node) do |description|
    return if description.end_with?("場合")

    add_offense(node.first_argument.loc.expression, message: MSG_CONTEXT)
  end

  it_with_description?(node) do |description|
    return if description.end_with?("こと")

    add_offense(node.first_argument.loc.expression, message: MSG_IT)
  end
end