Skip to content

Commit 69f5012

Browse files
committed
Cleanup workaround
It seems that the workaround was exclusively used in the DescriptionExtractor spec.
1 parent afe426c commit 69f5012

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

lib/rubocop/cop/rspec/cop.rb

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@
22

33
module RuboCop
44
module Cop
5-
WorkaroundCop = Cop.dup
6-
7-
# Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
8-
# the inherited method without breaking functionality
9-
class WorkaroundCop
10-
# Remove the Cop.inherited method to be a noop. Our RSpec::Cop
11-
# class will invoke the inherited hook instead
12-
class << self
13-
undef inherited
14-
def inherited(*) end
15-
end
16-
17-
# Special case `Module#<` so that the rspec support rubocop exports
18-
# is compatible with our subclass
19-
def self.<(other)
20-
other.equal?(RuboCop::Cop::Cop) || super
21-
end
22-
end
23-
private_constant(:WorkaroundCop)
24-
255
module RSpec
266
# @abstract parent class to rspec cops
277
#
@@ -37,7 +17,7 @@ module RSpec
3717
# Patterns:
3818
# - '_test.rb$'
3919
# - '(?:^|/)test/'
40-
class Cop < WorkaroundCop
20+
class Cop < ::RuboCop::Cop::Cop
4121
include RuboCop::RSpec::Language
4222
include RuboCop::RSpec::Language::NodePattern
4323

lib/rubocop/rspec/description_extractor.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ def documented_constant
6868
end
6969

7070
def cop_subclass?
71-
# YARD superclass resolution is a bit flaky: All classes loaded before
72-
# RuboCop::Cop::WorkaroundCop are shown as having RuboCop::Cop as
73-
# superclass, while all the following classes are listed as having
74-
# RuboCop::Cop::RSpec::Cop as their superclass.
71+
# FIXME: simplify
72+
7573
COP_CLASS_NAMES.include?(yardoc.superclass.path)
7674
end
7775

spec/rubocop/cop/rspec/cop_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
end
2121

2222
let(:fake_cop) do
23-
stub_const('RuboCop::RSpec', Module.new)
2423
# rubocop:disable Style/ClassAndModuleChildren
2524
# rubocop:disable RSpec/LeakyConstantDeclaration
2625
class RuboCop::RSpec::FakeCop < described_class

spec/rubocop/rspec/description_extractor_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ def bar
4242
YARD::Registry.all
4343
end
4444

45+
let(:temp_class) do
46+
temp = RuboCop::Cop::Cop.dup
47+
temp.class_exec do
48+
class << self
49+
undef inherited
50+
def inherited(*) end
51+
end
52+
end
53+
temp
54+
end
55+
4556
def stub_cop_const(name)
46-
stub_const(
47-
"RuboCop::Cop::RSpec::#{name}",
48-
Class.new(RuboCop::Cop.const_get(:WorkaroundCop))
49-
)
57+
stub_const("RuboCop::Cop::RSpec::#{name}", Class.new(temp_class))
5058
end
5159

5260
before do

0 commit comments

Comments
 (0)