lib/rubocop/cop/rspec/pending.rb in rubocop-rspec-1.35.0 vs lib/rubocop/cop/rspec/pending.rb in rubocop-rspec-1.36.0
- old
+ new
@@ -10,10 +10,16 @@
# 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
#
@@ -26,46 +32,34 @@
# describe MyClass do
# end
class Pending < Cop
MSG = 'Pending spec found.'
- PENDING_EXAMPLES = Examples::PENDING + Examples::SKIPPED \
- + ExampleGroups::SKIPPED
- SKIPPABLE_EXAMPLES = ExampleGroups::GROUPS + Examples::EXAMPLES
- SKIPPABLE_SELECTORS = SKIPPABLE_EXAMPLES.node_pattern_union
+ PENDING = Examples::PENDING + Examples::SKIPPED + ExampleGroups::SKIPPED
+ SKIPPABLE = ExampleGroups::GROUPS + Examples::EXAMPLES
- SKIP_SYMBOL = s(:sym, :skip)
- PENDING_SYMBOL = s(:sym, :pending)
+ def_node_matcher :skippable?, SKIPPABLE.send_pattern
- def_node_matcher :metadata, <<-PATTERN
- {(send #{RSPEC} #{SKIPPABLE_SELECTORS} ... (hash $...))
- (send #{RSPEC} #{SKIPPABLE_SELECTORS} $...)}
+ def_node_matcher :skipped_in_metadata?, <<-PATTERN
+ {
+ (send _ _ <#skip_or_pending? ...>)
+ (send _ _ ... (hash <(pair #skip_or_pending? true) ...>))
+ }
PATTERN
- def_node_matcher :pending_block?, PENDING_EXAMPLES.send_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_from_metadata?(node)
+ return unless pending_block?(node) || skipped?(node)
add_offense(node)
end
private
- def skipped_from_metadata?(node)
- (metadata(node) || []).any? { |n| skip_node?(n) }
- end
-
- def skip_node?(node)
- if node.respond_to?(:key)
- skip_symbol?(node.key) && node.value.truthy_literal?
- else
- skip_symbol?(node)
- end
- end
-
- def skip_symbol?(symbol_node)
- [SKIP_SYMBOL, PENDING_SYMBOL].include?(symbol_node)
+ def skipped?(node)
+ skippable?(node) && skipped_in_metadata?(node)
end
end
end
end
end