Class: RuboCop::Cop::RSpec::ExampleWording

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/rspec/example_wording.rb

Overview

Do not use should when describing your tests. see: betterspecs.org/#should

Examples:

# bad
it 'should find nothing' do
end

# good
it 'finds nothing' do
end

Constant Summary collapse

MSG =
'Do not use should when describing your tests.'

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



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

def on_block(node)
  method, _, _ = *node
  _, method_name, *args = *method

  return unless method_name == :it

  arguments = *(args.first)
  message = arguments.first.to_s
  return unless message.start_with?('should')

  add_offense(method, :selector, MSG)
end