Hi,
surely I''m missing something... but what!?
in my spec I''ve
User.should_receive(:find).with("1").and_return(@user)
and in my controller
User.find(params[:id])
green light... correct...
but if I change my controller using another method, for example first:
User.first
or even
User.all
I get green light too... I was expecting an error like
expected: 1 time
received: 0 times
could anyone give me a hint to understand that behaviour?
I''ve opened a question on StackOverflow too:
http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour
many thanks,
enricostn
--
? Enrico Stano
?
? twitter @enricostano
? skype ocirneonats
Hi, On 9 October 2012 13:04, enrico stano <enricostn at gmail.com> wrote:> Hi, > > surely I''m missing something... but what!? > > in my spec I''ve > > User.should_receive(:find).with("1").and_return(@user) > > and in my controller > > User.find(params[:id]) > > green light... correct... > > but if I change my controller using another method, for example first: > > User.first > > or even > > User.all > > I get green light too... I was expecting an error like > > expected: 1 time > received: 0 times > > could anyone give me a hint to understand that behaviour? >There is something wrong with your spec or your spec''s setup. Could you post a gist of the spec and the controller action? Regards, Ben> > I''ve opened a question on StackOverflow too: > > http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour > > many thanks, > > enricostn > > -- > ? Enrico Stano > ? > ? twitter @enricostano > ? skype ocirneonats > _-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20121009/1311722a/attachment.html>
Hi Ben, you could find more info browsing this Gist https://gist.github.com/3848429#file_user_controller_spec.rb I''ve added it to my StackOverflow question too. Thank you for your time! ennrico 2012/10/9 Ben Lovell <benjamin.lovell at gmail.com>:> Hi, > > On 9 October 2012 13:04, enrico stano <enricostn at gmail.com> wrote: >> >> Hi, >> >> surely I''m missing something... but what!? >> >> in my spec I''ve >> >> User.should_receive(:find).with("1").and_return(@user) >> >> and in my controller >> >> User.find(params[:id]) >> >> green light... correct... >> >> but if I change my controller using another method, for example first: >> >> User.first >> >> or even >> >> User.all >> >> I get green light too... I was expecting an error like >> >> expected: 1 time >> received: 0 times >> >> could anyone give me a hint to understand that behaviour? > > > > There is something wrong with your spec or your spec''s setup. Could you post > a gist of the spec and the controller action? > > Regards, > Ben > >> >> >> I''ve opened a question on StackOverflow too: >> >> http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour >> >> many thanks, >> >> enricostn >> >> -- >> ? Enrico Stano >> ? >> ? twitter @enricostano >> ? skype ocirneonats >> _ > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-- ? Enrico Stano ? ? twitter @enricostano ? skype ocirneonats
Hi,
I think we are on the right way on StackOverflow, #find is called twice:
http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour
now all I need is to detect which method call the two #find. I think
that the first is CanCan #authorize! and I know that the second one is
called by my UserController. But I want RSpec to tell me that in order
to check this behaviour right.
Something like (pseudo code)
User.should_receive(:find).with("1").called_by(User.authorize!)
Any hint?
thank you!
2012/10/9 enrico stano <enricostn at gmail.com>:> Hi Ben,
>
> you could find more info browsing this Gist
> https://gist.github.com/3848429#file_user_controller_spec.rb
>
> I''ve added it to my StackOverflow question too.
>
> Thank you for your time!
>
> ennrico
>
> 2012/10/9 Ben Lovell <benjamin.lovell at gmail.com>:
>> Hi,
>>
>> On 9 October 2012 13:04, enrico stano <enricostn at gmail.com>
wrote:
>>>
>>> Hi,
>>>
>>> surely I''m missing something... but what!?
>>>
>>> in my spec I''ve
>>>
>>> User.should_receive(:find).with("1").and_return(@user)
>>>
>>> and in my controller
>>>
>>> User.find(params[:id])
>>>
>>> green light... correct...
>>>
>>> but if I change my controller using another method, for example
first:
>>>
>>> User.first
>>>
>>> or even
>>>
>>> User.all
>>>
>>> I get green light too... I was expecting an error like
>>>
>>> expected: 1 time
>>> received: 0 times
>>>
>>> could anyone give me a hint to understand that behaviour?
>>
>>
>>
>> There is something wrong with your spec or your spec''s setup.
Could you post
>> a gist of the spec and the controller action?
>>
>> Regards,
>> Ben
>>
>>>
>>>
>>> I''ve opened a question on StackOverflow too:
>>>
>>>
http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour
>>>
>>> many thanks,
>>>
>>> enricostn
>>>
>>> --
>>> ? Enrico Stano
>>> ?
>>> ? twitter @enricostano
>>> ? skype ocirneonats
>>> _
>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
>
> --
> ? Enrico Stano
> ?
> ? twitter @enricostano
> ? skype ocirneonats
--
? Enrico Stano
?
? twitter @enricostano
? skype ocirneonats
On Tue, Oct 9, 2012 at 8:56 AM, enrico stano <enricostn at gmail.com> wrote:> Hi Ben, > > you could find more info browsing this Gist > https://gist.github.com/3848429#file_user_controller_spec.rb > > I''ve added it to my StackOverflow question too. > > Thank you for your time!It''s likely that cancan is calling User.find because of load_and_authorize_resource That''s likely why you see it being called twice when the stub is removed. -- Andy Lindeman http://www.andylindeman.com/
On 9 October 2012 13:56, enrico stano <enricostn at gmail.com> wrote:> Hi Ben, > > you could find more info browsing this Gist > https://gist.github.com/3848429#file_user_controller_spec.rb > > I''ve added it to my StackOverflow question too. > > Thank you for your time! > > ennrico > >CanCan is finding your user record somewhere in the stack so the expectation you have set is being met somewhere. Regards, Ben> 2012/10/9 Ben Lovell <benjamin.lovell at gmail.com>: > > Hi, > > > > On 9 October 2012 13:04, enrico stano <enricostn at gmail.com> wrote: > >> > >> Hi, > >> > >> surely I''m missing something... but what!? > >> > >> in my spec I''ve > >> > >> User.should_receive(:find).with("1").and_return(@user) > >> > >> and in my controller > >> > >> User.find(params[:id]) > >> > >> green light... correct... > >> > >> but if I change my controller using another method, for example first: > >> > >> User.first > >> > >> or even > >> > >> User.all > >> > >> I get green light too... I was expecting an error like > >> > >> expected: 1 time > >> received: 0 times > >> > >> could anyone give me a hint to understand that behaviour? > > > > > > > > There is something wrong with your spec or your spec''s setup. Could you > post > > a gist of the spec and the controller action? > > > > Regards, > > Ben > > > >> > >> > >> I''ve opened a question on StackOverflow too: > >> > >> > http://stackoverflow.com/questions/12799617/unexpected-rspec-should-receive-behaviour > >> > >> many thanks, > >> > >> enricostn > >> > >> -- > >> ? Enrico Stano > >> ? > >> ? twitter @enricostano > >> ? skype ocirneonats > >> _ > > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > ? Enrico Stano > ? > ? twitter @enricostano > ? skype ocirneonats > _______________________________________________ > 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/20121009/da1fd0e4/attachment-0001.html>
yes, it''s CanCan fault! ;)
any chance to check something like that (pseudo code) ?
User.should_receive(:find).with("1").called_by(User.authorize!)
User.should_receive(:find).with("1").called_by(controller)
just to check exactly what''s happening
thank you!
2012/10/9 Andy Lindeman <alindeman at gmail.com>:> On Tue, Oct 9, 2012 at 8:56 AM, enrico stano <enricostn at gmail.com>
wrote:
>> Hi Ben,
>>
>> you could find more info browsing this Gist
>> https://gist.github.com/3848429#file_user_controller_spec.rb
>>
>> I''ve added it to my StackOverflow question too.
>>
>> Thank you for your time!
>
> It''s likely that cancan is calling User.find because of
> load_and_authorize_resource
>
> That''s likely why you see it being called twice when the stub is
removed.
>
> --
> Andy Lindeman
> http://www.andylindeman.com/
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
--
? Enrico Stano
?
? twitter @enricostano
? skype ocirneonats
On 9 October 2012 14:46, enrico stano <enricostn at gmail.com> wrote:> yes, it''s CanCan fault! ;) > > any chance to check something like that (pseudo code) ? > > User.should_receive(:find).with("1").called_by(User.authorize!) > User.should_receive(:find).with("1").called_by(controller) > > just to check exactly what''s happening > > thank you! > >You can set the number of times an expectation should be met or the order in which they''re executed: https://www.relishapp.com/rspec/rspec-mocks/docs/message-expectations/receive-counts Regards, Ben> > 2012/10/9 Andy Lindeman <alindeman at gmail.com>: > > On Tue, Oct 9, 2012 at 8:56 AM, enrico stano <enricostn at gmail.com> > wrote: > >> Hi Ben, > >> > >> you could find more info browsing this Gist > >> https://gist.github.com/3848429#file_user_controller_spec.rb > >> > >> I''ve added it to my StackOverflow question too. > >> > >> Thank you for your time! > > > > It''s likely that cancan is calling User.find because of > > load_and_authorize_resource > > > > That''s likely why you see it being called twice when the stub is removed. > > > > -- > > Andy Lindeman > > http://www.andylindeman.com/ > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > -- > ? Enrico Stano > ? > ? twitter @enricostano > ? skype ocirneonats > _______________________________________________ > 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/20121009/3e6151e9/attachment.html>
ok, thank you very much for your time! bye, enrico On Tuesday, October 9, 2012, Ben Lovell wrote:> > On 9 October 2012 14:46, enrico stano <enricostn at gmail.com<javascript:_e({}, ''cvml'', ''enricostn at gmail.com'');> > > wrote: > >> yes, it''s CanCan fault! ;) >> >> any chance to check something like that (pseudo code) ? >> >> User.should_receive(:find).with("1").called_by(User.authorize!) >> User.should_receive(:find).with("1").called_by(controller) >> >> just to check exactly what''s happening >> >> thank you! >> >> > You can set the number of times an expectation should be met or the order > in which they''re executed: > > > https://www.relishapp.com/rspec/rspec-mocks/docs/message-expectations/receive-counts > > Regards, > Ben > > >> >> 2012/10/9 Andy Lindeman <alindeman at gmail.com <javascript:_e({}, ''cvml'', >> ''alindeman at gmail.com'');>>: >> > On Tue, Oct 9, 2012 at 8:56 AM, enrico stano <enricostn at gmail.com<javascript:_e({}, ''cvml'', ''enricostn at gmail.com'');>> >> wrote: >> >> Hi Ben, >> >> >> >> you could find more info browsing this Gist >> >> https://gist.github.com/3848429#file_user_controller_spec.rb >> >> >> >> I''ve added it to my StackOverflow question too. >> >> >> >> Thank you for your time! >> > >> > It''s likely that cancan is calling User.find because of >> > load_and_authorize_resource >> > >> > That''s likely why you see it being called twice when the stub is >> removed. >> > >> > -- >> > Andy Lindeman >> > http://www.andylindeman.com/ >> > _______________________________________________ >> > rspec-users mailing list >> > rspec-users at rubyforge.org <javascript:_e({}, ''cvml'', >> ''rspec-users at rubyforge.org'');> >> > http://rubyforge.org/mailman/listinfo/rspec-users >> >> >> >> -- >> ? Enrico Stano >> ? >> ? twitter @enricostano >> ? skype ocirneonats >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org <javascript:_e({}, ''cvml'', >> ''rspec-users at rubyforge.org'');> >> http://rubyforge.org/mailman/listinfo/rspec-users >> > >-- ? Enrico Stano ? ? twitter @enricostano ? skype ocirneonats -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20121010/b3ee9c7e/attachment.html>