I would hide the tricks even more: ZnClient stubRequests: [ :request | request uri = ('https://onesignal.com/api/v1/players/{1}?app_id={2}' format: { self uidy: 'Q7'. appId }) asZnUrl and: [ #(GET HEAD) includes: request method ] ] byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ].
And maybe with set of more simple cases: ZnClient stubGET: ('https://onesignal.com/api/v1/players/{1}?app_id={2}' format: { self uidy: 'Q7'. appId }) asZnUrl byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ]. Or better: ZnClient stubGET: ('https://onesignal.com/api/v1/players' asZnUrl / (self uidy: 'Q7') withParams: {'app_id' -> appId } byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ]. 2017-10-17 14:22 GMT+02:00 Herby Vojčík <he...@mailbox.sk>: > Denis Kudriashov wrote: > >> Hi Herby. >> >> There is message #will: which accepts the block with possible arguments >> (if needed). >> >> ZnClient stub new will: [ ZnMockClient ...] >> >> But generally your approach looks bad to me. You put too many details on >> your tests which just duplicate Zinc API used in the domain code. It >> makes tests brittle and tightly coupled. And they looks quite unreadable. >> > > BTW, made it shorter and probably more readable as a result (by also > shortening the test condition): > > ZnClient stub new will: [ ZnMockClient > whenRequest: [ :request | > request uri = ('https://onesignal.com/api/v1/players/{1}?app_id={2}' > format: { self uidy: 'Q7'. appId }) asZnUrl > and: [ #(GET HEAD) includes: request method ] ] > thenResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ]. > > The reason why I could not test uri as is, is Zinc adding ':443' to it. > But as mentioned, the previous was very unreadable; with asZnUrl it is > probably better. > > Herby >