Skip to content
This repository
Browse code

wip

  • Loading branch information...
commit d495ca4efb0f9e2e731f40b1902363352931152f 1 parent c223607
authored July 15, 2012
30  Cedar.xcodeproj/project.pbxproj
@@ -91,6 +91,8 @@
91 91
 		AE0D691213E8C6990048039A /* CDRSpecFailure.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AE8C880E13626FA5006C9305 /* CDRSpecFailure.h */; };
92 92
 		AE135D4011DEA6F400A922D4 /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D3111DEA6A900A922D4 /* OCMock.framework */; };
93 93
 		AE135E7011DEB46F00A922D4 /* libOCMock-StaticLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AE135D3511DEA6A900A922D4 /* libOCMock-StaticLib.a */; };
  94
+		AE167EF215B216DA005960B9 /* RaiseException.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE167EF115B216DA005960B9 /* RaiseException.mm */; };
  95
+		AE167EF315B216DA005960B9 /* RaiseException.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE167EF115B216DA005960B9 /* RaiseException.mm */; };
94 96
 		AE18A7B813F450A700C8872C /* Base.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEF72FFB13ECC21E00786282 /* Base.h */; };
95 97
 		AE18A7B913F450A700C8872C /* BeCloseTo.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEF72FFC13ECC21E00786282 /* BeCloseTo.h */; };
96 98
 		AE18A7BA13F450A700C8872C /* BeInstanceOf.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEF72FFD13ECC21E00786282 /* BeInstanceOf.h */; };
@@ -133,7 +135,7 @@
133 135
 		AE9855AE1236E7080024094E /* CDRSharedExampleGroupPool.m in Sources */ = {isa = PBXBuildFile; fileRef = AEFD17B111DD1E7200F4448A /* CDRSharedExampleGroupPool.m */; };
134 136
 		AE9AA67515AB601500617E1A /* CedarDoubles.h in Headers */ = {isa = PBXBuildFile; fileRef = 6628FC8714C4DBA70016652A /* CedarDoubles.h */; };
135 137
 		AE9AA67615AB601500617E1A /* CDRSpy.h in Headers */ = {isa = PBXBuildFile; fileRef = 6628FC9814C4DD440016652A /* CDRSpy.h */; };
136  
-		AE9AA67715AB601500617E1A /* Argument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6639A78814C544EB00B564B7 /* Argument.h */; };
  138
+		AE9AA67715AB601500617E1A /* Argument.h in Headers */ = {isa = PBXBuildFile; fileRef = 6639A78814C544EB00B564B7 /* Argument.h */; settings = {ATTRIBUTES = (Public, ); }; };
137 139
 		AE9AA67815AB601500617E1A /* HaveReceived.h in Headers */ = {isa = PBXBuildFile; fileRef = 6639A78014C50D3000B564B7 /* HaveReceived.h */; };
138 140
 		AE9AA67B15AB72DA00617E1A /* CDRClassFake.h in Headers */ = {isa = PBXBuildFile; fileRef = AE9AA67915AB72DA00617E1A /* CDRClassFake.h */; };
139 141
 		AE9AA68015AB748E00617E1A /* CDRClassFakeSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE9AA67F15AB748E00617E1A /* CDRClassFakeSpec.mm */; };
@@ -156,8 +158,6 @@
156 158
 		AE9AA6DC15AE0B0400617E1A /* CedarDoubleImpl.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AE9AA6DA15AE0B0300617E1A /* CedarDoubleImpl.h */; };
157 159
 		AE9AA6DE15AE0BE200617E1A /* CedarDoubleImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE9AA6DD15AE0BE200617E1A /* CedarDoubleImpl.mm */; };
158 160
 		AE9AA6DF15AE0BE200617E1A /* CedarDoubleImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE9AA6DD15AE0BE200617E1A /* CedarDoubleImpl.mm */; };
159  
-		AE9AA70915AF465000617E1A /* Argument.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE9AA70815AF465000617E1A /* Argument.mm */; };
160  
-		AE9AA70A15AF465000617E1A /* Argument.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE9AA70815AF465000617E1A /* Argument.mm */; };
161 161
 		AEB45A911496C8D800845D09 /* RaiseException.h in Headers */ = {isa = PBXBuildFile; fileRef = AEB45A901496C8D800845D09 /* RaiseException.h */; settings = {ATTRIBUTES = (Public, ); }; };
162 162
 		AEB45A921496C8D800845D09 /* RaiseException.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEB45A901496C8D800845D09 /* RaiseException.h */; };
163 163
 		AEBB92611496C1F000EEBD59 /* RaiseExceptionSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AEBB92601496C1F000EEBD59 /* RaiseExceptionSpec.mm */; };
@@ -479,6 +479,7 @@
479 479
 		AE0AF58413E9E87E00029396 /* ActualValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActualValue.h; sourceTree = "<group>"; };
480 480
 		AE135D2611DEA6A900A922D4 /* OCMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OCMock.xcodeproj; path = OCMock/Source/OCMock.xcodeproj; sourceTree = "<group>"; };
481 481
 		AE135E8311DEB4E400A922D4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Foundation.framework; sourceTree = SDKROOT; };
  482
+		AE167EF115B216DA005960B9 /* RaiseException.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RaiseException.mm; sourceTree = "<group>"; };
482 483
 		AE18A7D213F45BE500C8872C /* ComparatorsBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComparatorsBase.h; sourceTree = "<group>"; };
483 484
 		AE18A7D513F45BFC00C8872C /* ComparatorsContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComparatorsContainer.h; sourceTree = "<group>"; };
484 485
 		AE18A7FA13F4601400C8872C /* Contain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Contain.h; sourceTree = "<group>"; };
@@ -500,7 +501,6 @@
500 501
 		AE9AA6D715AE092C00617E1A /* StubbedMethodPrototype.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StubbedMethodPrototype.mm; sourceTree = "<group>"; };
501 502
 		AE9AA6DA15AE0B0300617E1A /* CedarDoubleImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CedarDoubleImpl.h; sourceTree = "<group>"; };
502 503
 		AE9AA6DD15AE0BE200617E1A /* CedarDoubleImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CedarDoubleImpl.mm; sourceTree = "<group>"; };
503  
-		AE9AA70815AF465000617E1A /* Argument.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Argument.mm; sourceTree = "<group>"; };
504 504
 		AEB45A901496C8D800845D09 /* RaiseException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RaiseException.h; sourceTree = "<group>"; };
505 505
 		AEBB92601496C1F000EEBD59 /* RaiseExceptionSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RaiseExceptionSpec.mm; sourceTree = "<group>"; };
506 506
 		AEC9DEEA12C2CC7E0039512D /* CDRColorizedReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDRColorizedReporter.h; sourceTree = "<group>"; };
@@ -664,7 +664,6 @@
664 664
 				AE9AA68315AB78FB00617E1A /* CDRClassFake.mm */,
665 665
 				AE9AA6D715AE092C00617E1A /* StubbedMethodPrototype.mm */,
666 666
 				AE9AA6DD15AE0BE200617E1A /* CedarDoubleImpl.mm */,
667  
-				AE9AA70815AF465000617E1A /* Argument.mm */,
668 667
 			);
669 668
 			path = Doubles;
670 669
 			sourceTree = "<group>";
@@ -829,6 +828,22 @@
829 828
 			name = Products;
830 829
 			sourceTree = "<group>";
831 830
 		};
  831
+		AE167EEC15B210C9005960B9 /* Matchers */ = {
  832
+			isa = PBXGroup;
  833
+			children = (
  834
+				AE167EF015B216A5005960B9 /* Base */,
  835
+			);
  836
+			path = Matchers;
  837
+			sourceTree = "<group>";
  838
+		};
  839
+		AE167EF015B216A5005960B9 /* Base */ = {
  840
+			isa = PBXGroup;
  841
+			children = (
  842
+				AE167EF115B216DA005960B9 /* RaiseException.mm */,
  843
+			);
  844
+			path = Base;
  845
+			sourceTree = "<group>";
  846
+		};
832 847
 		AE18A7D113F45BBE00C8872C /* Comparators */ = {
833 848
 			isa = PBXGroup;
834 849
 			children = (
@@ -888,6 +903,7 @@
888 903
 			children = (
889 904
 				AEEE1FCA11DC27B800029872 /* Headers */,
890 905
 				AEEE1FDC11DC27B800029872 /* iPhone */,
  906
+				AE167EEC15B210C9005960B9 /* Matchers */,
891 907
 				6628FC8414C4DAB90016652A /* Doubles */,
892 908
 				AEEE1FC511DC27B800029872 /* CDRExample.m */,
893 909
 				AE8C881113626FE6006C9305 /* CDRSpecFailure.m */,
@@ -1529,7 +1545,7 @@
1529 1545
 				AE9AA68715AB7E0900617E1A /* CDRClassFake.mm in Sources */,
1530 1546
 				AE9AA6D815AE092C00617E1A /* StubbedMethodPrototype.mm in Sources */,
1531 1547
 				AE9AA6DE15AE0BE200617E1A /* CedarDoubleImpl.mm in Sources */,
1532  
-				AE9AA70915AF465000617E1A /* Argument.mm in Sources */,
  1548
+				AE167EF215B216DA005960B9 /* RaiseException.mm in Sources */,
1533 1549
 			);
1534 1550
 			runOnlyForDeploymentPostprocessing = 0;
1535 1551
 		};
@@ -1598,7 +1614,7 @@
1598 1614
 				AE9AA68615AB7A8700617E1A /* CDRClassFake.mm in Sources */,
1599 1615
 				AE9AA6D915AE092C00617E1A /* StubbedMethodPrototype.mm in Sources */,
1600 1616
 				AE9AA6DF15AE0BE200617E1A /* CedarDoubleImpl.mm in Sources */,
1601  
-				AE9AA70A15AF465000617E1A /* Argument.mm in Sources */,
  1617
+				AE167EF315B216DA005960B9 /* RaiseException.mm in Sources */,
1602 1618
 			);
1603 1619
 			runOnlyForDeploymentPostprocessing = 0;
1604 1620
 		};
8  Source/Doubles/Argument.mm
... ...
@@ -1,8 +0,0 @@
1  
-#import "Argument.h"
2  
-#import <memory>
3  
-
4  
-namespace Cedar { namespace Doubles { namespace Arguments {
5  
-
6  
-    Argument::shared_ptr_t anything = Argument::shared_ptr_t(new Doubles::AnyArgument());
7  
-
8  
-}}}
2  Source/Doubles/CedarDoubleImpl.mm
@@ -47,7 +47,7 @@ - (void)dealloc {
47 47
     Cedar::Doubles::StubbedMethod::selector_map_t::iterator it = stubbed_methods_.find(selector);
48 48
     if (it != stubbed_methods_.end()) {
49 49
         [[NSException exceptionWithName:NSInternalInconsistencyException
50  
-                                 reason:[NSString stringWithFormat:@"The method '%s' is already stubbed", selector]
  50
+                                 reason:[NSString stringWithFormat:@"The method <%s> is already stubbed", selector]
51 51
                                userInfo:nil] raise];
52 52
     }
53 53
 
2  Source/Headers/Doubles/Argument.h
@@ -96,7 +96,7 @@ namespace Cedar { namespace Doubles {
96 96
     }
97 97
 
98 98
     namespace Arguments {
99  
-        extern Argument::shared_ptr_t anything;
  99
+        static const Argument::shared_ptr_t anything = Argument::shared_ptr_t(new Doubles::AnyArgument());
100 100
     }
101 101
 
102 102
 }}
101  Source/Headers/Matchers/Base/RaiseException.h
... ...
@@ -1,9 +1,11 @@
1 1
 #import "Base.h"
  2
+#import <tr1/memory>
2 3
 
3 4
 namespace Cedar { namespace Matchers {
4  
-    class RaiseException : public Base<> {
5  
-        typedef void (^empty_block_t)();
6 5
 
  6
+    typedef void (^empty_block_t)();
  7
+
  8
+    class RaiseException : public Base<> {
7 9
     private:
8 10
         RaiseException & operator=(const RaiseException &);
9 11
 
@@ -17,7 +19,6 @@ namespace Cedar { namespace Matchers {
17 19
         RaiseException operator()(NSObject *) const;
18 20
 
19 21
         RaiseException & or_subclass();
20  
-        RaiseException or_subclass() const;
21 22
 
22 23
         RaiseException & with_reason(NSString * const reason);
23 24
         RaiseException with_reason(NSString * const reason) const;
@@ -40,98 +41,8 @@ namespace Cedar { namespace Matchers {
40 41
     };
41 42
 
42 43
     RaiseException raise() __attribute__((deprecated)); // Please use raise_exception
43  
-    inline RaiseException raise() {
44  
-        return RaiseException();
45  
-    }
46  
-
47  
-    static const RaiseException raise_exception = RaiseException();
48  
-
49  
-    inline RaiseException::RaiseException(NSObject *expectedExceptionInstance /*= nil*/,
50  
-                                          Class expectedExceptionClass /*= nil*/,
51  
-                                          bool allowSubclasses /*= false */,
52  
-                                          NSString *reason /*= nil*/) :
53  
-    Base<>(),
54  
-    expectedExceptionInstance_([expectedExceptionInstance retain]),
55  
-    expectedExceptionClass_(expectedExceptionClass),
56  
-    allowSubclasses_(allowSubclasses),
57  
-    expectedReason_([reason retain]) {
58  
-    }
59  
-
60  
-    inline RaiseException::~RaiseException() {
61  
-        [expectedExceptionInstance_ release];
62  
-        [expectedReason_ release];
63  
-    }
64  
-
65  
-    inline RaiseException RaiseException::operator()() const {
66  
-        return RaiseException();
67  
-    }
68  
-
69  
-    inline RaiseException RaiseException::operator()(Class expectedExceptionClass) const {
70  
-        return RaiseException(nil, expectedExceptionClass);
71  
-    }
72  
-
73  
-    inline RaiseException RaiseException::operator()(NSObject *expectedExceptionInstance) const {
74  
-        return RaiseException(expectedExceptionInstance);
75  
-    }
76  
-
77  
-    inline RaiseException & RaiseException::or_subclass() {
78  
-        allowSubclasses_ = true;
79  
-        return *this;
80  
-    }
81  
-
82  
-    inline RaiseException RaiseException::or_subclass() const {
83  
-        return RaiseException(nil, expectedExceptionClass_, true);
84  
-    }
85  
-
86  
-    inline RaiseException & RaiseException::with_reason(NSString * const reason) {
87  
-        expectedReason_ = reason;
88  
-        return *this;
89  
-    }
90  
-
91  
-    inline RaiseException RaiseException::with_reason(NSString * const reason) const {
92  
-        return RaiseException(nil, nil, false, reason);
93  
-    }
94  
-
95  
-#pragma mark - Exception matcher
96  
-    inline bool RaiseException::matches(empty_block_t block) const {
97  
-        @try {
98  
-            block();
99  
-        }
100  
-        @catch (NSObject *exception) {
101  
-            return this->exception_matches_expected_class(exception) &&
102  
-            this->exception_matches_expected_instance(exception) &&
103  
-            this->exception_matches_expected_reason(exception);
104  
-        }
105  
-        return false;
106  
-    }
107  
-
108  
-    /*virtual*/ inline NSString * RaiseException::failure_message_end() const {
109  
-        NSMutableString *message = [NSMutableString stringWithFormat:@"raise an exception"];
110  
-        if (expectedExceptionClass_) {
111  
-            [message appendString:@" of class"];
112  
-            if (allowSubclasses_) {
113  
-                [message appendString:@", or subclass of class,"];
114  
-            }
115  
-            [message appendFormat:@" <%@>", NSStringFromClass(expectedExceptionClass_)];
116  
-        }
117  
-        if (expectedReason_) {
118  
-            [message appendFormat:@" with reason <%@>", expectedReason_];
119  
-        }
120  
-        return message;
121  
-    }
122  
-
123  
-#pragma mark - Private interface
124  
-    inline bool RaiseException::exception_matches_expected_class(NSObject * const exception) const {
125  
-        bool foo = !expectedExceptionClass_ || (allowSubclasses_ ? [exception isKindOfClass:expectedExceptionClass_] : [exception isMemberOfClass:expectedExceptionClass_]);
126  
-        return foo;
127  
-    }
128  
-
129  
-    inline bool RaiseException::exception_matches_expected_instance(NSObject * const exception) const {
130  
-        return !expectedExceptionInstance_ || [expectedExceptionInstance_ isEqual:exception];
131  
-    }
  44
+    RaiseException raise();
132 45
 
133  
-    inline bool RaiseException::exception_matches_expected_reason(NSObject * const exception) const {
134  
-        return !expectedReason_ || ([exception isKindOfClass:[NSException class]] && [expectedReason_ isEqualToString:[id(exception) reason]]);
135  
-    }
  46
+    static const RaiseException raise_exception;
136 47
 
137 48
 }}
96  Source/Matchers/Base/RaiseException.mm
... ...
@@ -0,0 +1,96 @@
  1
+#import "RaiseException.h"
  2
+
  3
+namespace Cedar { namespace Matchers {
  4
+
  5
+#pragma mark - RaiseException
  6
+    RaiseException::RaiseException(NSObject *expectedExceptionInstance /*= nil*/,
  7
+                                          Class expectedExceptionClass /*= nil*/,
  8
+                                          bool allowSubclasses /*= false */,
  9
+                                          NSString *reason /*= nil*/) :
  10
+    Base<>(),
  11
+    expectedExceptionInstance_([expectedExceptionInstance retain]),
  12
+    expectedExceptionClass_(expectedExceptionClass),
  13
+    allowSubclasses_(allowSubclasses),
  14
+    expectedReason_([reason retain]) {
  15
+    }
  16
+
  17
+    RaiseException::~RaiseException() {
  18
+        [expectedExceptionInstance_ release];
  19
+        [expectedReason_ release];
  20
+    }
  21
+
  22
+    RaiseException RaiseException::operator()() const {
  23
+        return RaiseException();
  24
+    }
  25
+
  26
+    RaiseException RaiseException::operator()(Class expectedExceptionClass) const {
  27
+        return RaiseException(nil, expectedExceptionClass);
  28
+    }
  29
+
  30
+    RaiseException RaiseException::operator()(NSObject *expectedExceptionInstance) const {
  31
+        return RaiseException(expectedExceptionInstance);
  32
+    }
  33
+
  34
+
  35
+    RaiseException & RaiseException::or_subclass() {
  36
+        allowSubclasses_ = true;
  37
+        return *this;
  38
+    }
  39
+
  40
+    RaiseException & RaiseException::with_reason(NSString * const reason) {
  41
+        expectedReason_ = reason;
  42
+        return *this;
  43
+    }
  44
+
  45
+    RaiseException RaiseException::with_reason(NSString * const reason) const {
  46
+        return RaiseException(nil, nil, false, reason);
  47
+    }
  48
+
  49
+#pragma mark - Exception matcher
  50
+    bool RaiseException::matches(empty_block_t block) const {
  51
+        @try {
  52
+            block();
  53
+        }
  54
+        @catch (NSObject *exception) {
  55
+            return this->exception_matches_expected_class(exception) &&
  56
+            this->exception_matches_expected_instance(exception) &&
  57
+            this->exception_matches_expected_reason(exception);
  58
+        }
  59
+        return false;
  60
+    }
  61
+
  62
+    /*virtual*/ NSString * RaiseException::failure_message_end() const {
  63
+        NSMutableString *message = [NSMutableString stringWithFormat:@"raise an exception"];
  64
+        if (expectedExceptionClass_) {
  65
+            [message appendString:@" of class"];
  66
+            if (allowSubclasses_) {
  67
+                [message appendString:@", or subclass of class,"];
  68
+            }
  69
+            [message appendFormat:@" <%@>", NSStringFromClass(expectedExceptionClass_)];
  70
+        }
  71
+        if (expectedReason_) {
  72
+            [message appendFormat:@" with reason <%@>", expectedReason_];
  73
+        }
  74
+
  75
+        return message;
  76
+    }
  77
+
  78
+#pragma mark - Private interface
  79
+    bool RaiseException::exception_matches_expected_class(NSObject * const exception) const {
  80
+        return !expectedExceptionClass_ || (allowSubclasses_ ? [exception isKindOfClass:expectedExceptionClass_] : [exception isMemberOfClass:expectedExceptionClass_]);
  81
+    }
  82
+
  83
+    bool RaiseException::exception_matches_expected_instance(NSObject * const exception) const {
  84
+        return !expectedExceptionInstance_ || [expectedExceptionInstance_ isEqual:exception];
  85
+    }
  86
+
  87
+    bool RaiseException::exception_matches_expected_reason(NSObject * const exception) const {
  88
+        return !expectedReason_ || ([exception isKindOfClass:[NSException class]] && [expectedReason_ isEqualToString:[id(exception) reason]]);
  89
+    }
  90
+
  91
+    // Deprecated
  92
+    RaiseException raise() {
  93
+        return RaiseException();
  94
+    }
  95
+
  96
+}}
127  Spec/Doubles/CedarDoubleSharedExamples.mm
@@ -39,7 +39,7 @@
39 39
 
40 40
             context(@"and then stubbed again", ^{
41 41
                 it(@"should raise an exception", ^{
42  
-                    ^{ [myDouble stub_method]("value"); } should raise_exception;
  42
+                    ^{ [myDouble stub_method]("value"); } should raise_exception.with_reason(@"The method <value> is already stubbed");
43 43
                 });
44 44
             });
45 45
 
@@ -74,70 +74,64 @@
74 74
                     ^{ stubbed_method_ptr->and_return(@"foo"); } should raise_exception;
75 75
                 });
76 76
             });
  77
+        });
77 78
 
78  
-            context(@"with too many argument expectations", ^{
  79
+        context(@"when the stub is instructed to raise an exception", ^{
  80
+            context(@"with no parameter", ^{
79 81
                 beforeEach(^{
80  
-                    stubbed_method_ptr->with(@"foo");
  82
+                    [myDouble stub_method]("increment").and_raise_exception();
81 83
                 });
82 84
 
83  
-                it(@"should raise an exception", ^{
84  
-                    NSString *reason = [NSString stringWithFormat:@"Wrong number of expected parameters for <value>; expected: 1, actual: 0"];
85  
-                    ^{ [myDouble value]; } should raise_exception.with_reason(reason);
  85
+                it(@"should raise a generic exception", ^{
  86
+                    ^{ [myDouble increment]; } should raise_exception([NSException class]);
86 87
                 });
87 88
             });
88  
-        });
89 89
 
90  
-        context(@"with a method that takes a single parameter", ^{
91  
-            __block Cedar::Doubles::StubbedMethod *stubbed_method_ptr;
92  
-            size_t expectedValue = 1;
93  
-            size_t actualValue = 6;
  90
+            context(@"with a specified exception", ^{
  91
+                id someException = @"that's some pig (exception)";
94 92
 
95  
-            beforeEach(^{
96  
-                stubbed_method_ptr = &[myDouble stub_method]("incrementBy:");
97  
-            });
  93
+                beforeEach(^{
  94
+                    [myDouble stub_method]("increment").and_raise_exception(someException);
  95
+                });
98 96
 
99  
-            context(@"when invoked with a parameter of the expected value", ^{
100  
-                it(@"should not raise an exception", ^{
101  
-                    [myDouble incrementBy:expectedValue];
  97
+                it(@"should raise that exception instance", ^{
  98
+                    ^{ [myDouble increment]; } should raise_exception(someException);
102 99
                 });
103 100
             });
  101
+        });
104 102
 
105  
-            context(@"with a specific expected argument", ^{
106  
-                beforeEach(^{
107  
-                    stubbed_method_ptr->with(expectedValue);
108  
-                });
  103
+        describe(@"argument expectations", ^{
  104
+            context(@"with too few", ^{
  105
+                size_t expectedIncrementValue = 1;
  106
+                NSNumber * expectedBitMoreValue = [NSNumber numberWithInteger:10];
109 107
 
110  
-                context(@"when invoked with a parameter of the expected value", ^{
111  
-                    it(@"should not raise an exception", ^{
112  
-                        [myDouble incrementBy:expectedValue];
113  
-                    });
  108
+                beforeEach(^{
  109
+                    [myDouble stub_method]("incrementByABit:andABitMore:").with(expectedIncrementValue);
114 110
                 });
115 111
 
116  
-                context(@"when invoked with a parameter of the wrong value", ^{
117  
-                    it(@"should raise an exception", ^{
118  
-                        ^{ [myDouble incrementBy:actualValue]; } should raise_exception;
119  
-                    });
  112
+                it(@"should raise an exception", ^{
  113
+                    NSString *reason = [NSString stringWithFormat:@"Wrong number of expected parameters for <incrementByABit:andABitMore:>; expected: 1, actual: 2"];
  114
+                    ^{ [myDouble incrementByABit:expectedIncrementValue andABitMore:expectedBitMoreValue]; } should raise_exception.with_reason(reason);
120 115
                 });
121 116
             });
122 117
 
123  
-            context(@"with any value", ^{
  118
+            context(@"with too many", ^{
124 119
                 beforeEach(^{
125  
-                    stubbed_method_ptr->with(anything);
  120
+                    [myDouble stub_method]("value").with(@"foo");
126 121
                 });
127 122
 
128  
-                it(@"should not raise an exception", ^{
129  
-                    [myDouble incrementBy:actualValue];
  123
+                it(@"should raise an exception", ^{
  124
+                    NSString *reason = [NSString stringWithFormat:@"Wrong number of expected parameters for <value>; expected: 1, actual: 0"];
  125
+                    ^{ [myDouble value]; } should raise_exception.with_reason(reason);
130 126
                 });
131 127
             });
132  
-        });
133 128
 
134  
-        context(@"with a method that takes multiple parameters", ^{
135  
-            size_t expectedIncrementValue = 1;
136  
-            NSNumber * expectedBitMoreValue = [NSNumber numberWithInteger:10];
137  
-            NSNumber * actualBitMoreValue = [NSNumber numberWithInteger:60];
138  
-
139  
-            context(@"with the correct number of argument expectations", ^{
  129
+            context(@"with the correct number", ^{
140 130
                 context(@"of the correct types", ^{
  131
+                    size_t expectedIncrementValue = 1;
  132
+                    NSNumber *expectedBitMoreValue = [NSNumber numberWithInteger:10];
  133
+                    NSNumber *actualBitMoreValue = [NSNumber numberWithInteger:11];
  134
+
141 135
                     beforeEach(^{
142 136
                         [myDouble stub_method]("incrementByABit:andABitMore:").with(expectedIncrementValue).and_with(expectedBitMoreValue);
143 137
                     });
@@ -150,7 +144,7 @@
150 144
 
151 145
                     context(@"when invoked with a parameter of the wrong value", ^{
152 146
                         it(@"should raise an exception", ^{
153  
-                            ^{ [myDouble incrementByABit:expectedIncrementValue andABitMore:actualBitMoreValue]; } should raise_exception;
  147
+                            ^{ [myDouble incrementByABit:expectedIncrementValue andABitMore:actualBitMoreValue]; } should raise_exception.with_reason(@"wibble");
154 148
                         });
155 149
                     });
156 150
                 });
@@ -164,46 +158,55 @@
164 158
 
165 159
                     it(@"should raise an exception", ^{
166 160
                         NSString *reason = [NSString stringWithFormat:@"Attempt to compare expected argument <%@> with actual argument type %s; argument #1 for <incrementByABit:andABitMore:>", argumentWithInvalidEncoding, @encode(size_t)];
167  
-                        ^{ [myDouble incrementByABit:expectedIncrementValue andABitMore:actualBitMoreValue]; } should raise_exception.with_reason(reason);
  161
+                        ^{ [myDouble incrementByABit:7 andABitMore:[NSNumber numberWithInt:8]]; } should raise_exception.with_reason(reason);
168 162
                     });
169 163
                 });
170 164
             });
171 165
 
172  
-            context(@"with too few expected arguments", ^{
173  
-                beforeEach(^{
174  
-                    [myDouble stub_method]("incrementByABit:andABitMore:").with(expectedIncrementValue);
175  
-                });
  166
+            context(@"with a specific value", ^{
  167
+                size_t expectedValue = 1;
  168
+                size_t anotherValue = 7;
176 169
 
177  
-                it(@"should raise an exception", ^{
178  
-                    NSString *reason = [NSString stringWithFormat:@"Wrong number of expected parameters for <incrementByABit:andABitMore:>; expected: 1, actual: 2"];
179  
-                    ^{ [myDouble incrementByABit:expectedIncrementValue andABitMore:expectedBitMoreValue]; } should raise_exception.with_reason(reason);
  170
+                beforeEach(^{
  171
+                    [myDouble stub_method]("incrementBy:").with(expectedValue);
180 172
                 });
181  
-            });
182  
-        });
183 173
 
184  
-        context(@"when the stub is instructed to raise an exception", ^{
185  
-            context(@"with no parameter", ^{
186  
-                beforeEach(^{
187  
-                    [myDouble stub_method]("increment").and_raise_exception();
  174
+                context(@"when invoked with an argument of the expected value", ^{
  175
+                    it(@"should record the invocation", ^{
  176
+                        [myDouble incrementBy:expectedValue];
  177
+                        myDouble should have_received("incrementBy:").with(expectedValue);
  178
+                    });
188 179
                 });
189 180
 
190  
-                it(@"should raise a generic exception", ^{
191  
-                    ^{ [myDouble increment]; } should raise_exception([NSException class]);
  181
+                context(@"when invoked with a parameter of the wrong value", ^{
  182
+                    it(@"should raise an exception", ^{
  183
+                        ^{ [myDouble incrementBy:anotherValue]; } should raise_exception.with_reason(@"wibble");
  184
+                    });
192 185
                 });
193 186
             });
194 187
 
195  
-            context(@"with a specified exception", ^{
196  
-                id someException = @"that's some pig (exception)";
  188
+            context(@"with an arugment specified as anything", ^{
  189
+                NSNumber *expectedBitMoreValue = [NSNumber numberWithInt:777];
  190
+                NSNumber *anotherBitMoreValue = [NSNumber numberWithInt:111];
197 191
 
198 192
                 beforeEach(^{
199  
-                    [myDouble stub_method]("increment").and_raise_exception(someException);
  193
+                    [myDouble stub_method]("incrementByABit:andABitMore:").with(anything).and_with(expectedBitMoreValue);
200 194
                 });
201 195
 
202  
-                it(@"should raise that exception instance", ^{
203  
-                    ^{ [myDouble increment]; } should raise_exception(someException);
  196
+                it(@"should allow any value for the 'anything' argument", ^{
  197
+                    [myDouble incrementByABit:8 andABitMore:expectedBitMoreValue];
  198
+                    [myDouble incrementByABit:88 andABitMore:expectedBitMoreValue];
  199
+                });
  200
+
  201
+                it(@"should still require the non-'anything' argument to match", ^{
  202
+                    ^{ [myDouble incrementByABit:8 andABitMore:anotherBitMoreValue]; } should raise_exception.with_reason(@"wibble");
204 203
                 });
205 204
             });
206 205
         });
  206
+
  207
+        describe(@"return values", ^{
  208
+//            <#content#>
  209
+        });
207 210
     });
208 211
 });
209 212
 
12  Spec/Matchers/Base/RaiseExceptionSpec.mm
@@ -45,7 +45,7 @@ @implementation AnotherSubclassException; @end
45 45
 
46 46
                 describe(@"negative match", ^{
47 47
                     it(@"should fail with a sensible failure message", ^{
48  
-                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception", block], ^{
  48
+                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception\nActually caught: %@", block, exception], ^{
49 49
                             block should_not raise_exception;
50 50
                         });
51 51
                     });
@@ -61,7 +61,7 @@ @implementation AnotherSubclassException; @end
61 61
 
62 62
                 describe(@"negative match", ^{
63 63
                     it(@"should fail with a sensible failure message", ^{
64  
-                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception", block], ^{
  64
+                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception\nActually caught: %@", block, exception], ^{
65 65
                             block should_not raise_exception;
66 66
                         });
67 67
                     });
@@ -127,7 +127,7 @@ @implementation AnotherSubclassException; @end
127 127
 
128 128
             describe(@"negative match", ^{
129 129
                 it(@"should fail with a sensible failure message", ^{
130  
-                    expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception of class <%@>", block, NSStringFromClass(expectedExceptionClass)], ^{
  130
+                    expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception of class <%@>\nActually caught: %@", block, NSStringFromClass(expectedExceptionClass), exception], ^{
131 131
                         block should_not raise_exception(expectedExceptionClass);
132 132
                     });
133 133
                 });
@@ -151,7 +151,7 @@ @implementation AnotherSubclassException; @end
151 151
 
152 152
                 describe(@"negative match", ^{
153 153
                     it(@"should fail with a sensible failure message", ^{
154  
-                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception of class, or subclass of class, <%@>", block, NSStringFromClass([expectedExceptionClass class])], ^{
  154
+                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not raise an exception of class, or subclass of class, <%@>\nActually caught: %@", block, NSStringFromClass([expectedExceptionClass class]), exception], ^{
155 155
                             block should_not raise_exception(expectedExceptionClass).or_subclass();
156 156
                         });
157 157
                     });
@@ -161,7 +161,7 @@ @implementation AnotherSubclassException; @end
161 161
             context(@"when subclass exceptions are not expected", ^{
162 162
                 describe(@"positive match", ^{
163 163
                     it(@"should fail with a sensible failure message", ^{
164  
-                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to raise an exception of class <%@>", block, NSStringFromClass([expectedExceptionClass class])], ^{
  164
+                        expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to raise an exception of class <%@>\nActually caught: %@", block, NSStringFromClass([expectedExceptionClass class]), exception], ^{
165 165
                             block should raise_exception(expectedExceptionClass);
166 166
                         });
167 167
                     });
@@ -185,7 +185,7 @@ @implementation AnotherSubclassException; @end
185 185
 
186 186
             describe(@"positive match", ^{
187 187
                 it(@"should fail with a sensible failure message", ^{
188  
-                    expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to raise an exception of class <%@>", block, NSStringFromClass([expectedExceptionClass class])], ^{
  188
+                    expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to raise an exception of class <%@>\nActually caught: %@", block, NSStringFromClass([expectedExceptionClass class]), exception], ^{
189 189
                         block should raise_exception(expectedExceptionClass);
190 190
                     });
191 191
                 });

0 notes on commit d495ca4

Please sign in to comment.
Something went wrong with that request. Please try again.