Skip to content
Browse files

Finally moved CDRSpecFailure into its own file; added be_nil matcher.

  • Loading branch information...
1 parent ca99d24 commit b4822c93d0fab5a305a57c3a33b89ead63327e72 Adam Milligan committed Apr 22, 2011
View
34 Cedar.xcodeproj/project.pbxproj
@@ -45,6 +45,14 @@
AE8C87BA13625239006C9305 /* Base.h in Headers */ = {isa = PBXBuildFile; fileRef = AE8C87B713625239006C9305 /* Base.h */; };
AE8C87BB13625239006C9305 /* Base.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87B813625239006C9305 /* Base.mm */; };
AE8C87BC13625239006C9305 /* Base.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87B813625239006C9305 /* Base.mm */; };
+ AE8C87E3136265C4006C9305 /* BeNil.h in Headers */ = {isa = PBXBuildFile; fileRef = AE8C87E1136265C4006C9305 /* BeNil.h */; };
+ AE8C87E4136265C4006C9305 /* BeNil.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87E2136265C4006C9305 /* BeNil.mm */; };
+ AE8C87E7136266D8006C9305 /* BeNilSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87E6136266D8006C9305 /* BeNilSpec.mm */; };
+ AE8C87E8136266D8006C9305 /* BeNilSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87E6136266D8006C9305 /* BeNilSpec.mm */; };
+ AE8C880D13626D2F006C9305 /* BeNil.mm in Sources */ = {isa = PBXBuildFile; fileRef = AE8C87E2136265C4006C9305 /* BeNil.mm */; };
+ AE8C880F13626FA5006C9305 /* CDRSpecFailure.h in Headers */ = {isa = PBXBuildFile; fileRef = AE8C880E13626FA5006C9305 /* CDRSpecFailure.h */; };
+ AE8C881413626FE7006C9305 /* CDRSpecFailure.m in Sources */ = {isa = PBXBuildFile; fileRef = AE8C881113626FE6006C9305 /* CDRSpecFailure.m */; };
+ AE8C881513626FE7006C9305 /* CDRSpecFailure.m in Sources */ = {isa = PBXBuildFile; fileRef = AE8C881113626FE6006C9305 /* CDRSpecFailure.m */; };
AE91CA6C11DE64A3002BA6B9 /* CDRSharedExampleGroupPool.h in Headers */ = {isa = PBXBuildFile; fileRef = AEFD17B311DD1E8200F4448A /* CDRSharedExampleGroupPool.h */; settings = {ATTRIBUTES = (Public, ); }; };
AE91CA6D11DE64B3002BA6B9 /* CDRSharedExampleGroupPool.h in Copy headers to framework */ = {isa = PBXBuildFile; fileRef = AEFD17B311DD1E8200F4448A /* CDRSharedExampleGroupPool.h */; };
AE9855AE1236E7080024094E /* CDRSharedExampleGroupPool.m in Sources */ = {isa = PBXBuildFile; fileRef = AEFD17B111DD1E7200F4448A /* CDRSharedExampleGroupPool.m */; };
@@ -238,6 +246,11 @@
AE8C87B213624BD4006C9305 /* BeTruthy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BeTruthy.mm; sourceTree = "<group>"; };
AE8C87B713625239006C9305 /* Base.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base.h; sourceTree = "<group>"; };
AE8C87B813625239006C9305 /* Base.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Base.mm; sourceTree = "<group>"; };
+ AE8C87E1136265C4006C9305 /* BeNil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BeNil.h; sourceTree = "<group>"; };
+ AE8C87E2136265C4006C9305 /* BeNil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BeNil.mm; sourceTree = "<group>"; };
+ AE8C87E6136266D8006C9305 /* BeNilSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BeNilSpec.mm; sourceTree = "<group>"; };
+ AE8C880E13626FA5006C9305 /* CDRSpecFailure.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDRSpecFailure.h; sourceTree = "<group>"; };
+ AE8C881113626FE6006C9305 /* CDRSpecFailure.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRSpecFailure.m; sourceTree = "<group>"; };
AEC9DEEA12C2CC7E0039512D /* CDRColorizedReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDRColorizedReporter.h; sourceTree = "<group>"; };
AEC9DEEB12C2CC7E0039512D /* CDRColorizedReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDRColorizedReporter.m; sourceTree = "<group>"; };
AEEE1FB611DC271300029872 /* Cedar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cedar.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -361,10 +374,11 @@
AE8C879F1362068A006C9305 /* Matchers */ = {
isa = PBXGroup;
children = (
- AE8C87A01362071E006C9305 /* EqualSpec.mm */,
- AE8C87A7136244D6006C9305 /* BeTruthySpec.mm */,
AE8C87AA13624523006C9305 /* ExpectFailureWithMessage.h */,
AE8C87AB13624524006C9305 /* ExpectFailureWithMessage.m */,
+ AE8C87A01362071E006C9305 /* EqualSpec.mm */,
+ AE8C87A7136244D6006C9305 /* BeTruthySpec.mm */,
+ AE8C87E6136266D8006C9305 /* BeNilSpec.mm */,
);
path = Matchers;
sourceTree = "<group>";
@@ -402,6 +416,7 @@
AEEE1FDC11DC27B800029872 /* iPhone */,
AEEE1FE311DC27B800029872 /* Matchers */,
AEEE1FC511DC27B800029872 /* CDRExample.m */,
+ AE8C881113626FE6006C9305 /* CDRSpecFailure.m */,
AEEE1FC611DC27B800029872 /* CDRExampleBase.m */,
AEEE1FC711DC27B800029872 /* CDRExampleGroup.m */,
AEEE1FC811DC27B800029872 /* CDRFunctions.m */,
@@ -419,6 +434,7 @@
children = (
AEEE1FD411DC27B800029872 /* iPhone */,
AEEE1FCC11DC27B800029872 /* CDRExample.h */,
+ AE8C880E13626FA5006C9305 /* CDRSpecFailure.h */,
AEEE1FCD11DC27B800029872 /* CDRExampleBase.h */,
AEEE1FCE11DC27B800029872 /* CDRExampleGroup.h */,
AEEE1FCF11DC27B800029872 /* CDRExampleParent.h */,
@@ -465,11 +481,13 @@
children = (
AEEE1FE411DC27B800029872 /* ActualValue.h */,
AE8C87531360CF02006C9305 /* AllMatchers.h */,
+ AE8C87B713625239006C9305 /* Base.h */,
+ AE8C87B813625239006C9305 /* Base.mm */,
AE8C874D135FD1DB006C9305 /* Equal.h */,
AE8C87B013624928006C9305 /* BeTruthy.h */,
AE8C87B213624BD4006C9305 /* BeTruthy.mm */,
- AE8C87B713625239006C9305 /* Base.h */,
- AE8C87B813625239006C9305 /* Base.mm */,
+ AE8C87E1136265C4006C9305 /* BeNil.h */,
+ AE8C87E2136265C4006C9305 /* BeNil.mm */,
);
path = Matchers;
sourceTree = "<group>";
@@ -532,6 +550,8 @@
AE8C87AC13624524006C9305 /* ExpectFailureWithMessage.h in Headers */,
AE8C87B113624928006C9305 /* BeTruthy.h in Headers */,
AE8C87B913625239006C9305 /* Base.h in Headers */,
+ AE8C87E3136265C4006C9305 /* BeNil.h in Headers */,
+ AE8C880F13626FA5006C9305 /* CDRSpecFailure.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -770,6 +790,8 @@
AEC9DEEE12C2CC7E0039512D /* CDRColorizedReporter.m in Sources */,
AE8C87B313624BD4006C9305 /* BeTruthy.mm in Sources */,
AE8C87BB13625239006C9305 /* Base.mm in Sources */,
+ AE8C87E4136265C4006C9305 /* BeNil.mm in Sources */,
+ AE8C881413626FE7006C9305 /* CDRSpecFailure.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -786,6 +808,7 @@
AE8C87A11362071E006C9305 /* EqualSpec.mm in Sources */,
AE8C87AE136245BB006C9305 /* ExpectFailureWithMessage.m in Sources */,
AE8C87B513624D73006C9305 /* BeTruthySpec.mm in Sources */,
+ AE8C87E7136266D8006C9305 /* BeNilSpec.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -810,6 +833,8 @@
AEC9DEF412C2CC8F0039512D /* CDRColorizedReporter.m in Sources */,
AE8C87B413624BD4006C9305 /* BeTruthy.mm in Sources */,
AE8C87BC13625239006C9305 /* Base.mm in Sources */,
+ AE8C880D13626D2F006C9305 /* BeNil.mm in Sources */,
+ AE8C881513626FE7006C9305 /* CDRSpecFailure.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -828,6 +853,7 @@
AE8C87A21362071E006C9305 /* EqualSpec.mm in Sources */,
AE8C87AF136245BD006C9305 /* ExpectFailureWithMessage.m in Sources */,
AE8C87B613624D75006C9305 /* BeTruthySpec.mm in Sources */,
+ AE8C87E8136266D8006C9305 /* BeNilSpec.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
1 Source/CDRExample.m
@@ -1,5 +1,6 @@
#import "CDRExample.h"
#import "CDRExampleReporter.h"
+#import "CDRSpecFailure.h"
const CDRSpecBlock PENDING = nil;
View
8 Source/CDRExampleBase.m
@@ -1,13 +1,5 @@
#import "CDRExampleBase.h"
-@implementation CDRSpecFailure
-
-+ (id)specFailureWithReason:(NSString *)reason {
- return [[self class] exceptionWithName:@"Spec failure" reason:reason userInfo:nil];
-}
-
-@end
-
@implementation CDRExampleBase
@synthesize text = text_, parent = parent_;
View
1 Source/CDRSharedExampleGroupPool.m
@@ -2,6 +2,7 @@
#import "SpecHelper.h"
#import "CDRSpec.h"
#import "CDRExampleGroup.h"
+#import "CDRSpecFailure.h"
extern CDRSpec *currentSpec;
View
1 Source/CDRSpec.m
@@ -1,6 +1,7 @@
#import "CDRSpec.h"
#import "CDRExample.h"
#import "CDRExampleGroup.h"
+#import "CDRSpecFailure.h"
#import "SpecHelper.h"
CDRSpec *currentSpec;
View
9 Source/CDRSpecFailure.m
@@ -0,0 +1,9 @@
+#import "CDRSpecFailure.h"
+
+@implementation CDRSpecFailure
+
++ (id)specFailureWithReason:(NSString *)reason {
+ return [[self class] exceptionWithName:@"Spec failure" reason:reason userInfo:nil];
+}
+
+@end
View
4 Source/Headers/CDRExampleBase.h
@@ -14,10 +14,6 @@ enum CDRExampleState {
};
typedef enum CDRExampleState CDRExampleState;
-@interface CDRSpecFailure : NSException
-+ (id)specFailureWithReason:(NSString *)reason;
-@end
-
@interface CDRExampleBase : NSObject {
NSString *text_;
id<CDRExampleParent> parent_;
View
5 Source/Headers/CDRSpecFailure.h
@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+@interface CDRSpecFailure : NSException
++ (id)specFailureWithReason:(NSString *)reason;
+@end
View
2 Source/Matchers/ActualValue.h
@@ -1,5 +1,5 @@
#import <Foundation/Foundation.h>
-#import "CDRExampleBase.h"
+#import "CDRSpecFailure.h"
#include <iostream>
#include <sstream>
View
1 Source/Matchers/AllMatchers.h
@@ -1,2 +1,3 @@
#import "BeTruthy.h"
+#import "BeNil.h"
#import "Equal.h"
View
38 Source/Matchers/BeNil.h
@@ -0,0 +1,38 @@
+#import <Foundation/Foundation.h>
+#import "Base.h"
+#import "CDRSpecFailure.h"
+
+namespace Cedar { namespace Matchers {
+ class BeNil : public Base {
+ private:
+ BeNil & operator=(const BeNil &);
+
+ public:
+ BeNil();
+ ~BeNil();
+ // Allow default copy ctor.
+
+ virtual NSString * failure_message_end() const;
+
+ template<typename U>
+ bool matches(const U &) const;
+
+ template<typename U>
+ bool matches(U * const &) const;
+ };
+
+ BeNil be_nil();
+
+#pragma mark Generic
+ template<typename U>
+ bool BeNil::matches(const U & actualValue) const {
+ [[CDRSpecFailure specFailureWithReason:@"Attempt to compare non-pointer type to nil"] raise];
+ }
+
+ template<typename U>
+ bool BeNil::matches(U * const &actualValue) const {
+ this->build_failure_message_start([NSString stringWithFormat:@"%x", actualValue]);
+ return !actualValue;
+ }
+
+}}
View
19 Source/Matchers/BeNil.mm
@@ -0,0 +1,19 @@
+#import "BeNil.h"
+
+namespace Cedar { namespace Matchers {
+
+ BeNil be_nil() {
+ return BeNil();
+ }
+
+ BeNil::BeNil() : Base() {
+ }
+
+ BeNil::~BeNil() {
+ }
+
+ /*virtual*/ NSString * BeNil::failure_message_end() const {
+ return @"be nil";
+ }
+
+}}
View
4 Source/Matchers/BeTruthy.h
@@ -1,10 +1,6 @@
#import <Foundation/Foundation.h>
-#import "CDRExampleBase.h"
#import "Base.h"
-#include <iostream>
-#include <sstream>
-
namespace Cedar { namespace Matchers {
class BeTruthy : public Base {
private:
View
4 Source/Matchers/Equal.h
@@ -1,10 +1,6 @@
#import <Foundation/Foundation.h>
-#import "CDRExampleBase.h"
#import "Base.h"
-#include <iostream>
-#include <sstream>
-
namespace Cedar { namespace Matchers {
template<typename T>
class Equal : public Base {
View
1 Spec/CDRExampleSpec.m
@@ -14,6 +14,7 @@
#import "CDRExample.h"
#import "CDRExampleGroup.h"
+#import "CDRSpecFailure.h"
SPEC_BEGIN(CDRExampleSpec)
View
119 Spec/Matchers/BeNilSpec.mm
@@ -0,0 +1,119 @@
+#if TARGET_OS_IPHONE
+#import <Cedar/SpecHelper.h>
+#import "OCMock.h"
+#else
+#import <Cedar/SpecHelper.h>
+#import <OCMock/OCMock.h>
+#endif
+
+extern "C" {
+#import "ExpectFailureWithMessage.h"
+}
+
+using namespace Cedar::Matchers;
+
+SPEC_BEGIN(BeNilSpec)
+
+describe(@"be_nil matcher", ^{
+ describe(@"when the value is a pointer to a built-in type", ^{
+ __block int * value;
+
+ describe(@"which is NULL", ^{
+ beforeEach(^{
+ value = NULL;
+ });
+
+ describe(@"positive match", ^{
+ it(@"should should pass", ^{
+ expect(value).to(be_nil());
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage(@"Expected <0> to not be nil", ^{
+ expect(value).to_not(be_nil());
+ });
+ });
+ });
+ });
+
+ describe(@"which is not NULL", ^{
+ __block int i = 7;
+
+ beforeEach(^{
+ value = &i;
+ });
+
+ describe(@"positive match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage([NSString stringWithFormat:@"Expected <%x> to be nil", value], ^{
+ expect(value).to(be_nil());
+ });
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should should pass", ^{
+ expect(value).to_not(be_nil());
+ });
+ });
+ });
+ });
+
+ describe(@"when the value is an id", ^{
+ __block id value;
+
+ describe(@"which is nil", ^{
+ beforeEach(^{
+ value = nil;
+ });
+
+ describe(@"positive match", ^{
+ it(@"should should pass", ^{
+ expect(value).to(be_nil());
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage(@"Expected <0> to not be nil", ^{
+ expect(value).to_not(be_nil());
+ });
+ });
+ });
+ });
+
+ describe(@"which is not nil", ^{
+ beforeEach(^{
+ value = [NSString string];
+ });
+
+ describe(@"positive match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage([NSString stringWithFormat:@"Expected <%x> to be nil", value], ^{
+ expect(value).to(be_nil());
+ });
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should should pass", ^{
+ expect(value).to_not(be_nil());
+ });
+ });
+ });
+ });
+
+ describe(@"when the value is not a pointer", ^{
+ int value = 7;
+
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage([NSString stringWithFormat:@"Attempt to compare non-pointer type to nil"], ^{
+ expect(value).to(be_nil());
+ });
+ });
+ });
+});
+
+SPEC_END
View
1 Spec/Matchers/ExpectFailureWithMessage.m
@@ -1,5 +1,6 @@
#import "ExpectFailureWithMessage.h"
#import "CDRSpec.h"
+#import "CDRSpecFailure.h"
void expectFailureWithMessage(NSString *message, CDRSpecBlock block) {
@try {
View
2 Spec/SpecSpec.m
@@ -12,6 +12,8 @@
#import <OCHamcrest/OCHamcrest.h>
#endif
+#import "CDRSpecFailure.h"
+
void expectFailure(CDRSpecBlock block) {
@try {
block();

0 comments on commit b4822c9

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