I want to make a Moya stub request in my Quick/Nimble BDD tests. Moya has a sampleData
parameter I created using a JSON file:
var sampleData: Data {
switch self {
case .getPlaces:
// Provided that project have a file named get_places.json in it's bundle.
guard let path = Bundle.main.path(forResource: "get_places", ofType: "json"),
let data = Data(base64Encoded: path) else {
return Data()
}
return data
case .getPlaceDetail:
// Provided that project have a file named get_place_detail.json in it's bundle.
guard let path = Bundle.main.path(forResource: "get_place_detail", ofType: "json"),
let data = Data(base64Encoded: path) else {
return Data()
}
return data
}
}
How can I use this parameter in tests? Any ideas to make a Moya stub request in tests?
Thank you!
testProvider.request(.getPlaces(location: "")) { places in expect(places).to(beNil()) }
andtestProvider.request(.getPlaces(location: "")) { places in expect(places).toNot(beNil()) }
. Why this happens? What I'm doing wrong? – Kautz