forked from wikimedia/wikipedia-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
1,758 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#import <Nocilla/Nocilla.h> | ||
#import "Nocilla.h" | ||
|
||
typedef LSStubResponseDSL * (^WithJSONMethod)(id json); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "LSHTTPBody.h" | ||
|
||
@interface NSData (Nocilla) <LSHTTPBody> | ||
|
||
@end |
9 changes: 9 additions & 0 deletions
9
WikipediaUnitTests/Third Party/Nocilla/Categories/NSData+Nocilla.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#import "NSData+Nocilla.h" | ||
|
||
@implementation NSData (Nocilla) | ||
|
||
- (NSData *)data { | ||
return self; | ||
} | ||
|
||
@end |
8 changes: 8 additions & 0 deletions
8
WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "LSHTTPBody.h" | ||
|
||
@interface NSString (Nocilla) <LSHTTPBody> | ||
|
||
- (NSRegularExpression *)regex; | ||
|
||
@end |
18 changes: 18 additions & 0 deletions
18
WikipediaUnitTests/Third Party/Nocilla/Categories/NSString+Nocilla.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import "NSString+Nocilla.h" | ||
|
||
@implementation NSString (Nocilla) | ||
|
||
- (NSRegularExpression *)regex { | ||
NSError *error = nil; | ||
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:self options:0 error:&error]; | ||
if (error) { | ||
[NSException raise:NSInvalidArgumentException format:@"Invalid regex pattern: %@\nError: %@", self, error]; | ||
} | ||
return regex; | ||
} | ||
|
||
- (NSData *)data { | ||
return [self dataUsingEncoding:NSUTF8StringEncoding]; | ||
} | ||
|
||
@end |
6 changes: 6 additions & 0 deletions
6
WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "LSHTTPRequest.h" | ||
|
||
@interface LSHTTPRequestDSLRepresentation : NSObject | ||
- (id)initWithRequest:(id<LSHTTPRequest>)request; | ||
@end |
39 changes: 39 additions & 0 deletions
39
WikipediaUnitTests/Third Party/Nocilla/DSL/LSHTTPRequestDSLRepresentation.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#import "LSHTTPRequestDSLRepresentation.h" | ||
|
||
@interface LSHTTPRequestDSLRepresentation () | ||
@property (nonatomic, strong) id<LSHTTPRequest> request; | ||
@end | ||
|
||
@implementation LSHTTPRequestDSLRepresentation | ||
- (id)initWithRequest:(id<LSHTTPRequest>)request { | ||
self = [super init]; | ||
if (self) { | ||
_request = request; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSString *)description { | ||
NSMutableString *result = [NSMutableString stringWithFormat:@"stubRequest(@\"%@\", @\"%@\")", self.request.method, [self.request.url absoluteString]]; | ||
if (self.request.headers.count) { | ||
[result appendString:@".\nwithHeaders(@{ "]; | ||
NSMutableArray *headerElements = [NSMutableArray arrayWithCapacity:self.request.headers.count]; | ||
|
||
NSArray *descriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"" ascending:YES]]; | ||
NSArray * sortedHeaders = [[self.request.headers allKeys] sortedArrayUsingDescriptors:descriptors]; | ||
|
||
for (NSString * header in sortedHeaders) { | ||
NSString *value = [self.request.headers objectForKey:header]; | ||
[headerElements addObject:[NSString stringWithFormat:@"@\"%@\": @\"%@\"", header, value]]; | ||
} | ||
[result appendString:[headerElements componentsJoinedByString:@", "]]; | ||
[result appendString:@" })"]; | ||
} | ||
if (self.request.body.length) { | ||
NSString *escapedBody = [[NSString alloc] initWithData:self.request.body encoding:NSUTF8StringEncoding]; | ||
escapedBody = [escapedBody stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; | ||
[result appendFormat:@".\nwithBody(@\"%@\")", escapedBody]; | ||
} | ||
return [NSString stringWithFormat:@"%@;", result]; | ||
} | ||
@end |
39 changes: 39 additions & 0 deletions
39
WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "NSString+Matcheable.h" | ||
#import "NSRegularExpression+Matcheable.h" | ||
#import "NSData+Matcheable.h" | ||
|
||
@class LSStubRequestDSL; | ||
@class LSStubResponseDSL; | ||
@class LSStubRequest; | ||
|
||
@protocol LSHTTPBody; | ||
|
||
typedef LSStubRequestDSL *(^WithHeaderMethod)(NSString *, NSString *); | ||
typedef LSStubRequestDSL *(^WithHeadersMethod)(NSDictionary *); | ||
typedef LSStubRequestDSL *(^AndBodyMethod)(id<LSMatcheable>); | ||
typedef LSStubResponseDSL *(^AndReturnMethod)(NSInteger); | ||
typedef LSStubResponseDSL *(^AndReturnRawResponseMethod)(NSData *rawResponseData); | ||
typedef void (^AndFailWithErrorMethod)(NSError *error); | ||
|
||
@interface LSStubRequestDSL : NSObject | ||
- (id)initWithRequest:(LSStubRequest *)request; | ||
|
||
@property (nonatomic, strong, readonly) WithHeaderMethod withHeader; | ||
@property (nonatomic, strong, readonly) WithHeadersMethod withHeaders; | ||
@property (nonatomic, strong, readonly) AndBodyMethod withBody; | ||
@property (nonatomic, strong, readonly) AndReturnMethod andReturn; | ||
@property (nonatomic, strong, readonly) AndReturnRawResponseMethod andReturnRawResponse; | ||
@property (nonatomic, strong, readonly) AndFailWithErrorMethod andFailWithError; | ||
|
||
@end | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
LSStubRequestDSL * stubRequest(NSString *method, id<LSMatcheable> url); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
72 changes: 72 additions & 0 deletions
72
WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubRequestDSL.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#import "LSStubRequestDSL.h" | ||
#import "LSStubResponseDSL.h" | ||
#import "LSStubRequest.h" | ||
#import "LSNocilla.h" | ||
|
||
@interface LSStubRequestDSL () | ||
@property (nonatomic, strong) LSStubRequest *request; | ||
@end | ||
|
||
@implementation LSStubRequestDSL | ||
|
||
- (id)initWithRequest:(LSStubRequest *)request { | ||
self = [super init]; | ||
if (self) { | ||
_request = request; | ||
} | ||
return self; | ||
} | ||
- (WithHeadersMethod)withHeaders { | ||
return ^(NSDictionary *headers) { | ||
for (NSString *header in headers) { | ||
NSString *value = [headers objectForKey:header]; | ||
[self.request setHeader:header value:value]; | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (WithHeaderMethod)withHeader { | ||
return ^(NSString * header, NSString * value) { | ||
[self.request setHeader:header value:value]; | ||
return self; | ||
}; | ||
} | ||
|
||
- (AndBodyMethod)withBody { | ||
return ^(id<LSMatcheable> body) { | ||
self.request.body = body.matcher; | ||
return self; | ||
}; | ||
} | ||
|
||
- (AndReturnMethod)andReturn { | ||
return ^(NSInteger statusCode) { | ||
self.request.response = [[LSStubResponse alloc] initWithStatusCode:statusCode]; | ||
LSStubResponseDSL *responseDSL = [[LSStubResponseDSL alloc] initWithResponse:self.request.response]; | ||
return responseDSL; | ||
}; | ||
} | ||
|
||
- (AndReturnRawResponseMethod)andReturnRawResponse { | ||
return ^(NSData *rawResponseData) { | ||
self.request.response = [[LSStubResponse alloc] initWithRawResponse:rawResponseData]; | ||
LSStubResponseDSL *responseDSL = [[LSStubResponseDSL alloc] initWithResponse:self.request.response]; | ||
return responseDSL; | ||
}; | ||
} | ||
|
||
- (AndFailWithErrorMethod)andFailWithError { | ||
return ^(NSError *error) { | ||
self.request.response = [[LSStubResponse alloc] initWithError:error]; | ||
}; | ||
} | ||
|
||
@end | ||
|
||
LSStubRequestDSL * stubRequest(NSString *method, id<LSMatcheable> url) { | ||
LSStubRequest *request = [[LSStubRequest alloc] initWithMethod:method urlMatcher:url.matcher]; | ||
LSStubRequestDSL *dsl = [[LSStubRequestDSL alloc] initWithRequest:request]; | ||
[[LSNocilla sharedInstance] addStubbedRequest:request]; | ||
return dsl; | ||
} |
19 changes: 19 additions & 0 deletions
19
WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@class LSStubResponse; | ||
@class LSStubResponseDSL; | ||
|
||
@protocol LSHTTPBody; | ||
|
||
typedef LSStubResponseDSL *(^ResponseWithBodyMethod)(id<LSHTTPBody>); | ||
typedef LSStubResponseDSL *(^ResponseWithHeaderMethod)(NSString *, NSString *); | ||
typedef LSStubResponseDSL *(^ResponseWithHeadersMethod)(NSDictionary *); | ||
|
||
@interface LSStubResponseDSL : NSObject | ||
- (id)initWithResponse:(LSStubResponse *)response; | ||
|
||
@property (nonatomic, strong, readonly) ResponseWithHeaderMethod withHeader; | ||
@property (nonatomic, strong, readonly) ResponseWithHeadersMethod withHeaders; | ||
@property (nonatomic, strong, readonly) ResponseWithBodyMethod withBody; | ||
|
||
@end |
40 changes: 40 additions & 0 deletions
40
WikipediaUnitTests/Third Party/Nocilla/DSL/LSStubResponseDSL.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#import "LSStubResponseDSL.h" | ||
#import "LSStubResponse.h" | ||
#import "LSHTTPBody.h" | ||
|
||
@interface LSStubResponseDSL () | ||
@property (nonatomic, strong) LSStubResponse *response; | ||
@end | ||
|
||
@implementation LSStubResponseDSL | ||
- (id)initWithResponse:(LSStubResponse *)response { | ||
self = [super init]; | ||
if (self) { | ||
_response = response; | ||
} | ||
return self; | ||
} | ||
- (ResponseWithHeaderMethod)withHeader { | ||
return ^(NSString * header, NSString * value) { | ||
[self.response setHeader:header value:value]; | ||
return self; | ||
}; | ||
} | ||
|
||
- (ResponseWithHeadersMethod)withHeaders; { | ||
return ^(NSDictionary *headers) { | ||
for (NSString *header in headers) { | ||
NSString *value = [headers objectForKey:header]; | ||
[self.response setHeader:header value:value]; | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (ResponseWithBodyMethod)withBody { | ||
return ^(id<LSHTTPBody> body) { | ||
self.response.body = [body data]; | ||
return self; | ||
}; | ||
} | ||
@end |
8 changes: 8 additions & 0 deletions
8
WikipediaUnitTests/Third Party/Nocilla/Diff/LSHTTPRequestDiff.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "LSHTTPRequest.h" | ||
|
||
@interface LSHTTPRequestDiff : NSObject | ||
@property (nonatomic, assign, readonly, getter = isEmpty) BOOL empty; | ||
|
||
- (id)initWithRequest:(id<LSHTTPRequest>)oneRequest andRequest:(id<LSHTTPRequest>)anotherRequest; | ||
@end |
Oops, something went wrong.