summaryrefslogtreecommitdiff
path: root/test/did_you_mean/test_verbose_formatter.rb
blob: 411f175180ff5a47e9eb5885225ece2d3ff108a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require_relative './helper'

class VerboseFormatterTest < Test::Unit::TestCase
  class ErrorHighlightDummyFormatter
    def message_for(spot)
      ""
    end
  end

  def setup
    require_relative File.join(DidYouMean::TestHelper.root, 'verbose')

    DidYouMean.formatter = DidYouMean::VerboseFormatter.new

    if defined?(ErrorHighlight)
      @error_highlight_old_formatter = ErrorHighlight.formatter
      ErrorHighlight.formatter = ErrorHighlightDummyFormatter.new
    end
  end

  def teardown
    DidYouMean.formatter = DidYouMean::PlainFormatter.new

    if defined?(ErrorHighlight)
      ErrorHighlight.formatter = @error_highlight_old_formatter
    end
  end

  def test_message
    @error = assert_raise(NoMethodError){ 1.zeor? }

    assert_match <<~MESSAGE.strip, @error.message
      undefined method `zeor?' for 1:Integer

          Did you mean? zero?
    MESSAGE
  end
end