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