diff --git a/lib/did_you_mean.rb b/lib/did_you_mean.rb index e0a80533..22cd4bf2 100644 --- a/lib/did_you_mean.rb +++ b/lib/did_you_mean.rb @@ -50,4 +50,20 @@ def self.formatter=(formatter) end self.formatter = PlainFormatter.new + + # Deprecated formatter + class Formatter #:nodoc: + def initialize(corrections = []) + @corrections = corrections + end + + def to_s + return "" if @corrections.empty? + + output = "\nDid you mean? ".dup + output << @corrections.join("\n ") + end + end + + deprecate_constant :Formatter end diff --git a/test/deprecated_formatter_test.rb b/test/deprecated_formatter_test.rb new file mode 100644 index 00000000..f9f6fa11 --- /dev/null +++ b/test/deprecated_formatter_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class DeprecatedFormatterTest < Minitest::Test + def test_deprecated_formatter + assert_output nil, "test/deprecated_formatter_test.rb:6: warning: constant DidYouMean::Formatter is deprecated\n" do + assert_equal "\nDid you mean? does_exist", ::DidYouMean::Formatter.new(['does_exist']).to_s + end + end +end