class RuboCop::Cop::RSpec::AroundBlock
Checks that around blocks actually run the test.
@example
# 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
Constants
- MSG_NO_ARG
- MSG_UNUSED_ARG
Public Instance Methods
Source
# File lib/rubocop/cop/rspec/around_block.rb, line 49 def on_block(node) hook_block(node) do |(example_proxy)| if example_proxy.nil? add_no_arg_offense(node) else check_for_unused_proxy(node, example_proxy) end end end
Source
# File lib/rubocop/cop/rspec/around_block.rb, line 59 def on_numblock(node) hook_numblock(node) do check_for_numblock(node) end end
Private Instance Methods
Source
# File lib/rubocop/cop/rspec/around_block.rb, line 67 def add_no_arg_offense(node) add_offense(node, message: MSG_NO_ARG) end
Source
# File lib/rubocop/cop/rspec/around_block.rb, line 82 def check_for_numblock(block) find_arg_usage(block) do |usage| return if usage.include?(s(:lvar, :_1)) end add_offense( block.children.last, message: format(MSG_UNUSED_ARG, arg: :_1) ) end
Source
# File lib/rubocop/cop/rspec/around_block.rb, line 71 def check_for_unused_proxy(block, proxy) find_arg_usage(block) do |usage| return if usage.include?(s(:lvar, proxy.name)) end add_offense( proxy, message: format(MSG_UNUSED_ARG, arg: proxy.name) ) end