Mocketry: what is used of #where ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mocketry: what is used of #where ?

Herby Vojčík
Hello,

When I am writing tests using Mocketry's DSL, I get puzzled about how /
when to use #where, and how is it different when it's used and when it
is not?

As far as i tried, I did not find any difference. That is, pasting part
of one of my tests:

    response := znClient
                username: (self uidy: 'Q7') asString, '/TEST' password: 'tk';
                timeout: 1; post; response.
        response should be isSuccess.
        response where contentType should equal: ZnMimeType applicationJson.
        response where entity should not be: nil.
        (STON fromString: response entity contents) should equal: nil

I get the same result (pass if ok, failure with DNU when thing is not
present) whether `where` is there or isn't.

Could you explain what is it's purpose and correct usage?

Thanks, Herby

Reply | Threaded
Open this post in threaded view
|

Re: Mocketry: what is used of #where ?

Denis Kudriashov
Hi Herbert.

It is a bit experimental API to allow more descriptive failures. Evaluate following code:

(2@3) where x should equal: 10

It will give you failure message: Got "2" from (2@3) x but it should equal "10".
But without #where it would be: Got "2" but it should equal "10". 

And it works with long message chains:

(2@3 corner: 10@30) where origin x should equal: 10

It will show: Got "2" from (2@3) corner: (10@30) origin x but it should equal "10".

I am still not sure is it good approach or not. But that is idea.
Besides It is possible to retrieve such information using magic with thisContext and reflectivity. But again the question is same: does it really make sense to do it for assertions? 

Best regards,
Denis 



2018-05-04 16:28 GMT+03:00 Herbert Vojčík <[hidden email]>:
Hello,

When I am writing tests using Mocketry's DSL, I get puzzled about how / when to use #where, and how is it different when it's used and when it is not?

As far as i tried, I did not find any difference. That is, pasting part of one of my tests:

        response := znClient
                username: (self uidy: 'Q7') asString, '/TEST' password: 'tk';
                timeout: 1; post; response.
        response should be isSuccess.
        response where contentType should equal: ZnMimeType applicationJson.
        response where entity should not be: nil.
        (STON fromString: response entity contents) should equal: nil

I get the same result (pass if ok, failure with DNU when thing is not present) whether `where` is there or isn't.

Could you explain what is it's purpose and correct usage?

Thanks, Herby


Reply | Threaded
Open this post in threaded view
|

Re: Mocketry: what is used of #where ?

Sean P. DeNigris
Administrator
Denis Kudriashov wrote
> It will give you failure message: Got "2" from (2@3) x but it should equal
> "10".
> But without #where it would be: Got "2" but it should equal "10".

Wow, that sounds really cool. I'll have to play with it a bit to see how
much difference it makes in practice…



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Mocketry: what is used of #where ?

Herby Vojčík
In reply to this post by Denis Kudriashov


Denis Kudriashov wrote:

> Hi Herbert.
>
> It is a bit experimental API to allow more descriptive failures.
> Evaluate following code:
>
>
>     (2@3) where x should equal: 10
>
> It will give you failure message: Got "2" from (2@3) x but it should
> equal "10".
> But without #where it would be: Got "2" but it should equal "10".
>
> And it works with long message chains:
>
>     (2@3 corner: 10@30) where origin x should equal: 10
>
> It will show: Got "2" from (2@3) corner: (10@30) origin x but it should
> equal "10".

So in my case, I could see difference in something like this?

         responseCheck := (znClient
                 username: (self uidy: 'Q7') asString, '/TEST' password:
'tk';
                 timeout: 1; post; response) where.
         responseCheck should be isSuccess.
         responseCheck where contentType should equal: ZnMimeType
applicationJson.
         responseCheck where entity should not be: nil.

In that case it would be nice to be able to write something like:

         (znClient
                 username: (self uidy: 'Q7') asString, '/TEST' password:
'tk';
                 timeout: 1; post; response) where: [ :response |
         response should be isSuccess.
         response where contentType should equal: ZnMimeType
applicationJson.
         response where entity should not be: nil ].

> I am still not sure is it good approach or not. But that is idea.
> Besides It is possible to retrieve such information using magic with
> thisContext and reflectivity. But again the question is same: does it
> really make sense to do it for assertions?
>
> Best regards,
> Denis
>
>
>
> 2018-05-04 16:28 GMT+03:00 Herbert Vojčík <[hidden email]
> <mailto:[hidden email]>>:
>
>     Hello,
>
>     When I am writing tests using Mocketry's DSL, I get puzzled about
>     how / when to use #where, and how is it different when it's used and
>     when it is not?
>
>     As far as i tried, I did not find any difference. That is, pasting
>     part of one of my tests:
>
>              response := znClient
>                      username: (self uidy: 'Q7') asString, '/TEST'
>     password: 'tk';
>                      timeout: 1; post; response.
>              response should be isSuccess.
>              response where contentType should equal: ZnMimeType
>     applicationJson.
>              response where entity should not be: nil.
>              (STON fromString: response entity contents) should equal: nil
>
>     I get the same result (pass if ok, failure with DNU when thing is
>     not present) whether `where` is there or isn't.
>
>     Could you explain what is it's purpose and correct usage?
>
>     Thanks, Herby
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Mocketry: what is used of #where ?

Herby Vojčík


Herbert Vojčík wrote:

>
>
> Denis Kudriashov wrote:
>> Hi Herbert.
>>
>> It is a bit experimental API to allow more descriptive failures.
>> Evaluate following code:
>>
>>
>>     (2@3) where x should equal: 10
>>
>> It will give you failure message: Got "2" from (2@3) x but it should
>> equal "10".
>> But without #where it would be: Got "2" but it should equal "10".
>>
>> And it works with long message chains:
>>
>>     (2@3 corner: 10@30) where origin x should equal: 10
>>
>> It will show: Got "2" from (2@3) corner: (10@30) origin x but it
>> should equal "10".
>
> So in my case, I could see difference in something like this?
>
>          responseCheck := (znClient
>                  username: (self uidy: 'Q7') asString, '/TEST' password:
> 'tk';
>                  timeout: 1; post; response) where.
>          responseCheck should be isSuccess.
>          responseCheck where contentType should equal: ZnMimeType
> applicationJson.
>          responseCheck where entity should not be: nil.
>
> In that case it would be nice to be able to write something like:
>
>          (znClient
>                  username: (self uidy: 'Q7') asString, '/TEST' password:
> 'tk';
>                  timeout: 1; post; response) where: [ :response |
>          response should be isSuccess.
>          response where contentType should equal: ZnMimeType
> applicationJson.
>          response where entity should not be: nil ].

Ah, I get it, it prints the receiver and lists the message chain...
ignore this. Thanks.

>> I am still not sure is it good approach or not. But that is idea.
>> Besides It is possible to retrieve such information using magic with
>> thisContext and reflectivity. But again the question is same: does it
>> really make sense to do it for assertions?
>>
>> Best regards,
>> Denis
>>
>>
>>
>> 2018-05-04 16:28 GMT+03:00 Herbert Vojčík <[hidden email]
>> <mailto:[hidden email]>>:
>>
>>     Hello,
>>
>>     When I am writing tests using Mocketry's DSL, I get puzzled about
>>     how / when to use #where, and how is it different when it's used and
>>     when it is not?
>>
>>     As far as i tried, I did not find any difference. That is, pasting
>>     part of one of my tests:
>>
>>              response := znClient
>>                      username: (self uidy: 'Q7') asString, '/TEST'
>>     password: 'tk';
>>                      timeout: 1; post; response.
>>              response should be isSuccess.
>>              response where contentType should equal: ZnMimeType
>>     applicationJson.
>>              response where entity should not be: nil.
>>              (STON fromString: response entity contents) should equal:
>> nil
>>
>>     I get the same result (pass if ok, failure with DNU when thing is
>>     not present) whether `where` is there or isn't.
>>
>>     Could you explain what is it's purpose and correct usage?
>>
>>     Thanks, Herby
>>
>>
>