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

Inherits:
Cop
  • 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.'.freeze
MSG_UNUSED_ARG =
'You should call `%<arg>s.call` '\
'or `%<arg>s.run`.'.freeze

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL

Instance Method Summary collapse

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_block(node) ⇒ Object



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

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