Moya: More documention on stubbing requests

Created on 7 Mar 2017  路  6Comments  路  Source: Moya/Moya

Hello. I was looking at stubbing Moya requests and I had great difficulty in figuring out how to do it. It would be great if the documentation could give examples on how to do so.

chore documentation question

Most helpful comment

@dannymout For absolute beginners who haven't read all the docs yet, I would expect to see documentation about stubs in the Basic section. This is especially important as the Basic doc talks about sampleData and how great Moya helps you doing unit testing.

Thanks for making Moya!

All 6 comments

@hartbit Were you not able to find the docs? It's pretty clear on how to stub the requests.

When you create an instance of the MoyaProvider, add stubClosure:.
let provider = MoyaProvider<MyTarget>(stubClosure: MoyaProvider.immediatelyStub)

It might be a good idea to make finding these things easier.

@dannymout For absolute beginners who haven't read all the docs yet, I would expect to see documentation about stubs in the Basic section. This is especially important as the Basic doc talks about sampleData and how great Moya helps you doing unit testing.

Thanks for making Moya!

What if i try to use provider like this ?

let provider = MoyaProvider<Target>(endpointClosure: defaultEndpointClosure, stubClosure: MoyaProvider.immediatelyStub)

As someone currently trying to figure this out, I agree that it should be in the Basics section.

Also, while the Provider docs make it clear how to "stub" the requests, it doesn't make it clear what that the requests are stubbed with. sampleData is not mentioned anywhere on the page except as part of the default endpoint closure. It'd be nice to explicitly state the connection to prevent confusion. It'd also make that page show up in searches for sampleData.

Thanks!

I can see why this is confusing. There doesn't seem to be a centralized section for testing. It's scattered among providers, basics, etc.

I'll see what I can do to improve this but I'm guessing it's a week before I'll be able to do a write up. I'm assigning this issue to myself but if anyone can complete it before me - feel free.

This is a duplicate of #632. Linking and closing

Was this page helpful?
0 / 5 - 0 ratings