@@ -49,21 +49,6 @@ def initialize(data)
4949 end
5050 end
5151
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-
6752 it "raises RuntimeError if no exception class is given" do
6853 -> { @object . raise } . should raise_error ( RuntimeError , "" )
6954 end
@@ -74,7 +59,7 @@ def initialize(data)
7459 end
7560
7661 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" )
7863 end
7964
8065 it "passes no arguments to the constructor when given only an exception class" do
@@ -86,19 +71,32 @@ def initialize
8671 end
8772
8873 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" )
9077 end
9178
9279 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" )
9481 end
9582
9683 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" )
9885 end
9986
10087 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" )
102100 end
103101
104102 it "re-raises a previously rescued exception without overwriting the backtrace" do
0 commit comments