Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread David Chelimsky
On Mon, Aug 6, 2012 at 9:21 AM, Alexander Baronec  wrote:
> 2012/8/6 David Chelimsky 
>>
>> On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec 
>> wrote:
>> > 2012/8/5 David Chelimsky 
>> >>
>> >> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec 
>> >> wrote:
>> >> > Hello.
>> >> > How can I test object to receive message and compare arguments of
>> >> > this
>> >> > message with value evaluated at present time? It is possible?
>> >> >
>> >> > For example:
>> >> >
>> >> > should_receive(:api_send).with( -> { players.count } ) And
>> >> > players.count
>> >> > will be called and evaluated only when api_send is received.
>> >>
>> >> Look at Fake Implementation on
>> >> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
>> >> You can do the same thing w/ should_receive, e.g.
>> >>
>> >> foo.should_receive(:api_send) do |player_count|
>> >>   player_count.should eq players.count
>> >> end
>> >>
>> >> HTH,
>> >> David
>>
>> > It don't work when object received few messages. I described it there:
>> >
>> > http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages
>>
>> should_receive, by default, expects exactly one call, but there are a
>> number of ways for you to specify more than one call. One possibility
>> would be:
>>
>> foo.should_receive(:api_send).ordered
>> foo.should_receive(:api_send).with(2).ordered
>>
>> See http://rubydoc.info/gems/rspec-mocks for more info

> I wan't to test order of received messages. I want to test only one message
> of few and compare it with real-time value.
> It's not possible?

It is, but you have to specify which time it should care if you're
going to compare it to a real time value.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread Alexander Baronec
I wan't to test order of received messages. I want to test only one message
of few and compare it with real-time value.
It's not possible?

2012/8/6 David Chelimsky 

> On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec 
> wrote:
> > 2012/8/5 David Chelimsky 
> >>
> >> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec 
> >> wrote:
> >> > Hello.
> >> > How can I test object to receive message and compare arguments of this
> >> > message with value evaluated at present time? It is possible?
> >> >
> >> > For example:
> >> >
> >> > should_receive(:api_send).with( -> { players.count } ) And
> players.count
> >> > will be called and evaluated only when api_send is received.
> >>
> >> Look at Fake Implementation on
> >> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
> >> You can do the same thing w/ should_receive, e.g.
> >>
> >> foo.should_receive(:api_send) do |player_count|
> >>   player_count.should eq players.count
> >> end
> >>
> >> HTH,
> >> David
>
> > It don't work when object received few messages. I described it there:
> >
> http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages
>
> should_receive, by default, expects exactly one call, but there are a
> number of ways for you to specify more than one call. One possibility
> would be:
>
> foo.should_receive(:api_send).ordered
> foo.should_receive(:api_send).with(2).ordered
>
> See http://rubydoc.info/gems/rspec-mocks for more info
> ___
> 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

Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread David Chelimsky
On Mon, Aug 6, 2012 at 3:48 AM, Alexander Baronec  wrote:
> 2012/8/5 David Chelimsky 
>>
>> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec 
>> wrote:
>> > Hello.
>> > How can I test object to receive message and compare arguments of this
>> > message with value evaluated at present time? It is possible?
>> >
>> > For example:
>> >
>> > should_receive(:api_send).with( -> { players.count } ) And players.count
>> > will be called and evaluated only when api_send is received.
>>
>> Look at Fake Implementation on
>> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
>> You can do the same thing w/ should_receive, e.g.
>>
>> foo.should_receive(:api_send) do |player_count|
>>   player_count.should eq players.count
>> end
>>
>> HTH,
>> David

> It don't work when object received few messages. I described it there:
> http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages

should_receive, by default, expects exactly one call, but there are a
number of ways for you to specify more than one call. One possibility
would be:

foo.should_receive(:api_send).ordered
foo.should_receive(:api_send).with(2).ordered

See http://rubydoc.info/gems/rspec-mocks for more info
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] should_receive with block or proc?

2012-08-06 Thread Alexander Baronec
It don't work when object received few messages. I described it there:
http://stackoverflow.com/questions/11669979/should-recieve-alongside-other-messages

2012/8/5 David Chelimsky 

> On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec 
> wrote:
> > Hello.
> > How can I test object to receive message and compare arguments of this
> > message with value evaluated at present time? It is possible?
> >
> > For example:
> >
> > should_receive(:api_send).with( -> { players.count } ) And players.count
> > will be called and evaluated only when api_send is received.
>
> Look at Fake Implementation on
> https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
> You can do the same thing w/ should_receive, e.g.
>
> foo.should_receive(:api_send) do |player_count|
>   player_count.should eq players.count
> end
>
> 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

Re: [rspec-users] should_receive with block or proc?

2012-08-05 Thread David Chelimsky
On Sat, Aug 4, 2012 at 1:46 PM, Alexander Baronec  wrote:
> Hello.
> How can I test object to receive message and compare arguments of this
> message with value evaluated at present time? It is possible?
>
> For example:
>
> should_receive(:api_send).with( -> { players.count } ) And players.count
> will be called and evaluated only when api_send is received.

Look at Fake Implementation on
https://www.relishapp.com/rspec/rspec-mocks/v/2-11/docs/method-stubs.
You can do the same thing w/ should_receive, e.g.

foo.should_receive(:api_send) do |player_count|
  player_count.should eq players.count
end

HTH,
David
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users