Sha256: 66f27af9a47cd40fde8eb65c126123adc811c59e6beec4ad17f7105104fa8cc7
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require 'rubocop' module RubocopHelper attr_accessor :cop private RUBY_VERSION = 2.5 private_constant :RUBY_VERSION def assert_no_offenses(source) investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil)) assert_predicate(cop.offenses, :empty?, "Did not expect Rubocop to find offenses") end def assert_offense(source) investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil)) refute_predicate(cop.offenses, :empty?, "Expected Rubocop to find offenses") end def assert_no_autocorrect(source) corrected = autocorrect_source(source) assert_equal(source, corrected) end def autocorrect_source(source) RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {} RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {} cop.instance_variable_get(:@options)[:auto_correct] = true processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil) investigate(processed_source) corrector = RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections) corrector.rewrite end def investigate(processed_source) forces = RuboCop::Cop::Force.all.each_with_object([]) do |klass, instances| next unless cop.join_force?(klass) instances << klass.new([cop]) end commissioner = RuboCop::Cop::Commissioner.new([cop], forces, raise_error: true) commissioner.investigate(processed_source) commissioner end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
statsd-instrument-3.0.1 | test/helpers/rubocop_helper.rb |