From 4b5ba3215975df1dd8e9c7eacffcf02abfffa92e Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Mon, 2 Apr 2018 23:05:42 -0400 Subject: [PATCH] Bring back the formatter that was unexpectedly removed closes #103 --- lib/did_you_mean.rb | 16 ++++++++++++++++ test/deprecated_formatter_test.rb | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/deprecated_formatter_test.rb 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