2017-10-17 14:49 GMT+02:00 Herby Vojčík <he...@mailbox.sk>:

> Denis Kudriashov wrote:
>
>> I would hide the tricks even more:
>>
>>    ZnClient stubRequests: [ :request |
>>        request uri =
>> ('https://onesignal.com/api/v1/players/{1}?app_id={2}
>> <https://onesignal.com/api/v1/players/%7B1%7D?app_id=%7B2%7D>' format: {
>> self uidy: 'Q7'. appId }) asZnUrl
>>          and: [ #(GET HEAD) includes: request method ] ]
>>      byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ].
>>
>
> This would be nice, but it would need cooperation of Zinc (unless I hide
> mocketry use under extension method).
>

Why not? I think it could be a  good library. Try to publish it as is. Then
people can contribute with their own cases.
I remember other people looked for similar tool in past. So it could be
good start.


>
> And maybe with set of more simple cases:
>>
>>    ZnClient
>>      stubGET: ('https://onesignal.com/api/v1/players/{1}?app_id={2}
>> <https://onesignal.com/api/v1/players/%7B1%7D?app_id=%7B2%7D>' format: {
>> self uidy: 'Q7'. appId }) asZnUrl
>>      byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ].
>>
>
> Well, I actually send HEAD in production code, as I only need to know if
> it is 2xx or 4xx (of course using #isSuccess and not testing status code
> myself) and I want be nice. But GET is good as well. Now what? :-)
>
> Or better:
>>
>>    ZnClient
>>      stubGET: ('https://onesignal.com/api/v1/players' asZnUrl / (self
>> uidy: 'Q7')
>>      withParams: {'app_id' -> appId }
>>      byResponse: [ :request | ZnResponse ok: (ZnEntity json: '{}') ] ].
>>
>
> Yes, we're getting where nock library is on node. I didn't want to make
> full http mocking dsl (would be nice, though).


You can be the man who starts the process :). Not necessary to implement
full version.


> Actually asked if there is one is the original thread. :-)
>
> Herby
>
>
>>
>>
>> 2017-10-17 14:22 GMT+02:00 Herby Vojčík <he...@mailbox.sk
>> <mailto: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}
>>     <https://onesignal.com/api/v1/players/%7B1%7D?app_id=%7B2%7D>'
>>     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
>>
>>
>>
>

Reply via email to