[rspec-users] Fuzzy should_receive matching

Alexander Baronec abonec at gmail.com
Wed Jun 5 09:20:28 UTC 2013


Thx. It's exactly what I searched.


On Thu, May 30, 2013 at 4:11 PM, David Chelimsky <dchelimsky at gmail.com>wrote:

> On Thu, May 30, 2013 at 2:44 AM, Alexander Baronec <abonec at gmail.com>wrote:
>
>> Hello.
>> I have a test problem when I should test arguments in method not by exact
>> matching buy with fuzzy matching.
>>
>> For example I have this test:
>>
>> require 'rspec'
>>
>> describe do
>>   it do
>>     o = Object.new
>>     o.should_receive(:api_send).with mode: :say
>>
>>     o.api_send mode: :say, time: Time.now + rand(1..10), bans: { login1:
>> {time: Time.now, expiration: Time.now + 100}}
>>
>   end
>> end
>>
>> I want helper to test that method api_send receive mode: :say, time:
>> Time.now + rand(1..10), bans: { login1: {time: Time.now, expiration:
>> Time.now + 100}} but I do not care about what time exactly is.
>>
>> I want something like
>>
>> inspect_api o, mode: :say, time: Time, bans: { login:1: {time: Time,
>> expiration: Time}}
>>
>
> See docs:
>
> http://rubydoc.info/gems/rspec-mocks/file/README.md#Argument_Matchers
>
> http://rubydoc.info/gems/rspec-mocks/RSpec/Mocks/ArgumentMatchers#hash_including-instance_method
>
> (the info in the 2nd link needs to be added to the first - sorry)
>
> You could do either of:
>
>     o.should_receive(:api_send).with hash_including(mode: :say)
>     o.should_receive(:api_send).with mode: :say, time: instance_of(Time),
> :bans { login1: {time: instance_of(Time), expiration: instance_of(Time) }
>
> HTH,
> David
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
С наилучшими пожеланиями,
Александр
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130605/6c1781c5/attachment.html>


More information about the rspec-users mailing list