Revision 393538303231 () - Diff

Link to this snippet: https://friendpaste.com/6p6ou6TLu41KriuWAMl3QF
Embed:
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
44
45
46
47
48
49
50
51
52
From a3f952616a416480f9f382248c39d0f37b1385b2 Mon Sep 17 00:00:00 2001
From: Graham <graham-storm-git@ript.net>
Date: Thu, 28 Jan 2010 15:46:33 -0700
Subject: [PATCH] Updated spec for issue when raising an object instance with a message

---
spec/ruby/language/rescue_spec.rb | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index 2bd01eb..1b1bd11 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -3,6 +3,12 @@ class SpecificExampleException < StandardError
end
class OtherCustomException < StandardError
end
+class CustomArgumentException < StandardError
+ attr_reader :val
+ def initialize(val)
+ @val = val
+ end
+end
def exception_list
[SpecificExampleException, ZeroDivisionError]
@@ -24,6 +30,23 @@ describe "The rescue keyword" do
e.message.should == "some text"
end
end
+
+ it "can take an object instance instead of a class to raise" do
+ begin
+ raise CustomArgumentException.new(1)
+ rescue CustomArgumentException => e
+ e.val.should == 1
+ end
+ end
+
+ it "can take an object instance instead of a class to raise as well as a message" do
+ begin
+ raise CustomArgumentException.new(1), "some text"
+ rescue CustomArgumentException => e
+ e.val.should == 1
+ e.message.should == "some text"
+ end
+ end
it "can rescue multiple raised exceptions with a single rescue block" do
lambda do
--
1.6.1.2