Mockingjay
Mockingjay copied to clipboard
Support for Swift 4 multiline json string
let myJsonString = """
{
"example": "value"
}
"""
stub(http(.post, uri: "*/route"), jsonString(myJsonString))
Implementation would be something like this inside the Builders.swift:
public func jsonString(_ jsonString: String, status: Int = 200, headers: [String:String]? = nil) -> (_ request: URLRequest) -> Response {
return { (request:URLRequest) in
var headers = headers ?? [String:String]()
if headers["Content-Type"] == nil {
headers["Content-Type"] = "application/json; charset=utf-8"
}
let data = jsonString.data(using: .utf8)!
return http(status, headers: headers, download: .content(data))(request)
}
}