-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
skip_block_inside_example.rb
46 lines (40 loc) · 1 KB
/
skip_block_inside_example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks for passing a block to `skip` within examples.
#
# @example
# # bad
# it 'does something' do
# skip 'not yet implemented' do
# do_something
# end
# end
#
# # good
# it 'does something' do
# skip 'not yet implemented'
# do_something
# end
#
# # good - when outside example
# skip 'not yet implemented' do
# end
#
class SkipBlockInsideExample < Base
MSG = "Don't pass a block to `skip` inside examples."
def on_block(node)
return unless node.method?(:skip)
return unless inside_example?(node)
add_offense(node)
end
alias on_numblock on_block
private
def inside_example?(node)
node.each_ancestor(:block).any? { |ancestor| example?(ancestor) }
end
end
end
end
end