Skip to content

Commit

Permalink
Introduced Mocktail (edge) for convenience.
Browse files Browse the repository at this point in the history
Very rare, single-malt version of Mocktail with mustaches.  Going to
have to wait on the pull request.
  • Loading branch information
bnickel committed Jul 28, 2013
1 parent 227f08f commit a5ecda2
Show file tree
Hide file tree
Showing 243 changed files with 20,548 additions and 1,193 deletions.
53 changes: 46 additions & 7 deletions AMYServer Tests/AMYServerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright (c) 2013 Brian Nickel. All rights reserved.
//

#import <KIFTestStepValidation.h>
#import <KIFTestCase.h>
#import "ExampleServer.h"


@interface AMYServerTests : KIFTestCase
@end

Expand All @@ -18,29 +18,68 @@ @implementation AMYServerTests
- (void)beforeAll
{
[exampleServer start];
[tester enterText:@"brian" intoViewWithAccessibilityLabel:@"Username"];
[tester enterText:@"$ecret" intoViewWithAccessibilityLabel:@"Password"];
}

- (void)afterAll
{
[tester clearTextFromViewWithAccessibilityLabel:@"Username"];
[tester clearTextFromViewWithAccessibilityLabel:@"Password"];
[exampleServer stop];
}

- (void)beforeEach
{
[tester tapViewWithAccessibilityLabel:@"Log In"];
}

- (void)afterEach
{
[tester clearTextFromViewWithAccessibilityLabel:@"Username"];
[tester clearTextFromViewWithAccessibilityLabel:@"Password"];
}

- (void)testSuccess
{
[tester enterText:@"brian" intoViewWithAccessibilityLabel:@"Username"];
[tester enterText:@"$ecret" intoViewWithAccessibilityLabel:@"Password"];
[tester tapViewWithAccessibilityLabel:@"Log In"];

[exampleServer waitForLoginWithUsername:@"brian" password:@"$ecret" andRespondWithSuccess:YES message:@"Welcome, Brian" token:@"12345"];

[tester waitForViewWithAccessibilityLabel:@"Welcome, Brian"];
[tester tapViewWithAccessibilityLabel:@"Close"];
}

- (void)testMissingMocktail
{
KIFExpectFailure([exampleServer waitForRequestMatchingMocktail:@"logon" andRespondWithValues:@{}]);
}

- (void)testBasicMocktail
{
[exampleServer waitForRequestMatchingMocktail:@"successful-login" andRespondWithValues:@{@"token": @"1234", @"message": @"Yo, Brian"}];

[tester waitForViewWithAccessibilityLabel:@"Yo, Brian"];
[tester tapViewWithAccessibilityLabel:@"Close"];
}

- (void)testMocktailWithBodyConditions
{
[exampleServer waitForRequestMatchingMocktail:@"successful-login" withHTTPBodyMatchingBlock:^KIFTestStepResult(NSData *body, NSError *__autoreleasing *error) {
id json = [NSJSONSerialization JSONObjectWithData:body options:0 error:NULL];
KIFTestWaitCondition([json[@"username"] isEqualToString:@"brian"], error, @"Could not find username");
return KIFTestStepResultSuccess;
} andRespondWithValues:@{@"token": @"1234", @"message": @"'Sup, Brian"}];

[tester waitForViewWithAccessibilityLabel:@"'Sup, Brian"];
[tester tapViewWithAccessibilityLabel:@"Close"];
}


- (void)testMocktailWithFailingBodyConditions
{
KIFExpectFailure([[exampleServer usingTimeout:0.5] waitForRequestMatchingMocktail:@"successful-login" withHTTPBodyMatchingBlock:^KIFTestStepResult(NSData *body, NSError *__autoreleasing *error) {
id json = [NSJSONSerialization JSONObjectWithData:body options:0 error:NULL];
KIFTestWaitCondition([json[@"username"] isEqualToString:@"joe"], error, @"Could not find username");
return KIFTestStepResultSuccess;
} andRespondWithValues:@{}]);
}


@end
10 changes: 10 additions & 0 deletions AMYServer Tests/successful-login.tail
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POST
login.json
200
application/json

{
"success": true,
"message": "{{{message}}}",
"token": "{{{token}}}"
}
4 changes: 4 additions & 0 deletions AMYServer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
EB9714401796706D0005E31E /* AMYRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = EB97143617965CC70005E31E /* AMYRequest.m */; };
EB9714411796706D0005E31E /* _AMYURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = EB971439179660B10005E31E /* _AMYURLProtocol.m */; };
EB971444179BAD210005E31E /* ExampleServer.m in Sources */ = {isa = PBXBuildFile; fileRef = EB971443179BAD210005E31E /* ExampleServer.m */; };
EBAE488417A46C680005EE19 /* successful-login.tail in Resources */ = {isa = PBXBuildFile; fileRef = EBAE488317A46C680005EE19 /* successful-login.tail */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -96,6 +97,7 @@
EB97143C17966E740005E31E /* AMYServerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMYServerTests.m; sourceTree = "<group>"; };
EB971442179BAD210005E31E /* ExampleServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExampleServer.h; sourceTree = "<group>"; };
EB971443179BAD210005E31E /* ExampleServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleServer.m; sourceTree = "<group>"; };
EBAE488317A46C680005EE19 /* successful-login.tail */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "successful-login.tail"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -224,6 +226,7 @@
EB971442179BAD210005E31E /* ExampleServer.h */,
EB971443179BAD210005E31E /* ExampleServer.m */,
EB97143C17966E740005E31E /* AMYServerTests.m */,
EBAE488317A46C680005EE19 /* successful-login.tail */,
);
path = "AMYServer Tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -344,6 +347,7 @@
buildActionMask = 2147483647;
files = (
EB97142B179657770005E31E /* InfoPlist.strings in Resources */,
EBAE488417A46C680005EE19 /* successful-login.tail in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions AMYServer/AMYServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@property (nonatomic, readonly) NSArray *pendingURLRequests;

- (AMYRequest *)waitForRequestMatchingBlock:(KIFTestStepResult (^)(NSURLRequest *request, NSError **error))block;
- (void)waitForRequestMatchingMocktail:(NSString *)mocktail withHTTPBodyMatchingBlock:(KIFTestStepResult (^)(NSData *body, NSError **error))block andRespondWithValues:(NSDictionary *)values;
- (void)waitForRequestMatchingMocktail:(NSString *)mocktail andRespondWithValues:(NSDictionary *)values;

- (void)start;
- (void)stop;
Expand Down
33 changes: 33 additions & 0 deletions AMYServer/AMYServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#import "AMYServer.h"
#import "_AMYURLProtocol.h"
#import "AMYRequest.h"
#import <MocktailResponse.h>
#import <NSBundle-KIFAdditions.h>
#import <NSError-KIFAdditions.h>

@implementation AMYServer

Expand Down Expand Up @@ -50,4 +53,34 @@ - (AMYRequest *)waitForRequestMatchingBlock:(KIFTestStepResult (^)(NSURLRequest
return request;
}

- (void)waitForRequestMatchingMocktail:(NSString *)mocktail andRespondWithValues:(NSDictionary *)values
{
[self waitForRequestMatchingMocktail:mocktail withHTTPBodyMatchingBlock:nil andRespondWithValues:values];
}

- (void)waitForRequestMatchingMocktail:(NSString *)mocktail withHTTPBodyMatchingBlock:(KIFTestStepResult (^)(NSData *, NSError *__autoreleasing *))block andRespondWithValues:(NSDictionary *)values
{
NSURL *mocktailURL = [[[[NSBundle KIFTestBundle] resourceURL] URLByAppendingPathComponent:mocktail] URLByAppendingPathExtension:MocktailFileExtension];
MocktailResponse *response = [MocktailResponse responseFromFileAtURL:mocktailURL];

if (!response) {
[self failWithError:[NSError KIFErrorWithCode:KIFTestStepResultFailure localizedDescriptionWithFormat:@"Failed to find valid mocktail named %@ at path %@", mocktail, mocktailURL.absoluteString] stopTest:YES];
}

AMYRequest *request = [self waitForRequestMatchingBlock:^KIFTestStepResult(NSURLRequest *request, NSError *__autoreleasing *error) {

KIFTestWaitCondition([response matchesURL:request.URL method:request.HTTPMethod patternLength:NULL], error, @"Could not find request matching mocktail.");

if (block) {
return block(request.HTTPBody, error);
}

return KIFTestStepResultSuccess;
}];

[request respondWithSatusCode:response.statusCode headerFields:response.headers];
[request sendData:[response bodyWithValues:values]];
[request close];
}

@end
6 changes: 4 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pod 'KIF-next', :path => '../KIF'
pod 'KIF-next', :git => 'https://github.com/bnickel/KIF.git', :commit => '53b84fbb2b'
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'

target 'AMYServer Tests' do
pod 'KIF-next', :path => '../KIF'
pod 'KIF-next', :git => 'https://github.com/bnickel/KIF.git', :commit => '53b84fbb2b'
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'
end
19 changes: 16 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
PODS:
- GRMustache (6.7.5):
- JRSwizzle (~> 1.0)
- JRSwizzle (1.0)
- KIF-next (2.0.0pre2)
- Mocktail (1.2):
- GRMustache (~> 6.7.5)

DEPENDENCIES:
- KIF-next (from `../KIF`)
- KIF-next (from `https://github.com/bnickel/KIF.git`, commit `53b84fbb2b`)
- Mocktail (from `https://github.com/bnickel/objc-mocktail.git`, commit `cd6568cdbf`)

EXTERNAL SOURCES:
KIF-next:
:path: ../KIF
:commit: 53b84fbb2b
:git: https://github.com/bnickel/KIF.git
Mocktail:
:commit: cd6568cdbf
:git: https://github.com/bnickel/objc-mocktail.git

SPEC CHECKSUMS:
KIF-next: d77f4d1a1f2f280266ab87d62b2020e9ba39c204
GRMustache: fd8c4885861658b6bb79fedfbca10beb02edc97b
JRSwizzle: 6242ff38485d870fc2636899048ee1ab883ae587
KIF-next: b4ee028e8caacb2d08bde731a2a4e3b1ffd92c21
Mocktail: d9354ae1571971e20ad216b82e49bc0d3bf48324

COCOAPODS: 0.22.2
1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustache.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheCompiler_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheConfiguration.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheContext.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheContext_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheError.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheFilter.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheFilter_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheLocalizer.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheParser_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheRendering.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheTag.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheTagDelegate.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheTag_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheTemplate.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheTemplate_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheToken_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustacheVersion.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/GRMustache_private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/GRMustache/NSFormatter+GRMustache.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/JRSwizzle/JRSwizzle.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/CGGeometry-KIFAdditions.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIF.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIFSystemTestActor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIFTestActor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIFTestCase.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Pods/BuildHeaders/KIF-next/KIFTestStepValidation.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIFTypist.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/KIFUITestActor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Pods/BuildHeaders/KIF-next/LoadableCategory.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a5ecda2

Please sign in to comment.