@@ -8,7 +8,8 @@ class UnexpectedException < Exception; end
8
8
describe RaiseErrorMatcher do
9
9
it "matches when the proc raises the expected exception" do
10
10
proc = Proc . new { raise ExpectedException }
11
- RaiseErrorMatcher . new ( ExpectedException , nil ) . matches? ( proc ) . should == true
11
+ matcher = RaiseErrorMatcher . new ( ExpectedException , nil )
12
+ matcher . matches? ( proc ) . should == true
12
13
end
13
14
14
15
it "executes it's optional block if matched" do
@@ -25,28 +26,50 @@ class UnexpectedException < Exception; end
25
26
26
27
it "matches when the proc raises the expected exception with the expected message" do
27
28
proc = Proc . new { raise ExpectedException , "message" }
28
- RaiseErrorMatcher . new ( ExpectedException , "message" ) . matches? ( proc ) . should == true
29
+ matcher = RaiseErrorMatcher . new ( ExpectedException , "message" )
30
+ matcher . matches? ( proc ) . should == true
31
+ end
32
+
33
+ it "matches when the proc raises the expected exception with a matching message" do
34
+ proc = Proc . new { raise ExpectedException , "some message" }
35
+ matcher = RaiseErrorMatcher . new ( ExpectedException , /some/ )
36
+ matcher . matches? ( proc ) . should == true
29
37
end
30
38
31
39
it "does not match when the proc does not raise the expected exception" do
32
- proc = Proc . new { raise UnexpectedException }
33
- RaiseErrorMatcher . new ( ExpectedException , nil ) . matches? ( proc ) . should == false
40
+ exc = UnexpectedException . new
41
+ matcher = RaiseErrorMatcher . new ( ExpectedException , nil )
42
+
43
+ matcher . matching_exception? ( exc ) . should == false
44
+ lambda {
45
+ matcher . matches? ( Proc . new { raise exc } )
46
+ } . should raise_error ( UnexpectedException )
34
47
end
35
48
36
49
it "does not match when the proc raises the expected exception with an unexpected message" do
37
- proc = Proc . new { raise ExpectedException , "unexpected" }
38
- RaiseErrorMatcher . new ( ExpectedException , "expected" ) . matches? ( proc ) . should == false
50
+ exc = ExpectedException . new ( "unexpected" )
51
+ matcher = RaiseErrorMatcher . new ( ExpectedException , "expected" )
52
+
53
+ matcher . matching_exception? ( exc ) . should == false
54
+ lambda {
55
+ matcher . matches? ( Proc . new { raise exc } )
56
+ } . should raise_error ( ExpectedException )
39
57
end
40
58
41
59
it "does not match when the proc does not raise an exception" do
42
60
proc = Proc . new { }
43
- RaiseErrorMatcher . new ( ExpectedException , "expected" ) . matches? ( proc ) . should == false
61
+ matcher = RaiseErrorMatcher . new ( ExpectedException , "expected" )
62
+ matcher . matches? ( proc ) . should == false
44
63
end
45
64
46
65
it "provides a useful failure message" do
47
- proc = Proc . new { raise UnexpectedException , "unexpected" }
66
+ exc = UnexpectedException . new ( "unexpected" )
48
67
matcher = RaiseErrorMatcher . new ( ExpectedException , "expected" )
49
- matcher . matches? ( proc )
68
+
69
+ matcher . matching_exception? ( exc ) . should == false
70
+ lambda {
71
+ matcher . matches? ( Proc . new { raise exc } )
72
+ } . should raise_error ( UnexpectedException )
50
73
matcher . failure_message . should ==
51
74
[ "Expected ExpectedException (expected)" , "but got UnexpectedException (unexpected)" ]
52
75
end
0 commit comments