KWSharedExample.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Licensed under the terms in License.txt
  3. //
  4. // Copyright 2014 Allen Ding. All rights reserved.
  5. //
  6. #import "KWSharedExample.h"
  7. #import "KWSharedExampleRegistry.h"
  8. #import "KWExample.h"
  9. @implementation KWSharedExample
  10. #pragma mark - Initializing
  11. - (id)initWithName:(NSString *)name block:(KWSharedExampleBlock)block {
  12. NSParameterAssert(name);
  13. NSParameterAssert(block);
  14. self = [super init];
  15. if (self) {
  16. _name = name;
  17. _block = block;
  18. }
  19. return self;
  20. }
  21. @end
  22. #pragma mark - Building Example Groups
  23. void sharedExamplesFor(NSString *name, KWSharedExampleBlock block) {
  24. KWSharedExample *sharedExample = [[KWSharedExample alloc] initWithName:name block:block];
  25. [[KWSharedExampleRegistry sharedRegistry] registerSharedExample:sharedExample];
  26. }
  27. void itBehavesLike(NSString *name, NSDictionary *data) {
  28. KWSharedExample *sharedExample = [[KWSharedExampleRegistry sharedRegistry] sharedExampleForName:name];
  29. NSString *description = [NSString stringWithFormat:@"behaves like %@", sharedExample.name];
  30. context(description, ^{ sharedExample.block(data); });
  31. }