Skip to content

Commit

Permalink
Patcher. .
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed Sep 2, 2013
1 parent 3bc3330 commit c234306
Show file tree
Hide file tree
Showing 4 changed files with 2,991 additions and 2,983 deletions.
6 changes: 4 additions & 2 deletions Source/Factory/Mutator/Patcher/TyphoonPatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#import <Foundation/Foundation.h>
#import "TyphoonComponentFactoryMutator.h"

typedef id (^objectCreationBlock)();
typedef id (^ObjectCreationBlock)();

@interface TyphoonPatcher : NSObject <TyphoonComponentFactoryMutator>
{
NSMutableDictionary* _patches;
}

- (void)patchDefinitionWithKey:(NSString*)key withObject:(objectCreationBlock)objectCreationBlock;
- (void)patchDefinitionWithKey:(NSString*)key withObject:(ObjectCreationBlock)objectCreationBlock;

- (void)patchDefinition:(TyphoonDefinition*)definition withObject:(ObjectCreationBlock)objectCreationBlock;

@end
7 changes: 6 additions & 1 deletion Source/Factory/Mutator/Patcher/TyphoonPatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ - (id)init
/* ====================================================================================================================================== */
#pragma mark - Interface Methods

- (void)patchDefinitionWithKey:(NSString*)key withObject:(objectCreationBlock)objectCreationBlock
- (void)patchDefinitionWithKey:(NSString*)key withObject:(ObjectCreationBlock)objectCreationBlock
{
id object = objectCreationBlock();
[_patches setObject:object forKey:key];
}

- (void)patchDefinition:(TyphoonDefinition*)definition withObject:(ObjectCreationBlock)objectCreationBlock
{
[self patchDefinitionWithKey:definition.key withObject:objectCreationBlock];
}

/* ====================================================================================================================================== */
#pragma mark - Protocol Methods

Expand Down
5 changes: 3 additions & 2 deletions Tests/Factory/Mutator/Patcher/TyphoonPatcherTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ @implementation TyphoonPatcherTests

- (void)test_allows_patching_out_a_component_with_a_mock
{
TyphoonComponentFactory* factory = [TyphoonBlockComponentFactory factoryWithAssembly:[MiddleAgesAssembly assembly]];
MiddleAgesAssembly* assembly = [MiddleAgesAssembly assembly];
TyphoonComponentFactory* factory = [TyphoonBlockComponentFactory factoryWithAssembly:assembly];

TyphoonPatcher* patcher = [[TyphoonPatcher alloc] init];
[patcher patchDefinitionWithKey:@"knight" withObject:^id
[patcher patchDefinition:[assembly knight] withObject:^id
{
Knight* mockKnight = mock([Knight class]);
[given([mockKnight favoriteDamsels]) willReturn:@[
Expand Down
Loading

0 comments on commit c234306

Please sign in to comment.