Permalink
Browse files

Add NSString support to be_empty matcher

  • Loading branch information...
1 parent 844fbf7 commit 2dde8e284d38dfef8551b8443393d2b00d085d35 Adam Milligan committed Sep 3, 2012
@@ -8,7 +8,11 @@ namespace Cedar { namespace Matchers { namespace Comparators {
#pragma mark compare_empty
template<typename T>
bool compare_empty(const T & container) {
- return 0 == [container count];
+ if ([container respondsToSelector:@selector(count)]) {
+ return 0 == [(id)container count];
+ } else {
+ return 0 == [(id)container length];
+ }
}
template<typename T>
@@ -362,6 +362,44 @@
});
});
});
+
+ describe(@"when the value is an NSString", ^{
+ describe(@"which is empty", ^{
+ NSString *container = [NSString string];
+
+ describe(@"positive match", ^{
+ it(@"should should pass", ^{
+ expect(container).to(be_empty());
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to not be empty", container], ^{
+ expect(container).to_not(be_empty());
+ });
+ });
+ });
+ });
+
+ describe(@"which is not empty", ^{
+ NSMutableSet *container = [NSString stringWithFormat:@"not empty"];
+
+ describe(@"positive match", ^{
+ it(@"should fail with a sensible failure message", ^{
+ expectFailureWithMessage([NSString stringWithFormat:@"Expected <%@> to be empty", container], ^{
+ expect(container).to(be_empty());
+ });
+ });
+ });
+
+ describe(@"negative match", ^{
+ it(@"should pass", ^{
+ expect(container).to_not(be_empty());
+ });
+ });
+ });
+ });
});
describe(@"be_empty shorthand syntax (no parentheses)", ^{

0 comments on commit 2dde8e2

Please sign in to comment.