You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im trying to stub a request with a specific body, i'm copying it from Charles but im getting always the same error:
Use this snippet to stub the request:
stubRequest(@"PUT", @"http://url.com").
withHeaders(@{ @"Accept": @"application/json", @"Accept-Encoding": @"gzip;q=1.0, compress;q=0.5", @"Accept-Language": @"en-US;q=1.0", @"Content-Length": @"108", @"Content-Type": @"application/json", @"User-Agent": @"Unknown/Unknown (Unknown; OS Version 9.3 (Build 13E230))", @"X-deviceToken": @"deviceToken", @"X-platformId": @"3", @"deviceId": @"deviceId", @"languageId": @"3" }).
withBody(@"{
\"matchIds\" : [
\"17\",
\"MatchId_3\",
\"MatchId_34\"
],
\"values\" : {
\"viewed\" : true
}
}");
And this in my test:
let urlPut = "http://url.com"
stubRequest("PUT", urlPut)
.withBody(fromJsonFile("getMatchesRequestPUTBody"))
.andReturn(200)
.withHeaders(["Content-Type": "application/json"])
Where getMatchesRequestPUTBody contains:
{
"matchIds" : [
"17",
"MatchId_3",
"MatchId_34"
],
"values" : {
"viewed" : true
}
}
If i remove the line "withBody" it works as expected.
Any ideas?
Notice i'm stubbing 2 request in the same method.
public func fromJsonFile(fileName: String) -> String {
return fromFile(fileName, fileExtension: "json")
}
public func fromTxtFile(fileName: String) -> String {
return fromFile(fileName, fileExtension: "txt")
}
public func fromFile(fileName: String, fileExtension: String) -> String {
let classBundle = NSBundle(forClass: self.classForCoder)
let path = classBundle.pathForResource(fileName, ofType: fileExtension)
let absolutePath = path ?? ""
do {
return try String(contentsOfFile: absolutePath, encoding: NSUTF8StringEncoding)
} catch _ {
print("Error trying to read file \(absolutePath). The file does not exist")
return ""
}
}
The text was updated successfully, but these errors were encountered:
Im trying to stub a request with a specific body, i'm copying it from Charles but im getting always the same error:
And this in my test:
Where getMatchesRequestPUTBody contains:
{
"matchIds" : [
"17",
"MatchId_3",
"MatchId_34"
],
"values" : {
"viewed" : true
}
}
If i remove the line "withBody" it works as expected.
Any ideas?
Notice i'm stubbing 2 request in the same method.
The text was updated successfully, but these errors were encountered: