Thx. It's exactly what I searched.

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

> On Thu, May 30, 2013 at 2:44 AM, Alexander Baronec <abo...@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@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
С наилучшими пожеланиями,
Александр
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to