Skip to content

Commit

Permalink
Bring back the formatter that was unexpectedly removed
Browse files Browse the repository at this point in the history
closes #103
  • Loading branch information
yuki24 committed Apr 3, 2018
1 parent 8f72cbb commit 4b5ba32
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/did_you_mean.rb
Expand Up @@ -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
9 changes: 9 additions & 0 deletions 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

0 comments on commit 4b5ba32

Please sign in to comment.