Skip to content

Commit

Permalink
Adds configuration and registry information to cop invoker
Browse files Browse the repository at this point in the history
This was added to accomodate the changes in [this pull request](rubocop/rubocop#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.
  • Loading branch information
camilopayan authored and searls committed Dec 3, 2022
1 parent 11dff94 commit f8c03c6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/cop_invoker.rb
Expand Up @@ -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?

Expand Down Expand Up @@ -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

0 comments on commit f8c03c6

Please sign in to comment.