Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change superclass for InferredSpecType #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/rubocop/cop/rspec_rails/inferred_spec_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module RSpecRails
# # spec/services/user_spec.rb
# RSpec.describe User, type: :common do
# end
class InferredSpecType < ::RuboCop::Cop::RSpec::Base
class InferredSpecType < ::RuboCop::Cop::Base
extend AutoCorrector

MSG = 'Remove redundant spec type.'
Expand Down Expand Up @@ -85,6 +85,35 @@ def on_block(node)
)
PATTERN

# @!method example_group?(node)
def_node_matcher :example_group?, <<~PATTERN
({block numblock}
(send #rspec? #ExampleGroups.all ...
) ...
)
PATTERN

# @!method rspec?(node)
def_node_matcher :rspec?, <<~PATTERN
{
(const {nil? cbase} :RSpec)
nil?
}
PATTERN

module ExampleGroups # :nodoc:
REGULAR = %i[describe context feature example_group].freeze
SKIPPED = %i[xdescribe xcontext xfeature].freeze
FOCUSED = %i[fdescribe fcontext ffeature].freeze
ALL = REGULAR + SKIPPED + FOCUSED

class << self
def all(element)
ALL.include?(element)
end
end
end

# @param [RuboCop::AST::Corrector] corrector
# @param [RuboCop::AST::Node] node
def autocorrect(corrector, node)
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/rspec_rails/description_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def to_h

# Decorator of a YARD code object for working with documented rspec cops
class CodeObject
RSPEC_RAILS_COP_CLASS_NAME = 'RuboCop::Cop::RSpec::Base'
RUBOCOP_COP_CLASS_NAME = 'RuboCop::Cop::Base'

def initialize(yardoc)
Expand Down Expand Up @@ -57,8 +56,7 @@ def documented_constant
end

def cop_subclass?
yardoc.superclass.path == RSPEC_RAILS_COP_CLASS_NAME ||
yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
yardoc.superclass.path == RUBOCOP_COP_CLASS_NAME
end

def abstract?
Expand Down