Skip to content

Commit

Permalink
Merge pull request #104 from xr1337/master
Browse files Browse the repository at this point in the history
Unload when a new post processor is added.
  • Loading branch information
jasperblues committed Nov 19, 2013
2 parents 59c8472 + 7b485cc commit 56fc367
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/Factory/TyphoonComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ - (void)attachPostProcessor:(id <TyphoonComponentFactoryPostProcessor>)postProce
{
LogTrace(@"Attaching post processor: %@", postProcessor);
[_postProcessors addObject:postProcessor];
if ([self isLoaded]) {
[self unload];
}
}

- (void)injectProperties:(id)instance
Expand Down
26 changes: 26 additions & 0 deletions Tests/Factory/Config/Patcher/TyphoonPatcherTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,30 @@ - (void)test_allows_patching_out_a_component_with_a_mock

}

- (void)test_allows_patching_out_a_loaded_component_with_a_mock
{
MiddleAgesAssembly* assembly = [MiddleAgesAssembly assembly];
TyphoonComponentFactory* factory = [TyphoonBlockComponentFactory factoryWithAssembly:assembly];
[factory componentForKey:@"knight"];
//at this point, patching a loaded factory will not pass.

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

return mockKnight;
}];

[factory attachPostProcessor:patcher];

Knight* knight = [factory componentForKey:@"knight"];
assertThatBool([knight favoriteDamsels].count > 0, is(equalToBool(YES)));
LogDebug(@"Damsels: %@", [knight favoriteDamsels]);

}
@end

0 comments on commit 56fc367

Please sign in to comment.