Skip to content

Commit

Permalink
Change superclass for InferredSpecType
Browse files Browse the repository at this point in the history
This copies some of the code from the `RuboCop::RSpec::Language` module
in rubocop-rspec, and it no longer allows the user to configure aliases
for example group methods (`describe`, `fcontext`, `xfeature` etc.).
  • Loading branch information
bquorning committed Apr 1, 2024
1 parent e568e14 commit 9a82b3b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
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

0 comments on commit 9a82b3b

Please sign in to comment.