-
-
Notifications
You must be signed in to change notification settings - Fork 940
Expand file tree
/
Copy pathtest_exception.rb
More file actions
43 lines (37 loc) · 775 Bytes
/
test_exception.rb
File metadata and controls
43 lines (37 loc) · 775 Bytes
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
require 'test/unit'
class TestException < Test::Unit::TestCase
def raise_an_error
raise "an error"
end
def rescue_an_error
begin
raise_an_error
rescue
raise
end
end
def test_good_stack_trace
begin
rescue_an_error
rescue RuntimeError => e
assert_match(/raise_an_error/, e.backtrace[0])
end
end
def raise_circular_cause
begin
raise "error 1"
rescue => e1
raise "error 2" rescue e2 = $!
raise e1, cause: e2
end
end
def test_circular_cause_handle
begin
raise_circular_cause
rescue => e
assert_match(/raise_circular_cause/, e.backtrace[0])
assert_equal("circular causes", e.message)
assert_equal("error 1", e.cause.message)
end
end
end