forked from rubocop/rubocop-rspec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pending.rb
66 lines (57 loc) · 1.55 KB
/
pending.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
# Checks for any pending or skipped examples.
#
# @example
# # bad
# describe MyClass do
# it "should be true"
# end
#
# describe MyClass do
# it "should be true", skip: true do
# expect(1).to eq(2)
# end
# end
#
# describe MyClass do
# it "should be true" do
# pending
# end
# end
#
# describe MyClass do
# xit "should be true" do
# end
# end
#
# # good
# describe MyClass do
# end
class Pending < Cop
MSG = 'Pending spec found.'
PENDING = Examples::PENDING + Examples::SKIPPED + ExampleGroups::SKIPPED
SKIPPABLE = ExampleGroups::GROUPS + Examples::EXAMPLES
def_node_matcher :skippable?, SKIPPABLE.send_pattern
def_node_matcher :skipped_in_metadata?, <<-PATTERN
{
(send _ _ <#skip_or_pending? ...>)
(send _ _ ... (hash <(pair #skip_or_pending? true) ...>))
}
PATTERN
def_node_matcher :skip_or_pending?, '{(sym :skip) (sym :pending)}'
def_node_matcher :pending_block?, PENDING.send_pattern
def on_send(node)
return unless pending_block?(node) || skipped?(node)
add_offense(node)
end
private
def skipped?(node)
skippable?(node) && skipped_in_metadata?(node)
end
end
end
end
end