summaryrefslogtreecommitdiff
path: root/test/ios/OHHTTPStubs/OHHTTPStubs/Sources/Mocktail/OHHTTPStubs+Mocktail.h
blob: 77fe65e892dbdb88bef99318751fcd2c9b2eb4de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/***********************************************************************************
 *
 * Copyright (c) 2015 Jinlian (Sunny) Wang
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 ***********************************************************************************/


////////////////////////////////////////////////////////////////////////////////

#import <OHHTTPStubs/OHHTTPStubs.h>
#import <OHHTTPStubs/Compatibility.h>

NS_ASSUME_NONNULL_BEGIN

/**
 * Error codes for the OHHTTPStubs Mocktail category
 */
typedef NS_ENUM(NSInteger, OHHTTPStubsMocktailError) {
    /** The specified path does not exist */
    OHHTTPStubsMocktailErrorPathDoesNotExist = 1,
    /** The specified path was not readable */
    OHHTTPStubsMocktailErrorPathFailedToRead,
    /** The specified path is not a directory */
    OHHTTPStubsMocktailErrorPathIsNotFolder,
    /** The specified file is not a valid Mocktail file */
    OHHTTPStubsMocktailErrorInvalidFileFormat,
    /** The specified Mocktail file has invalid headers */
    OHHTTPStubsMocktailErrorInvalidFileHeader,
    /** An unexpected internal error occured */
    OHHTTPStubsMocktailErrorInternalError
};

extern NSString* const MocktailErrorDomain;

@interface OHHTTPStubs (Mocktail)

/**
 * Add a stub given a file in the format of Mocktail as defined at https://github.com/square/objc-mocktail.
 *
 * This method will split the HTTP method Regex, the absolute URL Regex, the headers, the HTTP status code and
 * response body, and use them to add a stub.
 *
 * @param fileName The name of the mocktail file (without extension of '.tail') in the Mocktail format.
 * @param bundleOrNil The bundle in which the mocktail file is located. If `nil`, the `[NSBundle bundleForClass:self.class]` will be used.
 * @param error An out value that returns any error encountered during stubbing. Returns an NSError object if any error; otherwise returns nil.
 *
 * @return a stub descriptor that uniquely identifies the stub and can be later used to remove it with
 * `removeStub:`.
 */
+(id<OHHTTPStubsDescriptor>)stubRequestsUsingMocktailNamed:(NSString *)fileName inBundle:(nullable NSBundle*)bundleOrNil error:(NSError **)error;

/**
 * Add a stub given a file URL in the format of Mocktail as defined at https://github.com/square/objc-mocktail.
 *
 * This method will split the HTTP method Regex, the absolute URL Regex, the headers, the HTTP status code and
 * response body, and use them to add a stub.
 *
 * @param fileURL The URL pointing to the file in the Mocktail format.
 * @param error An out value that returns any error encountered during stubbing. Returns an NSError object if any error; otherwise returns nil.
 *
 * @return a stub descriptor that uniquely identifies the stub and can be later used to remove it with
 * `removeStub:`.
 */
+(id<OHHTTPStubsDescriptor>)stubRequestsUsingMocktail:(NSURL *)fileURL error:(NSError **)error;

/**
 * Add stubs using files under a folder in the format of Mocktail as defined at https://github.com/square/objc-mocktail.
 *
 * This method will retrieve all the files under the folder; for each file with surfix of ".tail", it will split the HTTP method Regex, the absolute URL Regex, the headers, the HTTP status code and response body, and use them to add a stub.
 *
 * @param path The name of the folder containing files in the Mocktail format.
 * @param bundleOrNil The bundle in which the path is located. If `nil`, the `[NSBundle bundleForClass:self.class]` will be used.
 * @param error An out value that returns any error encountered during stubbing. Returns an NSError object if any error; otherwise returns nil.
 *
 * @return an array of stub descriptor that uniquely identifies the stub and can be later used to remove it with
 * `removeStub:`.
 */
+(NSArray *)stubRequestsUsingMocktailsAtPath:(NSString *)path inBundle:(nullable NSBundle*)bundleOrNil error:(NSError **)error;

@end

NS_ASSUME_NONNULL_END