lib/rubocop/minitest/assert_offense.rb in rubocop-minitest-0.25.1 vs lib/rubocop/minitest/assert_offense.rb in rubocop-minitest-0.26.0

- old
+ new

@@ -68,19 +68,31 @@ # end # end # RUBY # # assert_no_corrections + # + # rubocop:disable Metrics/ModuleLength module AssertOffense private def setup cop_name = self.class.to_s.delete_suffix('Test') @cop = RuboCop::Cop::Minitest.const_get(cop_name).new end + def format_offense(source, **replacements) + replacements.each do |keyword, value| + value = value.to_s + source = source.gsub("%{#{keyword}}", value) + .gsub("^{#{keyword}}", '^' * value.size) + .gsub("_{#{keyword}}", ' ' * value.size) + end + source + end + def assert_no_offenses(source, file = nil) setup_assertion offenses = inspect_source(source, @cop, file) @@ -88,15 +100,16 @@ actual_annotations = expected_annotations.with_offense_annotations(offenses) assert_equal(source, actual_annotations.to_s) end - def assert_offense(source, file = nil) + def assert_offense(source, file = nil, **replacements) setup_assertion @cop.instance_variable_get(:@options)[:autocorrect] = true + source = format_offense(source, **replacements) expected_annotations = RuboCop::RSpec::ExpectOffense::AnnotatedSource.parse(source) if expected_annotations.plain_source == source raise 'Use `assert_no_offenses` to assert that no offenses are found' end @@ -203,7 +216,8 @@ def ruby_version 2.6 end end + # rubocop:enable Metrics/ModuleLength end end