Skip to content

Commit

Permalink
Removed dependency on experimental Mocktail by bringing files inline.…
Browse files Browse the repository at this point in the history
… Updated docs.
  • Loading branch information
bnickel committed Jul 29, 2013
1 parent 8439d5a commit 19ef254
Show file tree
Hide file tree
Showing 41 changed files with 3,630 additions and 4,903 deletions.
2 changes: 1 addition & 1 deletion AMYServer Tests/ExampleServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (void)waitForLoginWithUsername:(NSString *)username password:(NSString *)passw

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

[request respondWithSatusCode:200 headerFields:nil];
[request respondWithSatusCode:200 headerFields:@{@"X-Application-Token": response[@"token"]}];
[request sendData:[NSJSONSerialization dataWithJSONObject:response options:0 error:NULL]];
[request close];
}
Expand Down
1 change: 1 addition & 0 deletions AMYServer Tests/successful-login.tail
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ POST
login.json
200
application/json
X-Application-Token: {{{token}}}

{
"success": true,
Expand Down
15 changes: 15 additions & 0 deletions AMYServer.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Pod::Spec.new do |s|
s.name = "AMYServer"
s.version = "0.0.2"
s.summary = "AMY Mocks Your Server within KIF-next"
s.homepage = "https://github.com/bnickel/AMYServer"
s.license = 'Apache 2.0'
s.author = { "Brian Nickel" => "[email protected]" }
s.source = { :git => "https://github.com/bnickel/AMYServer.git", :tag => "0.0.2" }
s.platform = :ios, '5.0'
s.source_files = 'AMYServer'
s.requires_arc = true

s.dependency 'KIF-next', '~> 2.0.0pre3'
s.dependency 'GRMustache', '~> 6.7'
end
8 changes: 8 additions & 0 deletions AMYServer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
5641C68D282B4F7C8E987DB7 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C65A889641443929FA2D0A6 /* libPods.a */; };
D8941B57AA6B462F808362B6 /* libPods-AMYServer Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CFA695D96E74AD0B14ECB01 /* libPods-AMYServer Tests.a */; };
EB283E3B17A6317000883DEC /* _AMYMocktailResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */; };
EB283E3C17A6317000883DEC /* _AMYMocktailResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */; };
EB9713EA17961CD20005E31E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB9713E917961CD20005E31E /* Foundation.framework */; };
EB9713EF17961CD20005E31E /* AMYServer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = EB9713EE17961CD20005E31E /* AMYServer.h */; };
EB9713F117961CD20005E31E /* AMYServer.m in Sources */ = {isa = PBXBuildFile; fileRef = EB9713F017961CD20005E31E /* AMYServer.m */; };
Expand Down Expand Up @@ -65,6 +67,8 @@
2CFA695D96E74AD0B14ECB01 /* libPods-AMYServer Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AMYServer Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
660DAD8CDF4041B6ADB992C7 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
7C65A889641443929FA2D0A6 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
EB283E3917A6317000883DEC /* _AMYMocktailResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _AMYMocktailResponse.h; sourceTree = "<group>"; };
EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _AMYMocktailResponse.m; sourceTree = "<group>"; };
EB9713E617961CD20005E31E /* libAMYServer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAMYServer.a; sourceTree = BUILT_PRODUCTS_DIR; };
EB9713E917961CD20005E31E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
EB9713ED17961CD20005E31E /* AMYServer-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AMYServer-Prefix.pch"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -179,6 +183,8 @@
EB97143617965CC70005E31E /* AMYRequest.m */,
EB971438179660B10005E31E /* _AMYURLProtocol.h */,
EB971439179660B10005E31E /* _AMYURLProtocol.m */,
EB283E3917A6317000883DEC /* _AMYMocktailResponse.h */,
EB283E3A17A6317000883DEC /* _AMYMocktailResponse.m */,
EB9713EC17961CD20005E31E /* Supporting Files */,
);
path = AMYServer;
Expand Down Expand Up @@ -434,6 +440,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EB283E3B17A6317000883DEC /* _AMYMocktailResponse.m in Sources */,
EB9713F117961CD20005E31E /* AMYServer.m in Sources */,
EB97143717965CC70005E31E /* AMYRequest.m in Sources */,
EB97143A179660B10005E31E /* _AMYURLProtocol.m in Sources */,
Expand All @@ -454,6 +461,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EB283E3C17A6317000883DEC /* _AMYMocktailResponse.m in Sources */,
EB97143D17966E740005E31E /* AMYServerTests.m in Sources */,
EB97143F1796706D0005E31E /* AMYServer.m in Sources */,
EB9714401796706D0005E31E /* AMYRequest.m in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions AMYServer/AMYServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#import "AMYServer.h"
#import "_AMYURLProtocol.h"
#import "_AMYMocktailResponse.h"
#import "AMYRequest.h"
#import <MocktailResponse.h>
#import <NSBundle-KIFAdditions.h>
#import <NSError-KIFAdditions.h>

Expand Down Expand Up @@ -60,8 +60,8 @@ - (void)waitForRequestMatchingMocktail:(NSString *)mocktail andRespondWithValues

- (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];
NSURL *mocktailURL = [[[[NSBundle KIFTestBundle] resourceURL] URLByAppendingPathComponent:mocktail] URLByAppendingPathExtension:_AMYMocktailFileExtension];
_AMYMocktailResponse *response = [_AMYMocktailResponse responseFromFileAtURL:mocktailURL];

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

[request respondWithSatusCode:response.statusCode headerFields:response.headers];
[request respondWithSatusCode:response.statusCode headerFields:[response headersWithValues:values]];
[request sendData:[response bodyWithValues:values]];
[request close];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT NSString * const MocktailFileExtension;
FOUNDATION_EXPORT NSString * const _AMYMocktailFileExtension;

@interface MocktailResponse : NSObject
@interface _AMYMocktailResponse : NSObject

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

@property (nonatomic, readonly) NSDictionary *headers;
@property (nonatomic, readonly) NSInteger statusCode;
@property (nonatomic, readonly) NSData *body;

- (NSData *)bodyWithValues:(NSDictionary *)values;
- (NSDictionary *)headersWithValues:(NSDictionary *)values;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
//

#import <Foundation/Foundation.h>
#import "MocktailResponse.h"
#import "_AMYMocktailResponse.h"
#import <GRMustache.h>

NSString * const MocktailFileExtension = @"tail";
NSString * const _AMYMocktailFileExtension = @"tail";

@interface MocktailResponse ()
@interface _AMYMocktailResponse ()
@property (nonatomic, strong) NSRegularExpression *methodRegex;
@property (nonatomic, strong) NSRegularExpression *absoluteURLRegex;
@property (nonatomic, strong) NSURL *fileURL;
Expand All @@ -23,7 +23,7 @@ @interface MocktailResponse ()
@property (nonatomic, assign) NSUInteger bodyOffset;
@end

@implementation MocktailResponse
@implementation _AMYMocktailResponse

+ (instancetype)responseFromFileAtURL:(NSURL *)url;
{
Expand All @@ -45,12 +45,27 @@ + (instancetype)responseFromFileAtURL:(NSURL *)url;
NSLog(@"Invalid amount of lines: %u", (unsigned)[lines count]);
return nil;
}

MocktailResponse *response = [[self alloc] init];
_AMYMocktailResponse *response = [[self alloc] init];
response.methodRegex = [NSRegularExpression regularExpressionWithPattern:lines[0] options:NSRegularExpressionCaseInsensitive error:nil];
response.absoluteURLRegex = [NSRegularExpression regularExpressionWithPattern:lines[1] options:NSRegularExpressionCaseInsensitive error:nil];
response.statusCode = [lines[2] integerValue];
response.headers = @{@"Content-Type":lines[3]};
NSMutableDictionary *headers = @{@"Content-Type":lines[3]}.mutableCopy;

// From line 5 to '\n\n', expect HTTP response headers.
NSRegularExpression *headerPattern = [NSRegularExpression regularExpressionWithPattern:@"^([^:]+):\\s+(.*)" options:0 error:NULL];
for (NSUInteger line = 4; line < lines.count; line ++) {
NSString *headerLine = lines[line];
NSTextCheckingResult *match = [headerPattern firstMatchInString:headerLine options:0 range:NSMakeRange(0, headerLine.length)];

if (match) {
NSString *key = [headerLine substringWithRange:[match rangeAtIndex:1]];
NSString *value = [headerLine substringWithRange:[match rangeAtIndex:2]];
headers[key] = value;
}
}

response.headers = headers.copy;
response.fileURL = url;
response.bodyOffset = [headerMatter dataUsingEncoding:originalEncoding].length + 2;
return response;
Expand All @@ -72,6 +87,16 @@ - (BOOL)matchesURL:(NSURL *)URL method:(NSString *)method patternLength:(NSUInte
return NO;
}

- (NSDictionary *)headersWithValues:(NSDictionary *)values
{
NSMutableDictionary *headers = [NSMutableDictionary dictionary];
[self.headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSString *transformedObj = [GRMustacheTemplate renderObject:values fromString:obj error:NULL];
headers[key] = transformedObj ?: obj;
}];
return headers.copy;
}

- (NSData *)bodyWithValues:(NSDictionary *)values;
{
NSData *body = [NSData dataWithContentsOfURL:self.fileURL];
Expand Down
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pod 'KIF-next', '2.0.0pre3'
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'
pod 'GRMustache', '~> 6.7'

target 'AMYServer Tests' do
pod 'KIF-next', '2.0.0pre3'
pod 'Mocktail', :git => 'https://github.com/bnickel/objc-mocktail.git', :commit => 'cd6568cdbf'
pod 'GRMustache', '~> 6.7'
end
10 changes: 1 addition & 9 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ PODS:
- JRSwizzle (~> 1.0)
- JRSwizzle (1.0)
- KIF-next (2.0.0pre3)
- Mocktail (1.2):
- GRMustache (~> 6.7.5)

DEPENDENCIES:
- GRMustache (~> 6.7)
- KIF-next (= 2.0.0pre3)
- Mocktail (from `https://github.com/bnickel/objc-mocktail.git`, commit `cd6568cdbf`)

EXTERNAL SOURCES:
Mocktail:
:commit: cd6568cdbf
:git: https://github.com/bnickel/objc-mocktail.git

SPEC CHECKSUMS:
GRMustache: fd8c4885861658b6bb79fedfbca10beb02edc97b
JRSwizzle: 6242ff38485d870fc2636899048ee1ab883ae587
KIF-next: 9035617946ec98228379f4a8088443dc04c71d62
Mocktail: d9354ae1571971e20ad216b82e49bc0d3bf48324

COCOAPODS: 0.22.2
1 change: 0 additions & 1 deletion Pods/BuildHeaders/Mocktail/Mocktail.h

This file was deleted.

1 change: 0 additions & 1 deletion Pods/BuildHeaders/Mocktail/MocktailResponse.h

This file was deleted.

1 change: 0 additions & 1 deletion Pods/BuildHeaders/Mocktail/MocktailURLProtocol.h

This file was deleted.

1 change: 0 additions & 1 deletion Pods/BuildHeaders/Mocktail/Mocktail_Private.h

This file was deleted.

1 change: 0 additions & 1 deletion Pods/Headers/Mocktail/Mocktail.h

This file was deleted.

1 change: 0 additions & 1 deletion Pods/Headers/Mocktail/MocktailResponse.h

This file was deleted.

16 changes: 0 additions & 16 deletions Pods/Local Podspecs/Mocktail.podspec

This file was deleted.

10 changes: 1 addition & 9 deletions Pods/Manifest.lock

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

15 changes: 0 additions & 15 deletions Pods/Mocktail/LICENSE

This file was deleted.

50 changes: 0 additions & 50 deletions Pods/Mocktail/Mocktail/Mocktail.h

This file was deleted.

Loading

0 comments on commit 19ef254

Please sign in to comment.