Skip to content

Commit 90fbd13

Browse files
fixed undefined issue running specs described in rubocop/rubocop#11169 issue. borrowed #registry code from rubocop cop_helper
1 parent 31117db commit 90fbd13

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

spec/support/standard_runner.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
module StandardRunner
55
def self.included(example_group)
66
example_group.include FilesystemHelpers
7+
example_group.before do
8+
allow_any_instance_of(RuboCop::AST::ProcessedSource).to receive(:registry).and_return(registry)
9+
end
710
example_group.around do |example|
811
Dir.mktmpdir do |code|
912
@code = code
@@ -21,10 +24,22 @@ def issues(output = @engine_output)
2124
end
2225

2326
def run_engine(config = nil)
27+
@config = config
2428
io = StringIO.new
25-
standard = CC::Engine::Standard.new(@code, config, io)
29+
standard = CC::Engine::Standard.new(@code, @config, io)
2630
standard.run
2731

2832
@engine_output = io.string
2933
end
34+
35+
def registry
36+
# https://github.com/rubocop/rubocop/blob/master/lib/rubocop/rspec/cop_helper.rb
37+
@registry ||= begin
38+
keys = RuboCop::Config.new(@config || {}, "#{Dir.pwd}/.rubocop.yml").keys
39+
cops = keys.map { |directive| RuboCop::Cop::Registry.global.find_cops_by_directive(directive) }.flatten
40+
cops << cop_class if defined?(cop_class) && !cops.include?(cop_class)
41+
cops.compact!
42+
RuboCop::Cop::Registry.new(cops)
43+
end
44+
end
3045
end

0 commit comments

Comments
 (0)