Matthijs Langenberg
2007-Apr-11 19:03 UTC
[rspec-users] redirection doesn''t get detected well?
I''m doing a redirect in one of my controller actions and somehow I can''t spec it, see this pastie: http://pastie.caboo.se/53120. When following the link from a browser I''m being redirected to the right page. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070411/e6786c86/attachment.html
David Chelimsky
2007-Apr-11 19:29 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote:> I''m doing a redirect in one of my controller actions and somehow I can''t > spec it, see this pastie: http://pastie.caboo.se/53120. > When following the link from a browser I''m being redirected to the right > page.First of all - nice example! Secondly, this looks like it should work. What''s actually in the response? ... it "should destroy order_product with order_id==3 and product_id==6 and redirect to /orders/3." do @order_product.should_receive(:destroy) delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 puts response.inspect response.should be_redirect end ...> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Matthijs Langenberg
2007-Apr-11 21:58 UTC
[rspec-users] redirection doesn''t get detected well?
Thanks for the hint David, when I looked at response.body I saw the following HTML passing by: <pre>OrderProduct expected :find with (:first, {:conditions=> {:order_id=>3, :product_id=>6}}) but received it with (:first, {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> Which makes totally sense since params["order_id"] and params["product_id"] indeed are String objects instead of Fixnum objects, however, shouldn''t this expectation error raise earlier and make that expectation fail instead of the response.should be_redirect expectation? On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > I''m doing a redirect in one of my controller actions and somehow I can''t > > spec it, see this pastie: http://pastie.caboo.se/53120. > > When following the link from a browser I''m being redirected to the right > > page. > > First of all - nice example! > > Secondly, this looks like it should work. What''s actually in the response? > > ... > it "should destroy order_product with order_id==3 and product_id==6 > and redirect to /orders/3." do > @order_product.should_receive(:destroy) > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > puts response.inspect > response.should be_redirect > end > ... > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
I ran into a similar issue due to the same issue and blogged about it here: http://blog.railsconsulting.com/2007/3/27/mocking-restful-routes I was going to originally respond to you and suggest that but since the first test didn''t fail it threw me once again. Michael On Apr 11, 2007, at 5:58 PM, Matthijs Langenberg wrote:> Thanks for the hint David, when I looked at response.body I saw the > following HTML passing by: > > <pre>OrderProduct expected :find with (:first, {:conditions=> > {:order_id=>3, :product_id=>6}}) but received it with (:first, > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > Which makes totally sense since params["order_id"] and > params["product_id"] indeed are String objects instead of Fixnum > objects, however, shouldn''t this expectation error raise earlier and > make that expectation fail instead of the response.should be_redirect > expectation? > > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: >> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>> I''m doing a redirect in one of my controller actions and somehow >>> I can''t >>> spec it, see this pastie: http://pastie.caboo.se/53120. >>> When following the link from a browser I''m being redirected to >>> the right >>> page. >> >> First of all - nice example! >> >> Secondly, this looks like it should work. What''s actually in the >> response? >> >> ... >> it "should destroy order_product with order_id==3 and product_id==6 >> and redirect to /orders/3." do >> @order_product.should_receive(:destroy) >> delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 >> puts response.inspect >> response.should be_redirect >> end >> ... >> >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
aslak hellesoy
2007-Apr-11 22:16 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote:> Thanks for the hint David, when I looked at response.body I saw the > following HTML passing by: > > <pre>OrderProduct expected :find with (:first, {:conditions=> > {:order_id=>3, :product_id=>6}}) but received it with (:first, > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > Which makes totally sense since params["order_id"] and > params["product_id"] indeed are String objects instead of Fixnum > objects, however, shouldn''t this expectation error raise earlier and > make that expectation fail instead of the response.should be_redirect > expectation?RSpec doesn''t invoke actions directly - it invokes them via Rails. Rails catches any exceptions that happen in a controller action and prints the backtrace to the response. Would it make sense if we found a way to at least let mock errors ripple through and back to RSpec? Aslak> > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > I''m doing a redirect in one of my controller actions and somehow I can''t > > > spec it, see this pastie: http://pastie.caboo.se/53120. > > > When following the link from a browser I''m being redirected to the right > > > page. > > > > First of all - nice example! > > > > Secondly, this looks like it should work. What''s actually in the response? > > > > ... > > it "should destroy order_product with order_id==3 and product_id==6 > > and redirect to /orders/3." do > > @order_product.should_receive(:destroy) > > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > > puts response.inspect > > response.should be_redirect > > end > > ... > > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2007-Apr-11 22:19 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > Thanks for the hint David, when I looked at response.body I saw the > > following HTML passing by: > > > > <pre>OrderProduct expected :find with (:first, {:conditions=> > > {:order_id=>3, :product_id=>6}}) but received it with (:first, > > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > > > Which makes totally sense since params["order_id"] and > > params["product_id"] indeed are String objects instead of Fixnum > > objects, however, shouldn''t this expectation error raise earlier and > > make that expectation fail instead of the response.should be_redirect > > expectation? > > RSpec doesn''t invoke actions directly - it invokes them via Rails. > Rails catches any exceptions that happen in a controller action and > prints the backtrace to the response. > > Would it make sense if we found a way to at least let mock errors > ripple through and back to RSpec?You mean monkey patch Rails to not catch mock failures? That sounds scary.> > Aslak > > > > > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > I''m doing a redirect in one of my controller actions and somehow I can''t > > > > spec it, see this pastie: http://pastie.caboo.se/53120. > > > > When following the link from a browser I''m being redirected to the right > > > > page. > > > > > > First of all - nice example! > > > > > > Secondly, this looks like it should work. What''s actually in the response? > > > > > > ... > > > it "should destroy order_product with order_id==3 and product_id==6 > > > and redirect to /orders/3." do > > > @order_product.should_receive(:destroy) > > > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > > > puts response.inspect > > > response.should be_redirect > > > end > > > ... > > > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Matthijs Langenberg
2007-Apr-11 22:26 UTC
[rspec-users] redirection doesn''t get detected well?
I think that''s the only way and it is quit simple: OrderProductsController.class_eval do def rescue_action(e) raise e end; end 1) Spec::Mocks::MockExpectationError in ''DELETE on /order_products?order_id=3&product_id=6 should destroy order_product with order_id==3 and product_id==6 and redirect to /orders/3.'' OrderProduct expected :find with (:first, {:conditions=>{:order_id=>3, :product_id=>"6"}}) but received it with (:first, {:conditions=>{:order_id=>"3", :product_id=>"6"}}) /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/order_products_controller.rb:3:in `destroy'' ./spec/controllers/order_products_controller_spec.rb:17: Finished in 0.055156 seconds 1 example, 1 failure Now I wouldn''t mind if the controller_name method does this type of monkeypatching, it saves me a lot of debugging. On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > Thanks for the hint David, when I looked at response.body I saw the > > > following HTML passing by: > > > > > > <pre>OrderProduct expected :find with (:first, {:conditions=> > > > {:order_id=>3, :product_id=>6}}) but received it with (:first, > > > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > > > > > Which makes totally sense since params["order_id"] and > > > params["product_id"] indeed are String objects instead of Fixnum > > > objects, however, shouldn''t this expectation error raise earlier and > > > make that expectation fail instead of the response.should be_redirect > > > expectation? > > > > RSpec doesn''t invoke actions directly - it invokes them via Rails. > > Rails catches any exceptions that happen in a controller action and > > prints the backtrace to the response. > > > > Would it make sense if we found a way to at least let mock errors > > ripple through and back to RSpec? > > You mean monkey patch Rails to not catch mock failures? That sounds scary. > > > > > Aslak > > > > > > > > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > > I''m doing a redirect in one of my controller actions and somehow I can''t > > > > > spec it, see this pastie: http://pastie.caboo.se/53120. > > > > > When following the link from a browser I''m being redirected to the right > > > > > page. > > > > > > > > First of all - nice example! > > > > > > > > Secondly, this looks like it should work. What''s actually in the response? > > > > > > > > ... > > > > it "should destroy order_product with order_id==3 and product_id==6 > > > > and redirect to /orders/3." do > > > > @order_product.should_receive(:destroy) > > > > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > > > > puts response.inspect > > > > response.should be_redirect > > > > end > > > > ... > > > > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2007-Apr-11 22:34 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote:> I think that''s the only way and it is quit simple: > > OrderProductsController.class_eval do > def rescue_action(e) raise e end; > end > > 1) > Spec::Mocks::MockExpectationError in ''DELETE on > /order_products?order_id=3&product_id=6 should destroy order_product > with order_id==3 and product_id==6 and redirect to /orders/3.'' > OrderProduct expected :find with (:first, {:conditions=>{:order_id=>3, > :product_id=>"6"}}) but received it with (:first, > {:conditions=>{:order_id=>"3", :product_id=>"6"}}) > /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/order_products_controller.rb:3:in > `destroy'' > ./spec/controllers/order_products_controller_spec.rb:17: > > Finished in 0.055156 seconds > > 1 example, 1 failure > > Now I wouldn''t mind if the controller_name method does this type of > monkeypatching, it saves me a lot of debugging.Interestingly enough, we had that in there and it was recently removed: http://rubyforge.org/tracker/?func=detail&group_id=797&aid=9767&atid=3149 We could make that configurable, but I certainly don''t want to simply add it back in. WDYT?> > On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > Thanks for the hint David, when I looked at response.body I saw the > > > > following HTML passing by: > > > > > > > > <pre>OrderProduct expected :find with (:first, {:conditions=> > > > > {:order_id=>3, :product_id=>6}}) but received it with (:first, > > > > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > > > > > > > Which makes totally sense since params["order_id"] and > > > > params["product_id"] indeed are String objects instead of Fixnum > > > > objects, however, shouldn''t this expectation error raise earlier and > > > > make that expectation fail instead of the response.should be_redirect > > > > expectation? > > > > > > RSpec doesn''t invoke actions directly - it invokes them via Rails. > > > Rails catches any exceptions that happen in a controller action and > > > prints the backtrace to the response. > > > > > > Would it make sense if we found a way to at least let mock errors > > > ripple through and back to RSpec? > > > > You mean monkey patch Rails to not catch mock failures? That sounds scary. > > > > > > > > Aslak > > > > > > > > > > > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > > > I''m doing a redirect in one of my controller actions and somehow I can''t > > > > > > spec it, see this pastie: http://pastie.caboo.se/53120. > > > > > > When following the link from a browser I''m being redirected to the right > > > > > > page. > > > > > > > > > > First of all - nice example! > > > > > > > > > > Secondly, this looks like it should work. What''s actually in the response? > > > > > > > > > > ... > > > > > it "should destroy order_product with order_id==3 and product_id==6 > > > > > and redirect to /orders/3." do > > > > > @order_product.should_receive(:destroy) > > > > > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > > > > > puts response.inspect > > > > > response.should be_redirect > > > > > end > > > > > ... > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Isn''t that how Test::Unit handles a similar situation? I think if we just know to add it if needed that should be enough. Or at least make it configurable. I agree that we probably don''t want that magic happening without being aware of it. Michael On Apr 11, 2007, at 6:34 PM, David Chelimsky wrote:> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >> I think that''s the only way and it is quit simple: >> >> OrderProductsController.class_eval do >> def rescue_action(e) raise e end; >> end >> >> 1) >> Spec::Mocks::MockExpectationError in ''DELETE on >> /order_products?order_id=3&product_id=6 should destroy order_product >> with order_id==3 and product_id==6 and redirect to /orders/3.'' >> OrderProduct expected :find with (:first, {:conditions=> >> {:order_id=>3, >> :product_id=>"6"}}) but received it with (:first, >> {:conditions=>{:order_id=>"3", :product_id=>"6"}}) >> /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/ >> order_products_controller.rb:3:in >> `destroy'' >> ./spec/controllers/order_products_controller_spec.rb:17: >> >> Finished in 0.055156 seconds >> >> 1 example, 1 failure >> >> Now I wouldn''t mind if the controller_name method does this type of >> monkeypatching, it saves me a lot of debugging. > > Interestingly enough, we had that in there and it was recently > removed: > > http://rubyforge.org/tracker/? > func=detail&group_id=797&aid=9767&atid=3149 > > We could make that configurable, but I certainly don''t want to simply > add it back in. WDYT? > >> >> On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>> On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: >>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>>>> Thanks for the hint David, when I looked at response.body I saw >>>>> the >>>>> following HTML passing by: >>>>> >>>>> <pre>OrderProduct expected :find with (:first, {:conditions=> >>>>> {:order_id=>3, :product_id=>6}}) but received it with (:first, >>>>> {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> >>>>> >>>>> Which makes totally sense since params["order_id"] and >>>>> params["product_id"] indeed are String objects instead of Fixnum >>>>> objects, however, shouldn''t this expectation error raise >>>>> earlier and >>>>> make that expectation fail instead of the response.should >>>>> be_redirect >>>>> expectation? >>>> >>>> RSpec doesn''t invoke actions directly - it invokes them via Rails. >>>> Rails catches any exceptions that happen in a controller action and >>>> prints the backtrace to the response. >>>> >>>> Would it make sense if we found a way to at least let mock errors >>>> ripple through and back to RSpec? >>> >>> You mean monkey patch Rails to not catch mock failures? That >>> sounds scary. >>> >>>> >>>> Aslak >>>> >>>>> >>>>> On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>>>>>> I''m doing a redirect in one of my controller actions and >>>>>>> somehow I can''t >>>>>>> spec it, see this pastie: http://pastie.caboo.se/53120. >>>>>>> When following the link from a browser I''m being redirected >>>>>>> to the right >>>>>>> page. >>>>>> >>>>>> First of all - nice example! >>>>>> >>>>>> Secondly, this looks like it should work. What''s actually in >>>>>> the response? >>>>>> >>>>>> ... >>>>>> it "should destroy order_product with order_id==3 and >>>>>> product_id==6 >>>>>> and redirect to /orders/3." do >>>>>> @order_product.should_receive(:destroy) >>>>>> delete ''destroy'', :id => ''nil'', :order_id => >>>>>> 3, :product_id => 6 >>>>>> puts response.inspect >>>>>> response.should be_redirect >>>>>> end >>>>>> ... >>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Matthijs Langenberg
2007-Apr-11 23:13 UTC
[rspec-users] redirection doesn''t get detected well?
That''s indeed just how Test::Unit is handeling this situation. I think that there are two options for this problem, the first is to enhance the rspec_controller generator to add the class eval code in the controller_spec.rb file, just like rails with Test::Unit does. While writing your specs, you see that the method is being monkey patched and if it gets in your way, you remove it yourself and know that rails errors do not raise. The second one requires some more work, but can be a smarter solution: we check if the method is already defined in the controller, if it isn''t we can "safely" monkeypatch it. When it is already defined, we don''t monkeypatch the controller, but do print a warning about not being able to catch exceptions raised by the action. On 4/12/07, Michael Trier <mtrier at eminentconsultinggroup.com> wrote:> Isn''t that how Test::Unit handles a similar situation? I think if we > just know to add it if needed that should be enough. Or at least > make it configurable. I agree that we probably don''t want that magic > happening without being aware of it. > > Michael > > On Apr 11, 2007, at 6:34 PM, David Chelimsky wrote: > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >> I think that''s the only way and it is quit simple: > >> > >> OrderProductsController.class_eval do > >> def rescue_action(e) raise e end; > >> end > >> > >> 1) > >> Spec::Mocks::MockExpectationError in ''DELETE on > >> /order_products?order_id=3&product_id=6 should destroy order_product > >> with order_id==3 and product_id==6 and redirect to /orders/3.'' > >> OrderProduct expected :find with (:first, {:conditions=> > >> {:order_id=>3, > >> :product_id=>"6"}}) but received it with (:first, > >> {:conditions=>{:order_id=>"3", :product_id=>"6"}}) > >> /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/ > >> order_products_controller.rb:3:in > >> `destroy'' > >> ./spec/controllers/order_products_controller_spec.rb:17: > >> > >> Finished in 0.055156 seconds > >> > >> 1 example, 1 failure > >> > >> Now I wouldn''t mind if the controller_name method does this type of > >> monkeypatching, it saves me a lot of debugging. > > > > Interestingly enough, we had that in there and it was recently > > removed: > > > > http://rubyforge.org/tracker/? > > func=detail&group_id=797&aid=9767&atid=3149 > > > > We could make that configurable, but I certainly don''t want to simply > > add it back in. WDYT? > > > >> > >> On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>> On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > >>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >>>>> Thanks for the hint David, when I looked at response.body I saw > >>>>> the > >>>>> following HTML passing by: > >>>>> > >>>>> <pre>OrderProduct expected :find with (:first, {:conditions=> > >>>>> {:order_id=>3, :product_id=>6}}) but received it with (:first, > >>>>> {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > >>>>> > >>>>> Which makes totally sense since params["order_id"] and > >>>>> params["product_id"] indeed are String objects instead of Fixnum > >>>>> objects, however, shouldn''t this expectation error raise > >>>>> earlier and > >>>>> make that expectation fail instead of the response.should > >>>>> be_redirect > >>>>> expectation? > >>>> > >>>> RSpec doesn''t invoke actions directly - it invokes them via Rails. > >>>> Rails catches any exceptions that happen in a controller action and > >>>> prints the backtrace to the response. > >>>> > >>>> Would it make sense if we found a way to at least let mock errors > >>>> ripple through and back to RSpec? > >>> > >>> You mean monkey patch Rails to not catch mock failures? That > >>> sounds scary. > >>> > >>>> > >>>> Aslak > >>>> > >>>>> > >>>>> On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >>>>>>> I''m doing a redirect in one of my controller actions and > >>>>>>> somehow I can''t > >>>>>>> spec it, see this pastie: http://pastie.caboo.se/53120. > >>>>>>> When following the link from a browser I''m being redirected > >>>>>>> to the right > >>>>>>> page. > >>>>>> > >>>>>> First of all - nice example! > >>>>>> > >>>>>> Secondly, this looks like it should work. What''s actually in > >>>>>> the response? > >>>>>> > >>>>>> ... > >>>>>> it "should destroy order_product with order_id==3 and > >>>>>> product_id==6 > >>>>>> and redirect to /orders/3." do > >>>>>> @order_product.should_receive(:destroy) > >>>>>> delete ''destroy'', :id => ''nil'', :order_id => > >>>>>> 3, :product_id => 6 > >>>>>> puts response.inspect > >>>>>> response.should be_redirect > >>>>>> end > >>>>>> ... > >>>>>> > >>>>>>> > >>>>>>> _______________________________________________ > >>>>>>> rspec-users mailing list > >>>>>>> rspec-users at rubyforge.org > >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>>> > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-users at rubyforge.org > >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
aslak hellesoy
2007-Apr-11 23:44 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > I think that''s the only way and it is quit simple: > > > > OrderProductsController.class_eval do > > def rescue_action(e) raise e end; > > end > > > > 1) > > Spec::Mocks::MockExpectationError in ''DELETE on > > /order_products?order_id=3&product_id=6 should destroy order_product > > with order_id==3 and product_id==6 and redirect to /orders/3.'' > > OrderProduct expected :find with (:first, {:conditions=>{:order_id=>3, > > :product_id=>"6"}}) but received it with (:first, > > {:conditions=>{:order_id=>"3", :product_id=>"6"}}) > > /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/order_products_controller.rb:3:in > > `destroy'' > > ./spec/controllers/order_products_controller_spec.rb:17: > > > > Finished in 0.055156 seconds > > > > 1 example, 1 failure > > > > Now I wouldn''t mind if the controller_name method does this type of > > monkeypatching, it saves me a lot of debugging. > > Interestingly enough, we had that in there and it was recently removed: > > http://rubyforge.org/tracker/?func=detail&group_id=797&aid=9767&atid=3149 > > We could make that configurable, but I certainly don''t want to simply > add it back in. WDYT? >I''m working on adding it back in - this time a little smarter. It will only reraise the exception if it is a mock exception, otherwise it will be handled by Rails. Makes sense? Aslak> > > > On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > > Thanks for the hint David, when I looked at response.body I saw the > > > > > following HTML passing by: > > > > > > > > > > <pre>OrderProduct expected :find with (:first, {:conditions=> > > > > > {:order_id=>3, :product_id=>6}}) but received it with (:first, > > > > > {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > > > > > > > > > > Which makes totally sense since params["order_id"] and > > > > > params["product_id"] indeed are String objects instead of Fixnum > > > > > objects, however, shouldn''t this expectation error raise earlier and > > > > > make that expectation fail instead of the response.should be_redirect > > > > > expectation? > > > > > > > > RSpec doesn''t invoke actions directly - it invokes them via Rails. > > > > Rails catches any exceptions that happen in a controller action and > > > > prints the backtrace to the response. > > > > > > > > Would it make sense if we found a way to at least let mock errors > > > > ripple through and back to RSpec? > > > > > > You mean monkey patch Rails to not catch mock failures? That sounds scary. > > > > > > > > > > > Aslak > > > > > > > > > > > > > > On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > > > On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > > > > > > > I''m doing a redirect in one of my controller actions and somehow I can''t > > > > > > > spec it, see this pastie: http://pastie.caboo.se/53120. > > > > > > > When following the link from a browser I''m being redirected to the right > > > > > > > page. > > > > > > > > > > > > First of all - nice example! > > > > > > > > > > > > Secondly, this looks like it should work. What''s actually in the response? > > > > > > > > > > > > ... > > > > > > it "should destroy order_product with order_id==3 and product_id==6 > > > > > > and redirect to /orders/3." do > > > > > > @order_product.should_receive(:destroy) > > > > > > delete ''destroy'', :id => ''nil'', :order_id => 3, :product_id => 6 > > > > > > puts response.inspect > > > > > > response.should be_redirect > > > > > > end > > > > > > ... > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > > rspec-users mailing list > > > > > > > rspec-users at rubyforge.org > > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > > > _______________________________________________ > > > > > > rspec-users mailing list > > > > > > rspec-users at rubyforge.org > > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Apr 11, 2007, at 7:44 PM, aslak hellesoy wrote:> On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: >> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>> I think that''s the only way and it is quit simple: >>> >>> OrderProductsController.class_eval do >>> def rescue_action(e) raise e end; >>> end >>> >>> 1) >>> Spec::Mocks::MockExpectationError in ''DELETE on >>> /order_products?order_id=3&product_id=6 should destroy order_product >>> with order_id==3 and product_id==6 and redirect to /orders/3.'' >>> OrderProduct expected :find with (:first, {:conditions=> >>> {:order_id=>3, >>> :product_id=>"6"}}) but received it with (:first, >>> {:conditions=>{:order_id=>"3", :product_id=>"6"}}) >>> /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/ >>> order_products_controller.rb:3:in >>> `destroy'' >>> ./spec/controllers/order_products_controller_spec.rb:17: >>> >>> Finished in 0.055156 seconds >>> >>> 1 example, 1 failure >>> >>> Now I wouldn''t mind if the controller_name method does this type of >>> monkeypatching, it saves me a lot of debugging. >> >> Interestingly enough, we had that in there and it was recently >> removed: >> >> http://rubyforge.org/tracker/? >> func=detail&group_id=797&aid=9767&atid=3149 >> >> We could make that configurable, but I certainly don''t want to simply >> add it back in. WDYT? >> > > I''m working on adding it back in - this time a little smarter. It will > only reraise the exception if it is a mock exception, otherwise it > will be handled by Rails. > > Makes sense?Sounds good. Thanks aslak. This will help out a lot. Michael>>> >>> On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>>> On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: >>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>>>>> Thanks for the hint David, when I looked at response.body I >>>>>> saw the >>>>>> following HTML passing by: >>>>>> >>>>>> <pre>OrderProduct expected :find with (:first, {:conditions=> >>>>>> {:order_id=>3, :product_id=>6}}) but received it with (:first, >>>>>> {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> >>>>>> >>>>>> Which makes totally sense since params["order_id"] and >>>>>> params["product_id"] indeed are String objects instead of Fixnum >>>>>> objects, however, shouldn''t this expectation error raise >>>>>> earlier and >>>>>> make that expectation fail instead of the response.should >>>>>> be_redirect >>>>>> expectation? >>>>> >>>>> RSpec doesn''t invoke actions directly - it invokes them via Rails. >>>>> Rails catches any exceptions that happen in a controller action >>>>> and >>>>> prints the backtrace to the response. >>>>> >>>>> Would it make sense if we found a way to at least let mock errors >>>>> ripple through and back to RSpec? >>>> >>>> You mean monkey patch Rails to not catch mock failures? That >>>> sounds scary. >>>> >>>>> >>>>> Aslak >>>>> >>>>>> >>>>>> On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>>>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: >>>>>>>> I''m doing a redirect in one of my controller actions and >>>>>>>> somehow I can''t >>>>>>>> spec it, see this pastie: http://pastie.caboo.se/53120. >>>>>>>> When following the link from a browser I''m being redirected >>>>>>>> to the right >>>>>>>> page. >>>>>>> >>>>>>> First of all - nice example! >>>>>>> >>>>>>> Secondly, this looks like it should work. What''s actually in >>>>>>> the response? >>>>>>> >>>>>>> ... >>>>>>> it "should destroy order_product with order_id==3 and >>>>>>> product_id==6 >>>>>>> and redirect to /orders/3." do >>>>>>> @order_product.should_receive(:destroy) >>>>>>> delete ''destroy'', :id => ''nil'', :order_id => >>>>>>> 3, :product_id => 6 >>>>>>> puts response.inspect >>>>>>> response.should be_redirect >>>>>>> end >>>>>>> ... >>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> rspec-users mailing list >>>>>>>> rspec-users at rubyforge.org >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>>> >>>>>>> _______________________________________________ >>>>>>> rspec-users mailing list >>>>>>> rspec-users at rubyforge.org >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>>> >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
aslak hellesoy
2007-Apr-12 00:13 UTC
[rspec-users] redirection doesn''t get detected well?
On 4/12/07, Michael Trier <mtrier at eminentconsultinggroup.com> wrote:> On Apr 11, 2007, at 7:44 PM, aslak hellesoy wrote: > > > On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >>> I think that''s the only way and it is quit simple: > >>> > >>> OrderProductsController.class_eval do > >>> def rescue_action(e) raise e end; > >>> end > >>> > >>> 1) > >>> Spec::Mocks::MockExpectationError in ''DELETE on > >>> /order_products?order_id=3&product_id=6 should destroy order_product > >>> with order_id==3 and product_id==6 and redirect to /orders/3.'' > >>> OrderProduct expected :find with (:first, {:conditions=> > >>> {:order_id=>3, > >>> :product_id=>"6"}}) but received it with (:first, > >>> {:conditions=>{:order_id=>"3", :product_id=>"6"}}) > >>> /Users/mlangenberg/Documents/rails/pos/config/../app/controllers/ > >>> order_products_controller.rb:3:in > >>> `destroy'' > >>> ./spec/controllers/order_products_controller_spec.rb:17: > >>> > >>> Finished in 0.055156 seconds > >>> > >>> 1 example, 1 failure > >>> > >>> Now I wouldn''t mind if the controller_name method does this type of > >>> monkeypatching, it saves me a lot of debugging. > >> > >> Interestingly enough, we had that in there and it was recently > >> removed: > >> > >> http://rubyforge.org/tracker/? > >> func=detail&group_id=797&aid=9767&atid=3149 > >> > >> We could make that configurable, but I certainly don''t want to simply > >> add it back in. WDYT? > >> > > > > I''m working on adding it back in - this time a little smarter. It will > > only reraise the exception if it is a mock exception, otherwise it > > will be handled by Rails. > > > > Makes sense? > > Sounds good. Thanks aslak. This will help out a lot. >Ok, it''s on the trunk. That should get rid of those red(irection) herrings! Aslak> Michael > > >>> > >>> On 4/12/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>>> On 4/11/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote: > >>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >>>>>> Thanks for the hint David, when I looked at response.body I > >>>>>> saw the > >>>>>> following HTML passing by: > >>>>>> > >>>>>> <pre>OrderProduct expected :find with (:first, {:conditions=> > >>>>>> {:order_id=>3, :product_id=>6}}) but received it with (:first, > >>>>>> {:conditions=>{:order_id=>"3", :product_id=>"6"}})</pre> > >>>>>> > >>>>>> Which makes totally sense since params["order_id"] and > >>>>>> params["product_id"] indeed are String objects instead of Fixnum > >>>>>> objects, however, shouldn''t this expectation error raise > >>>>>> earlier and > >>>>>> make that expectation fail instead of the response.should > >>>>>> be_redirect > >>>>>> expectation? > >>>>> > >>>>> RSpec doesn''t invoke actions directly - it invokes them via Rails. > >>>>> Rails catches any exceptions that happen in a controller action > >>>>> and > >>>>> prints the backtrace to the response. > >>>>> > >>>>> Would it make sense if we found a way to at least let mock errors > >>>>> ripple through and back to RSpec? > >>>> > >>>> You mean monkey patch Rails to not catch mock failures? That > >>>> sounds scary. > >>>> > >>>>> > >>>>> Aslak > >>>>> > >>>>>> > >>>>>> On 4/11/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>>>>>> On 4/11/07, Matthijs Langenberg <mlangenberg at gmail.com> wrote: > >>>>>>>> I''m doing a redirect in one of my controller actions and > >>>>>>>> somehow I can''t > >>>>>>>> spec it, see this pastie: http://pastie.caboo.se/53120. > >>>>>>>> When following the link from a browser I''m being redirected > >>>>>>>> to the right > >>>>>>>> page. > >>>>>>> > >>>>>>> First of all - nice example! > >>>>>>> > >>>>>>> Secondly, this looks like it should work. What''s actually in > >>>>>>> the response? > >>>>>>> > >>>>>>> ... > >>>>>>> it "should destroy order_product with order_id==3 and > >>>>>>> product_id==6 > >>>>>>> and redirect to /orders/3." do > >>>>>>> @order_product.should_receive(:destroy) > >>>>>>> delete ''destroy'', :id => ''nil'', :order_id => > >>>>>>> 3, :product_id => 6 > >>>>>>> puts response.inspect > >>>>>>> response.should be_redirect > >>>>>>> end > >>>>>>> ... > >>>>>>> > >>>>>>>> > >>>>>>>> _______________________________________________ > >>>>>>>> rspec-users mailing list > >>>>>>>> rspec-users at rubyforge.org > >>>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>>>> > >>>>>>> _______________________________________________ > >>>>>>> rspec-users mailing list > >>>>>>> rspec-users at rubyforge.org > >>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>>> > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-users at rubyforge.org > >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >