From f8c03c6c753a6efd3a33908fef7a80ea18a7703f Mon Sep 17 00:00:00 2001 From: Camilo Payan Date: Thu, 10 Nov 2022 15:27:11 -0500 Subject: [PATCH] Adds configuration and registry information to cop invoker This was added to accomodate the changes in [this pull request](https://github.com/rubocop/rubocop/pull/10987) It does seem as though these changes should be reflected in the ProcessedSource module of rubocop-AST or in the cop model in rubocop, and shouldn't need this change to our test code. --- test/cop_invoker.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/cop_invoker.rb b/test/cop_invoker.rb index 0dc5e1dd..92c4ebc6 100644 --- a/test/cop_invoker.rb +++ b/test/cop_invoker.rb @@ -22,6 +22,8 @@ def assert_offense(cop, source) @last_source = RuboCop::ProcessedSource.new( expected.plain_source, RUBY_VERSION, nil ) + @last_source.config = configuration + @last_source.registry = registry raise "Error parsing example code" unless @last_source.valid_syntax? @@ -206,4 +208,21 @@ def parse_source(source, file = nil) RuboCop::ProcessedSource.new(source, RUBY_VERSION, file) end + + def configuration + @configuration ||= if defined?(config) + config + else + RuboCop::Config.new({}, "#{Dir.pwd}/.rubocop.yml") + end + end + + def registry + @registry ||= begin + cops = configuration.keys.map { |cop| RuboCop::Cop::Registry.global.find_by_cop_name(cop) } + cops << cop_class if defined?(cop_class) && !cops.include?(cop_class) + cops.compact! + RuboCop::Cop::Registry.new(cops) + end + end end