aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/template_error_test.rb
blob: 643c29602b469670d285521a5f4b493de1c17e86 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require "abstract_unit"

class TemplateErrorTest < ActiveSupport::TestCase
  def test_provides_original_message
    error = begin
      raise Exception.new("original")
    rescue Exception
      raise ActionView::Template::Error.new("test") rescue $!
    end

    assert_equal "original", error.message
  end

  def test_provides_original_backtrace
    error = begin
      original_exception = Exception.new
      original_exception.set_backtrace(%W[ foo bar baz ])
      raise original_exception
    rescue Exception
      raise ActionView::Template::Error.new("test") rescue $!
    end

    assert_equal %W[ foo bar baz ], error.backtrace
  end

  def test_provides_useful_inspect
    error = begin
      raise Exception.new("original")
    rescue Exception
      raise ActionView::Template::Error.new("test") rescue $!
    end

    assert_equal "#<ActionView::Template::Error: original>", error.inspect
  end

  def test_annotated_source_code_returns_empty_array_if_source_cant_be_found
    template = Class.new do
      def identifier
        "something"
      end
    end.new

    error = begin
      raise
    rescue
      raise ActionView::Template::Error.new(template) rescue $!
    end

    assert_equal [], error.annotated_source_code
  end
end