Sha256: a68f578fec0a231b59d28e3507ee1c45ee60c21c69845afe0d3fb3634006fac2

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

#import "EXPMatchers+haveCountOf.h"

EXPMatcherImplementationBegin(haveCountOf, (NSUInteger expected)) {
  BOOL actualIsStringy = [actual isKindOfClass:[NSString class]] || [actual isKindOfClass:[NSAttributedString class]];
  BOOL actualIsCompatible = actualIsStringy || [actual respondsToSelector:@selector(count)];

  prerequisite(^BOOL{
    return actualIsCompatible;
  });

  NSUInteger (^count)(id) = ^(id actual) {
    if(actualIsStringy) {
      return [actual length];
  } else {
      return [actual count];
    }
  };

  match(^BOOL{
    if(actualIsCompatible) {
      return count(actual) == expected;
    }
    return NO;
  });

  failureMessageForTo(^NSString *{
    if(!actualIsCompatible) return [NSString stringWithFormat:@"%@ is not an instance of NSString, NSAttributedString, NSArray, NSSet, NSOrderedSet, or NSDictionary", EXPDescribeObject(actual)];
    return [NSString stringWithFormat:@"expected %@ to have a count of %zi but got %zi", EXPDescribeObject(actual), expected, count(actual)];
  });

  failureMessageForNotTo(^NSString *{
    if(!actualIsCompatible) return [NSString stringWithFormat:@"%@ is not an instance of NSString, NSAttributedString, NSArray, NSSet, NSOrderedSet, or NSDictionary", EXPDescribeObject(actual)];
    return [NSString stringWithFormat:@"expected %@ not to have a count of %zi", EXPDescribeObject(actual), expected];
  });
}
EXPMatcherImplementationEnd

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
second_curtain-0.6.0 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
second_curtain-0.5.0 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
second_curtain-0.4.0 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
second_curtain-0.3.0 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
cocoapods-deintegrate-0.2.1 spec/fixtures/Project/StaticLibraries/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
cocoapods-deintegrate-0.2.0 spec/fixtures/Project/StaticLibraries/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
second_curtain-0.2.4 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m
second_curtain-0.2.3 Demo/Pods/Expecta/src/matchers/EXPMatchers+haveCountOf.m