Skip to content

Commit

Permalink
Use Typhoon 3.0 style in test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed Apr 21, 2015
1 parent a9086bc commit 7ffed57
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions Tests/Test/Patcher/TyphoonPatcherTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@interface TyphoonPatcherTests : XCTestCase
{
MiddleAgesAssembly *_assembly;
TyphoonComponentFactory *_factory;
TyphoonPatcher *_patcher;
}

Expand All @@ -35,8 +34,7 @@ - (void)setUp
{
[super setUp];

_assembly = [MiddleAgesAssembly assembly];
_factory = [TyphoonBlockComponentFactory factoryWithAssembly:_assembly];
_assembly = [[MiddleAgesAssembly assembly] activate];
}

- (void)test_allows_patching_out_a_component_with_a_mock
Expand All @@ -47,7 +45,7 @@ - (void)test_allows_patching_out_a_component_with_a_mock

- (void)test_allows_patching_out_a_loaded_component_with_a_mock
{
[_factory componentForKey:@"knight"];
[_assembly componentForKey:@"knight"];

[self applyAPatch];
[self assertPatchApplied];
Expand All @@ -59,23 +57,21 @@ - (void)test_honours_the_scope_of_patched_definition
[self applyAPatch];
[self assertPatchApplied];

XCTAssertFalse([_factory componentForKey:@"knight"] == [_factory componentForKey:@"knight"]);
XCTAssertTrue([_factory componentForKey:@"cavalryMan"] == [_factory componentForKey:@"cavalryMan"]);
XCTAssertFalse([_assembly componentForKey:@"knight"] == [_assembly componentForKey:@"knight"]);
XCTAssertTrue([_assembly componentForKey:@"cavalryMan"] == [_assembly componentForKey:@"cavalryMan"]);
}

- (void)test_patcher_with_runtime_args
{
MiddleAgesAssembly *factory = (MiddleAgesAssembly *)_factory;

[self applyAPatch];
[self assertPatchApplied];

Knight *knight = [factory knightWithFoobar:@"123"];
Knight *knight = [_assembly knightWithFoobar:@"123"];
XCTAssertEqual(knight.foobar, @"Fooooo");

[_patcher detach];

knight = [factory knightWithFoobar:@"123"];
knight = [_assembly knightWithFoobar:@"123"];
XCTAssertEqual(knight.foobar, @"123");

}
Expand All @@ -85,20 +81,19 @@ - (void)test_allows_detaching_patcher
[self applyAPatch];
[self assertPatchApplied];

XCTAssertFalse([_factory componentForKey:@"knight"] == [_factory componentForKey:@"knight"]);
XCTAssertTrue([_factory componentForKey:@"cavalryMan"] == [_factory componentForKey:@"cavalryMan"]);
XCTAssertFalse([_assembly componentForKey:@"knight"] == [_assembly componentForKey:@"knight"]);
XCTAssertTrue([_assembly componentForKey:@"cavalryMan"] == [_assembly componentForKey:@"cavalryMan"]);

[_patcher detach];

Knight *knight = [_factory componentForKey:@"knight"];
Knight *knight = [_assembly componentForKey:@"knight"];
LogDebug(@"%@", [knight favoriteDamsels]);
}

- (void)applyAPatch
{
MiddleAgesAssembly *assembly = [MiddleAgesAssembly assembly];
_patcher = [[TyphoonPatcher alloc] init];
[_patcher patchDefinition:[assembly knight] withObject:^id {
[_patcher patchDefinitionWithSelector:@selector(knight) withObject:^id {
Knight *mockKnight = mock([Knight class]);
[given([mockKnight favoriteDamsels]) willReturn:@[
@"Mary",
Expand Down Expand Up @@ -126,12 +121,12 @@ - (void)applyAPatch
return knight;
}];

[_factory attachPostProcessor:_patcher];
[_assembly attachPostProcessor:_patcher];
}

- (void)assertPatchApplied
{
Knight *knight = [_factory componentForKey:@"knight"];
Knight *knight = [_assembly componentForKey:@"knight"];
XCTAssertTrue([knight favoriteDamsels].count > 0);
}

Expand Down

0 comments on commit 7ffed57

Please sign in to comment.