测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Tatsuya Tanaka,Tatsuya Tanaka 维护。
一个易于使用的库,用于模拟 HTTP 请求。
具体来说,可以替换 URLSession 的响应为 JSON 字符串。
import XCTest
class MokeiTests: XCTestCase {
func testJSONFile() {
// register a stub
self.stub.url("echo.jsontest.com").json(["test": "data"])
// load sample.json & register a stub.
self.stub.json(filename: "sample")
let expectation = self.expectation(description: "")
let url = URL(string: "http://echo.jsontest.com/key/value/one/two")!
URLSession(configuration: .default).dataTask(with: url) { data, _, _ in
let json = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! [String: String]
XCTAssert(json["test"] == "data")
expectation.fulfill()
}.resume()
self.waitForExpectations(timeout: 0.02, handler: nil)
}
}
import Quick
import Nimble
import Alamofire
class MokeiSpecs: QuickSpec {
override func spec() {
describe("Quick compatibility test") {
context("using JSON file") {
beforeEach() {
// wait for 1s
self.stub.url("echo.jsontest.com/[a-z]+/.*").httpMethod(.post).json(["test": "data"]).delay(1)
}
it("returns mock data") {
var json: [String: String]?
Alamofire.request("http://echo.jsontest.com/key/value/one/two", method: .post).responseJSON { response in
json = response.result.value as? [String: String]
}
// SessionManager is also OK.
// SessionManager.default.request("http://echo.jsontest.com/key/value/one/two").responseJSON { _ in }
expect(json?["test"]).toEventually(equal("data"))
}
}
}
}
}
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Mokei 根据 MIT 许可证发布。有关详细信息,请参阅 LICENSE。