Class: RuboCop::Cop::RSpec::AroundBlock

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

Overview

Checks that around blocks actually run the test.

Examples:

# bad
around do
  some_method
end

around do |test|
  some_method
end

# good
around do |test|
  some_method
  test.call
end

around do |test|
  some_method
  test.run
end

Constant Summary collapse

MSG_NO_ARG =
'Test object should be passed to around block.'
MSG_UNUSED_ARG =
'You should call `%<arg>s.call` '\
'or `%<arg>s.run`.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_block(node) ⇒ Object


41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/rspec/around_block.rb', line 41

def on_block(node)
  hook(node) do |(example_proxy)|
    if example_proxy.nil?
      add_no_arg_offense(node)
    else
      check_for_unused_proxy(node, example_proxy)
    end
  end
end