@@ -49,21 +49,6 @@ def initialize(data)
49
49
end
50
50
end
51
51
52
- it "does not allow message and extra keyword arguments" do
53
- data_error = Class . new ( StandardError ) do
54
- attr_reader :data
55
- def initialize ( data )
56
- @data = data
57
- end
58
- end
59
-
60
- -> { @object . raise ( data_error , { a : 1 } , b : 2 ) } . should raise_error ( StandardError ) do |e |
61
- [ TypeError , ArgumentError ] . should . include? ( e . class )
62
- end
63
-
64
- -> { @object . raise ( data_error , { a : 1 } , [ ] , b : 2 ) } . should raise_error ( ArgumentError )
65
- end
66
-
67
52
it "raises RuntimeError if no exception class is given" do
68
53
-> { @object . raise } . should raise_error ( RuntimeError , "" )
69
54
end
@@ -74,7 +59,7 @@ def initialize(data)
74
59
end
75
60
76
61
it "raises a RuntimeError if string given" do
77
- -> { @object . raise ( "a bad thing" ) } . should raise_error ( RuntimeError )
62
+ -> { @object . raise ( "a bad thing" ) } . should raise_error ( RuntimeError , "a bad thing" )
78
63
end
79
64
80
65
it "passes no arguments to the constructor when given only an exception class" do
@@ -86,19 +71,32 @@ def initialize
86
71
end
87
72
88
73
it "raises a TypeError when passed a non-Exception object" do
89
- -> { @object . raise ( Object . new ) } . should raise_error ( TypeError )
74
+ -> { @object . raise ( Object . new ) } . should raise_error ( TypeError , "exception class/object expected" )
75
+ -> { @object . raise ( Object . new , "message" ) } . should raise_error ( TypeError , "exception class/object expected" )
76
+ -> { @object . raise ( Object . new , "message" , [ ] ) } . should raise_error ( TypeError , "exception class/object expected" )
90
77
end
91
78
92
79
it "raises a TypeError when passed true" do
93
- -> { @object . raise ( true ) } . should raise_error ( TypeError )
80
+ -> { @object . raise ( true ) } . should raise_error ( TypeError , "exception class/object expected" )
94
81
end
95
82
96
83
it "raises a TypeError when passed false" do
97
- -> { @object . raise ( false ) } . should raise_error ( TypeError )
84
+ -> { @object . raise ( false ) } . should raise_error ( TypeError , "exception class/object expected" )
98
85
end
99
86
100
87
it "raises a TypeError when passed nil" do
101
- -> { @object . raise ( nil ) } . should raise_error ( TypeError )
88
+ -> { @object . raise ( nil ) } . should raise_error ( TypeError , "exception class/object expected" )
89
+ end
90
+
91
+ it "raises TypeError when passed a non-Exception object but it responds to #exception method that doesn't return an instance of Exception class" do
92
+ e = Object . new
93
+ def e . exception
94
+ Array
95
+ end
96
+
97
+ -> {
98
+ @object . raise e
99
+ } . should raise_error ( TypeError , "exception object expected" )
102
100
end
103
101
104
102
it "re-raises a previously rescued exception without overwriting the backtrace" do
0 commit comments