File: exception_mapper_test.rb

package info (click to toggle)
ruby-web-console 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 632 kB
  • sloc: ruby: 1,496; javascript: 497; sh: 19; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download
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
# frozen_string_literal: true

require "test_helper"

module WebConsole
  class ExceptionMapperTest < ActiveSupport::TestCase
    test "#first tries to find the first application binding" do
      Rails.stubs(:root).returns Pathname(__FILE__).parent

      mapper = ExceptionMapper.new(External.exception)

      assert_equal __FILE__, SourceLocation.new(mapper.first).path
    end

    test ".[] tries match the binding for trace index" do
      exception = External.exception
      mapper = ExceptionMapper.new(exception)

      last_index = exception.backtrace.count - 1
      file, line = exception.backtrace.last.split(":")

      assert_equal file, SourceLocation.new(mapper[last_index]).path
      assert_equal line.to_i, SourceLocation.new(mapper[last_index]).lineno
    end

    test ".[] fall backs to index if no trace can be found" do
      exception = External.exception
      mapper = ExceptionMapper.new(exception)

      unbound_index = exception.backtrace.count

      assert_nil mapper[unbound_index]
    end
  end
end