Class: Rubocop::Cop::RSpec::SingleLineHook

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

Overview

Checks for single-line hook blocks

Examples:


# bad
before { do_something }
after(:each) { undo_something }

# good
before do
  do_something
end

after(:each) do
  undo_something
end

Constant Summary collapse

MESSAGE =
"Don't use single-line hook blocks."

Instance Method Summary collapse

Instance Method Details

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



33
34
35
36
37
38
# File 'lib/rubocop/cop/rspec/single_line_hook.rb', line 33

def on_block(node)
  return unless node.single_line?
  return unless rspec_hook?(node)

  add_offense(node, message: MESSAGE)
end

#rspec_hook?(node) ⇒ Object



29
30
31
# File 'lib/rubocop/cop/rspec/single_line_hook.rb', line 29

def_node_search :rspec_hook?, <<~PATTERN
  (send nil? {:after :around :before} ...)
PATTERN