Hi, A controller has a method with the following def update ... if @config.update_attributes( params[:new_config] ) redirect_to :action => :index else * render :action => :edit, :id => params[:id] # this line here* end ... end The example has the following it ''should render the "edit" config url on an unsuccessful save'' do @config.should_receive(:update_attributes).once.and_return(false) c*ontroller.expect_render( :action => :edit, :id => 1 ).once # my prob* do_update end This fails with Mock ''expect_render_mock_proxy'' expected :render with ({:action=>:edit, :id=>1}) once, but received it 0 times I have tried controller.expect_render( :action => :edit ).once Am I using #expect_render correctly? Thanks for all and any helpv Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070914/acd6d8e6/attachment.html
Hi, A controller has a method with the following def update ... if @config.update_attributes ( params[:new_config] ) redirect_to :action => :index else * render :action => :edit, :id => params[:id] # this line here* end ... end The example has the following it ''should render the "edit" config url on an unsuccessful save'' do @config.should_receive(:update_attributes).once.and_return(false) c*ontroller.expect_render( :action => :edit, :id => 1 ).once # my prob* do_update end This fails with ... Mock ''expect_render_mock_proxy'' expected :render with ({:action=>:edit, :id=>1}) once, but received it 0 times I have tried controller.expect_render( :action => :edit ).once Am I using #expect_render correctly? Thanks for all and any help! Cheers! sinclair -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070914/ab198e3f/attachment.html
Look at your test.log and you can see exactly what was rendered. That should explain why the example is failing. This works best if you can silence the logs for all examples other than the one you are testing. On Sep 14, 2007, at 7:35 PM, sinclair bain wrote:> Hi, > > > A controller has a method with the following > > > def update > ... > if @config.update_attributes ( params[:new_config] ) > redirect_to :action => :index > else > render :action => :edit, :id => params[:id] # this line > here > end > ... > end > > > The example has the following > > > it ''should render the "edit" config url on an unsuccessful save'' do > @config.should_receive(:update_attributes).once.and_return(false) > controller.expect_render ( :action => :edit, :id => > 1 ).once # my prob > do_update > end > > > This fails with > ... > Mock ''expect_render_mock_proxy'' expected :render with > ({:action=>:edit, :id=>1}) once, but received it 0 times > > > I have tried > controller.expect_render( :action => :edit ).once > > > Am I using #expect_render correctly? > > > Thanks for all and any help! > > > Cheers! > sinclair > _______________________________________________ > 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/20070914/8999f848/attachment-0001.html
On 9/15/07, s.ross <cwdinfo at gmail.com> wrote:> Look at your test.log and you can see exactly what was rendered. That should > explain why the example is failing. This works best if you can silence the > logs for all examples other than the one you are testing. >Better if you run just that example: spec spec\controllers\my_controller_spec.rb -e "My failing example name" -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi
On Fri, 2007-09-14 at 17:51 -0400, sinclair bain wrote:> > def update > ... > if @config.update_attributes ( params[:new_config] ) > redirect_to :action => :index > else > render :action => :edit, :id => params[:id] # this line > here > end > ... > end> it ''should render the "edit" config url on an unsuccessful save'' do > @config.should_receive(:update_attributes).once.and_return(false) > controller.expect_render( :action => :edit, :id => 1 ).once > # my prob > do_update > endI''m not sure what do_update is doing? I assume it is doing a post? In any case params are normally strings, so doing controller.expect_render(:action => :edit, :id => ''1'').once will most likely work. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070925/0bb90090/attachment-0001.bin
Hans that did it! Thanks for that one! Cheers! sinclair On 9/25/07, Hans de Graaff <hans at degraaff.org> wrote:> > On Fri, 2007-09-14 at 17:51 -0400, sinclair bain wrote: > > > > def update > > ... > > if @config.update_attributes ( params[:new_config] ) > > redirect_to :action => :index > > else > > render :action => :edit, :id => params[:id] # this line > > here > > end > > ... > > end > > > it ''should render the "edit" config url on an unsuccessful save'' do > > @config.should_receive(:update_attributes).once.and_return(false) > > controller.expect_render( :action => :edit, :id => 1 ).once > > # my prob > > do_update > > end > > I''m not sure what do_update is doing? I assume it is doing a post? In > any case params are normally strings, so doing > > controller.expect_render(:action => :edit, :id => ''1'').once > > will most likely work. > > Kind regards, > > Hans > > > _______________________________________________ > 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/20071001/1168e781/attachment-0001.html