Fork me on GitHub
#ring
<
2017-10-30
>
kennytilton18:10:33

I am working on a client framework and am hoping to find a way to mock responses, not requests. I see a few mentions that ring.mock does that, but no sign of it in the source or doc. Am I just deeply confused?

seancorfield18:10:40

I thought ring.mock only mocked requests...?

seancorfield18:10:43

For responses, what sort of things are you looking to mock @hiskennyness? By the time a response reaches the client, isn't just an regular HTTP response, i.e., a bunch of lines of text starting with headers?

seancorfield19:10:37

You'd be mocking ajax requests and responses I guess. I'd expect there to be a JS library for that...?

kennytilton19:10:44

Agreed, @seancorfield on the scope of ring mock, but a stack overflow response and the doc for https://github.com/johanhaleby/stub-http itself both cite ring.mock as alternatives to response faking. Now you know why I proposed “deeply confused” as one explanation. 🙂 My test code will be executing a callback hell sequence of Ajax requests (that is the functional capability I am targeting)… hmmm, maybe I need to bring up a cooperating server to truly simulate asynchronous chaos. A fixed test I can hit any public REST API.

seancorfield20:10:57

I think it's a matter of how you read that doc... "A Clojure library designed to stub HTTP responses regardless of which client library that is used to make the actual HTTP requests. There are several client specific "http mocking/stubbing/faking" libraries out there such as clj-http-fake and ring-mock but they work on the level of the library and not the HTTP level." -- to me that just implies that ring-mock can be used for mocking around Ring (since it mocks how a client behaves in terms of interacting with Ring).

seancorfield20:10:12

But, yeah, it could certainly be clearer.

kennytilton22:10:35

Ah, right: the sequence of /-delimited functions broadened the context beyond stubbing. Thx.