Skip to content

Commit 19ef254

Browse files
committed
Removed dependency on experimental Mocktail by bringing files inline. Updated docs.
1 parent 8439d5a commit 19ef254

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3630
-4903
lines changed

AMYServer Tests/ExampleServer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (void)waitForLoginWithUsername:(NSString *)username password:(NSString *)passw
4646

4747
id response = @{@"success": @(success), @"message": message ?: @"", @"token" : token ?: @""};
4848

49-
[request respondWithSatusCode:200 headerFields:nil];
49+
[request respondWithSatusCode:200 headerFields:@{@"X-Application-Token": response[@"token"]}];
5050
[request sendData:[NSJSONSerialization dataWithJSONObject:response options:0 error:NULL]];
5151
[request close];
5252
}

AMYServer Tests/successful-login.tail

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ POST
22
login.json
33
200
44
application/json
5+
X-Application-Token: {{{token}}}
56

67
{
78
"success": true,

AMYServer.podspec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Pod::Spec.new do |s|
2+
s.name = "AMYServer"
3+
s.version = "0.0.2"
4+
s.summary = "AMY Mocks Your Server within KIF-next"
5+
s.homepage = "https://github.com/bnickel/AMYServer"
6+
s.license = 'Apache 2.0'
7+
s.author = { "Brian Nickel" => "brian.nickel@gmail.com" }
8+
s.source = { :git => "https://github.com/bnickel/AMYServer.git", :tag => "0.0.2" }
9+
s.platform = :ios, '5.0'
10+
s.source_files = 'AMYServer'
11+
s.requires_arc = true
12+
13+
s.dependency 'KIF-next', '~> 2.0.0pre3'
14+
s.dependency 'GRMustache', '~> 6.7'
15+
end

AMYServer.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
5641C68D282B4F7C8E987DB7 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C65A889641443929FA2D0A6 /* libPods.a */; };
1111
D8941B57AA6B462F808362B6 /* libPods-AMYServer Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CFA695D96E74AD0B14ECB01 /* libPods-AMYServer Tests.a */; };
12+
EB283E3B17A6317000883DEC /* _AMYMocktailResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */; };
13+
EB283E3C17A6317000883DEC /* _AMYMocktailResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */; };
1214
EB9713EA17961CD20005E31E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB9713E917961CD20005E31E /* Foundation.framework */; };
1315
EB9713EF17961CD20005E31E /* AMYServer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = EB9713EE17961CD20005E31E /* AMYServer.h */; };
1416
EB9713F117961CD20005E31E /* AMYServer.m in Sources */ = {isa = PBXBuildFile; fileRef = EB9713F017961CD20005E31E /* AMYServer.m */; };
@@ -65,6 +67,8 @@
6567
2CFA695D96E74AD0B14ECB01 /* libPods-AMYServer Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AMYServer Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
6668
660DAD8CDF4041B6ADB992C7 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
6769
7C65A889641443929FA2D0A6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
70+
EB283E3917A6317000883DEC /* _AMYMocktailResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _AMYMocktailResponse.h; sourceTree = "<group>"; };
71+
EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _AMYMocktailResponse.m; sourceTree = "<group>"; };
6872
EB9713E617961CD20005E31E /* libAMYServer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAMYServer.a; sourceTree = BUILT_PRODUCTS_DIR; };
6973
EB9713E917961CD20005E31E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
7074
EB9713ED17961CD20005E31E /* AMYServer-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AMYServer-Prefix.pch"; sourceTree = "<group>"; };
@@ -179,6 +183,8 @@
179183
EB97143617965CC70005E31E /* AMYRequest.m */,
180184
EB971438179660B10005E31E /* _AMYURLProtocol.h */,
181185
EB971439179660B10005E31E /* _AMYURLProtocol.m */,
186+
EB283E3917A6317000883DEC /* _AMYMocktailResponse.h */,
187+
EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */,
182188
EB9713EC17961CD20005E31E /* Supporting Files */,
183189
);
184190
path = AMYServer;
@@ -434,6 +440,7 @@
434440
isa = PBXSourcesBuildPhase;
435441
buildActionMask = 2147483647;
436442
files = (
443+
EB283E3B17A6317000883DEC /* _AMYMocktailResponse.m in Sources */,
437444
EB9713F117961CD20005E31E /* AMYServer.m in Sources */,
438445
EB97143717965CC70005E31E /* AMYRequest.m in Sources */,
439446
EB97143A179660B10005E31E /* _AMYURLProtocol.m in Sources */,
@@ -454,6 +461,7 @@
454461
isa = PBXSourcesBuildPhase;
455462
buildActionMask = 2147483647;
456463
files = (
464+
EB283E3C17A6317000883DEC /* _AMYMocktailResponse.m in Sources */,
457465
EB97143D17966E740005E31E /* AMYServerTests.m in Sources */,
458466
EB97143F1796706D0005E31E /* AMYServer.m in Sources */,
459467
EB9714401796706D0005E31E /* AMYRequest.m in Sources */,

AMYServer/AMYServer.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#import "AMYServer.h"
1010
#import "_AMYURLProtocol.h"
11+
#import "_AMYMocktailResponse.h"
1112
#import "AMYRequest.h"
12-
#import <MocktailResponse.h>
1313
#import <NSBundle-KIFAdditions.h>
1414
#import <NSError-KIFAdditions.h>
1515

@@ -60,8 +60,8 @@ - (void)waitForRequestMatchingMocktail:(NSString *)mocktail andRespondWithValues
6060

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

6666
if (!response) {
6767
[self failWithError:[NSError KIFErrorWithCode:KIFTestStepResultFailure localizedDescriptionWithFormat:@"Failed to find valid mocktail named %@ at path %@", mocktail, mocktailURL.absoluteString] stopTest:YES];
@@ -78,7 +78,7 @@ - (void)waitForRequestMatchingMocktail:(NSString *)mocktail withHTTPBodyMatching
7878
return KIFTestStepResultSuccess;
7979
}];
8080

81-
[request respondWithSatusCode:response.statusCode headerFields:response.headers];
81+
[request respondWithSatusCode:response.statusCode headerFields:[response headersWithValues:values]];
8282
[request sendData:[response bodyWithValues:values]];
8383
[request close];
8484
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
#import <Foundation/Foundation.h>
1111

12-
FOUNDATION_EXPORT NSString * const MocktailFileExtension;
12+
FOUNDATION_EXPORT NSString * const _AMYMocktailFileExtension;
1313

14-
@interface MocktailResponse : NSObject
14+
@interface _AMYMocktailResponse : NSObject
1515

1616
+ (instancetype)responseFromFileAtURL:(NSURL *)url;
1717
- (BOOL)matchesURL:(NSURL *)URL method:(NSString *)method patternLength:(NSUInteger *)patternLength;
1818

1919
@property (nonatomic, readonly) NSDictionary *headers;
2020
@property (nonatomic, readonly) NSInteger statusCode;
2121
@property (nonatomic, readonly) NSData *body;
22+
2223
- (NSData *)bodyWithValues:(NSDictionary *)values;
24+
- (NSDictionary *)headersWithValues:(NSDictionary *)values;
2325

2426
@end
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
//
1010

1111
#import <Foundation/Foundation.h>
12-
#import "MocktailResponse.h"
12+
#import "_AMYMocktailResponse.h"
1313
#import <GRMustache.h>
1414

15-
NSString * const MocktailFileExtension = @"tail";
15+
NSString * const _AMYMocktailFileExtension = @"tail";
1616

17-
@interface MocktailResponse ()
17+
@interface _AMYMocktailResponse ()
1818
@property (nonatomic, strong) NSRegularExpression *methodRegex;
1919
@property (nonatomic, strong) NSRegularExpression *absoluteURLRegex;
2020
@property (nonatomic, strong) NSURL *fileURL;
@@ -23,7 +23,7 @@ @interface MocktailResponse ()
2323
@property (nonatomic, assign) NSUInteger bodyOffset;
2424
@end
2525

26-
@implementation MocktailResponse
26+
@implementation _AMYMocktailResponse
2727

2828
+ (instancetype)responseFromFileAtURL:(NSURL *)url;
2929
{
@@ -45,12 +45,27 @@ + (instancetype)responseFromFileAtURL:(NSURL *)url;
4545
NSLog(@"Invalid amount of lines: %u", (unsigned)[lines count]);
4646
return nil;
4747
}
48-
49-
MocktailResponse *response = [[self alloc] init];
48+
49+
_AMYMocktailResponse *response = [[self alloc] init];
5050
response.methodRegex = [NSRegularExpression regularExpressionWithPattern:lines[0] options:NSRegularExpressionCaseInsensitive error:nil];
5151
response.absoluteURLRegex = [NSRegularExpression regularExpressionWithPattern:lines[1] options:NSRegularExpressionCaseInsensitive error:nil];
5252
response.statusCode = [lines[2] integerValue];
53-
response.headers = @{@"Content-Type":lines[3]};
53+
NSMutableDictionary *headers = @{@"Content-Type":lines[3]}.mutableCopy;
54+
55+
// From line 5 to '\n\n', expect HTTP response headers.
56+
NSRegularExpression *headerPattern = [NSRegularExpression regularExpressionWithPattern:@"^([^:]+):\\s+(.*)" options:0 error:NULL];
57+
for (NSUInteger line = 4; line < lines.count; line ++) {
58+
NSString *headerLine = lines[line];
59+
NSTextCheckingResult *match = [headerPattern firstMatchInString:headerLine options:0 range:NSMakeRange(0, headerLine.length)];
60+
61+
if (match) {
62+
NSString *key = [headerLine substringWithRange:[match rangeAtIndex:1]];
63+
NSString *value = [headerLine substringWithRange:[match rangeAtIndex:2]];
64+
headers[key] = value;
65+
}
66+
}
67+
68+
response.headers = headers.copy;
5469
response.fileURL = url;
5570
response.bodyOffset = [headerMatter dataUsingEncoding:originalEncoding].length + 2;
5671
return response;
@@ -72,6 +87,16 @@ - (BOOL)matchesURL:(NSURL *)URL method:(NSString *)method patternLength:(NSUInte
7287
return NO;
7388
}
7489

90+
- (NSDictionary *)headersWithValues:(NSDictionary *)values
91+
{
92+
NSMutableDictionary *headers = [NSMutableDictionary dictionary];
93+
[self.headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
94+
NSString *transformedObj = [GRMustacheTemplate renderObject:values fromString:obj error:NULL];
95+
headers[key] = transformedObj ?: obj;
96+
}];
97+
return headers.copy;
98+
}
99+
75100
- (NSData *)bodyWithValues:(NSDictionary *)values;
76101
{
77102
NSData *body = [NSData dataWithContentsOfURL:self.fileURL];

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pod 'KIF-next', '2.0.0pre3'
2-
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'
2+
pod 'GRMustache', '~> 6.7'
33

44
target 'AMYServer Tests' do
55
pod 'KIF-next', '2.0.0pre3'
6-
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'
6+
pod 'GRMustache', '~> 6.7'
77
end

Podfile.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,14 @@ PODS:
33
- JRSwizzle (~> 1.0)
44
- JRSwizzle (1.0)
55
- KIF-next (2.0.0pre3)
6-
- Mocktail (1.2):
7-
- GRMustache (~> 6.7.5)
86

97
DEPENDENCIES:
8+
- GRMustache (~> 6.7)
109
- KIF-next (= 2.0.0pre3)
11-
- Mocktail (from `https://github.com/bnickel/objc-mocktail.git`, commit `cd6568cdbf`)
12-
13-
EXTERNAL SOURCES:
14-
Mocktail:
15-
:commit: cd6568cdbf
16-
:git: https://github.com/bnickel/objc-mocktail.git
1710

1811
SPEC CHECKSUMS:
1912
GRMustache: fd8c4885861658b6bb79fedfbca10beb02edc97b
2013
JRSwizzle: 6242ff38485d870fc2636899048ee1ab883ae587
2114
KIF-next: 9035617946ec98228379f4a8088443dc04c71d62
22-
Mocktail: d9354ae1571971e20ad216b82e49bc0d3bf48324
2315

2416
COCOAPODS: 0.22.2

Pods/BuildHeaders/Mocktail/Mocktail.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)