lib/rubocop/rspec/description_extractor.rb in rubocop-rspec-1.21.0 vs lib/rubocop/rspec/description_extractor.rb in rubocop-rspec-1.22.0

- old
+ new

@@ -17,21 +17,25 @@ attr_reader :code_objects # Decorator of a YARD code object for working with documented rspec cops class CodeObject + COP_CLASS_NAMES = %w[RuboCop::Cop RuboCop::Cop::RSpec::Cop].freeze RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'.freeze def initialize(yardoc) @yardoc = yardoc end # Test if the YARD code object documents a concrete rspec cop class # # @return [Boolean] def rspec_cop? - class_documentation? && rspec_cop_namespace? && !abstract? + class_documentation? && + rspec_cop_namespace? && + cop_subclass? && + !abstract? end # Configuration for the documented cop that would live in default.yml # # @return [Hash] @@ -57,9 +61,17 @@ documented_constant.start_with?(RSPEC_NAMESPACE) end def documented_constant yardoc.to_s + end + + def cop_subclass? + # YARD superclass resolution is a bit flaky: All classes loaded before + # RuboCop::Cop::WorkaroundCop are shown as having RuboCop::Cop as + # superclass, while all the following classes are listed as having + # RuboCop::Cop::RSpec::Cop as their superclass. + COP_CLASS_NAMES.include?(yardoc.superclass.path) end def abstract? yardoc.tags.any? { |tag| tag.tag_name.eql?('abstract') } end