TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SPMSupports SPM | ✗ |
Maintained by Wojtek Lukaszuk.
HTTP/HTTPS requests stubbing for iOS and macOS. It works with NSURLSession, AFNetworking, Alamofire or any networking framework that use Cocoa’s URL Loading System.
WebMock requires using session configuration’s replacements instead of default ones.
let defaultConfiguration = NSURLSessionConfiguration.webmockDefaultSessionConfiguration()
let ephemeralConfiguration = NSURLSessionConfiguration.webmockEphemeralSessionConfiguration()
let data = "test".dataUsingEncoding(NSUTF8StringEncoding)
let response = Response(data: data)
let URL = NSURL(string: "https://www.google.com")!
let stub = Stub(method: .GET, URL: URL, response: response)
WebMock.startWithStubs([stub])
let json = ["testKey": "testValue"]
let response = Response(json: json)
let URL = NSURL(string: "https://www.google.com")!
let stub = Stub(method: .GET, URL: URL, response: response)
WebMock.startWithStubs([stub])
let fileURL = bundle.pathForResource("test", ofType: "json")!
let response = Response(fileURL: fileURL)
let URL = NSURL(string: "https://www.google.com")!
let stub = Stub(method: .GET, URL: URL, response: response)
WebMock.startWithStubs([stub])
let error = NSError(domain: NSInternalInconsistencyException,
code: 0,
userInfo: nil)
let response = Response(error: error)
let URL = NSURL(string: "https://www.google.com")!
let stub = Stub(method: .GET, URL: URL, response: response)
WebMock.startWithStubs([stub])
You can additionaly define response’s header fields and http method.
Manually add the file into your Xcode project. Slightly simpler, but updates are also manual.
Wojtek Lukaszuk @wojteklu
WebMock is available under the MIT license. See the LICENSE file for more info.