@@ -10,12 +10,32 @@ module BetterErrors
10
10
its ( :message ) { is_expected . to eq "whoops" }
11
11
its ( :type ) { is_expected . to eq RuntimeError }
12
12
13
- context "when the exception wraps another exception" do
13
+ context 'when the exception is an ActionView::Template::Error that responds to #cause (Rails 6+)' do
14
+ before do
15
+ stub_const (
16
+ "ActionView::Template::Error" ,
17
+ Class . new ( StandardError ) do
18
+ def cause
19
+ RuntimeError . new ( "something went wrong!" )
20
+ end
21
+ end
22
+ )
23
+ end
24
+ let ( :exception ) {
25
+ ActionView ::Template ::Error . new ( "undefined method `something!' for #<Class:0x00deadbeef>" )
26
+ }
27
+
28
+ its ( :message ) { is_expected . to eq "something went wrong!" }
29
+ its ( :type ) { is_expected . to eq RuntimeError }
30
+ end
31
+
32
+ context 'when the exception is a Rails < 6 exception that has an #original_exception' do
14
33
let ( :original_exception ) { RuntimeError . new ( "something went wrong!" ) }
15
34
let ( :exception ) { double ( :original_exception => original_exception ) }
16
35
17
36
its ( :exception ) { is_expected . to eq original_exception }
18
- its ( :message ) { is_expected . to eq "something went wrong!" }
37
+ its ( :message ) { is_expected . to eq "something went wrong!" }
38
+ its ( :type ) { is_expected . to eq RuntimeError }
19
39
end
20
40
21
41
context "when the exception is a SyntaxError" do
@@ -50,35 +70,20 @@ module BetterErrors
50
70
end
51
71
end
52
72
53
- context "when the exception is an ActionView::Template::Error" do
54
- before do
55
- stub_const (
56
- "ActionView::Template::Error" ,
57
- Class . new ( StandardError ) do
58
- def file_name
59
- "app/views/foo/bar.haml"
60
- end
61
-
62
- def line_number
63
- 42
64
- end
65
- end
66
- )
67
- end
68
-
69
- let ( :exception ) {
70
- ActionView ::Template ::Error . new ( "undefined method `something!' for #<Class:0x00deadbeef>" )
71
- }
72
-
73
- its ( :message ) { is_expected . to eq "undefined method `something!' for #<Class:0x00deadbeef>" }
74
- its ( :type ) { is_expected . to eq ActionView ::Template ::Error }
75
-
76
- it "has the right filename and line number in the backtrace" do
77
- expect ( subject . backtrace . first . filename ) . to eq ( "app/views/foo/bar.haml" )
78
- expect ( subject . backtrace . first . line ) . to eq ( 42 )
79
- end
80
- end
81
-
73
+ # context "when the exception is an ActionView::Template::Error" do
74
+ #
75
+ # let(:exception) {
76
+ # ActionView::Template::Error.new("undefined method `something!' for #<Class:0x00deadbeef>")
77
+ # }
78
+ #
79
+ # its(:message) { is_expected.to eq "undefined method `something!' for #<Class:0x00deadbeef>" }
80
+ #
81
+ # it "has the right filename and line number in the backtrace" do
82
+ # expect(subject.backtrace.first.filename).to eq("app/views/foo/bar.haml")
83
+ # expect(subject.backtrace.first.line).to eq(42)
84
+ # end
85
+ # end
86
+ #
82
87
context "when the exception is a Coffeelint syntax error" do
83
88
before do
84
89
stub_const ( "Sprockets::Coffeelint::Error" , Class . new ( SyntaxError ) )
0 commit comments