Hi, all! I would love if someone could help me figure this out. I can''t seem to see why the following fails: Here''s the spec: it "should redirect back to the index page" do Coupon.should_receive (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) @coupon.should_receive(:save) response.should redirect_to(:action => ''index'') post ''save_coupon'',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} end (the @vars are all set up) Here''s the method: def save_coupon @coupon = Coupon.new(params[:coupon]) @coupon.save redirect_to :action => :index end Now, I''ve tried it through the browser, and it works. Any thoughts? I appreciate it. -Corey -- http://www.coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/853a4691/attachment-0001.html
On Jan 14, 2008 8:31 PM, Corey Haines <coreyhaines at gmail.com> wrote:> Hi, all! > > I would love if someone could help me figure this out. I can''t seem to see > why the following fails: > > Here''s the spec: > it "should redirect back to the index page" do > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > @coupon.should_receive(:save) > response.should redirect_to(:action => ''index'') > post > ''save_coupon'',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > end > > (the @vars are all set up) > > Here''s the method: > def save_coupon > @coupon = Coupon.new(params[:coupon]) > @coupon.save > redirect_to :action => :index > end > > Now, I''ve tried it through the browser, and it works. Any thoughts?What''s the failure message?> > I appreciate it. > -Corey > > -- > http://www.coreyhaines.com > The Internet''s Premiere source of information about Corey Haines > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Did your spec failed? Would you paste it? On Jan 14, 2008 9:32 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Jan 14, 2008 8:31 PM, Corey Haines <coreyhaines at gmail.com> wrote: > > Hi, all! > > > > I would love if someone could help me figure this out. I can''t seem to > see > > why the following fails: > > > > Here''s the spec: > > it "should redirect back to the index page" do > > Coupon.should_receive > > > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > > @coupon.should_receive(:save) > > response.should redirect_to(:action => ''index'') > > post > > ''save_coupon'',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > end > > > > (the @vars are all set up) > > > > Here''s the method: > > def save_coupon > > @coupon = Coupon.new(params[:coupon]) > > @coupon.save > > redirect_to :action => :index > > end > > > > Now, I''ve tried it through the browser, and it works. Any thoughts? > > What''s the failure message? > > > > > I appreciate it. > > -Corey > > > > -- > > http://www.coreyhaines.com > > The Internet''s Premiere source of information about Corey Haines > > _______________________________________________ > > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/c5b06926/attachment.html
On 1/14/08, Corey Haines <coreyhaines at gmail.com> wrote:> Hi, all! > > I would love if someone could help me figure this out. I can''t seem to see > why the following fails: > > Here''s the spec: > it "should redirect back to the index page" do > Coupon.should_receive > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > @coupon.should_receive(:save) > response.should redirect_to(:action => ''index'') > post > ''save_coupon'',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}}I think you need to check the response after the post, not before. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
That was it! Thanks, Rick! Sorry about not posting the failure. DOH! Thanks again, everyone! -Corey On Jan 14, 2008 9:38 PM, Rick DeNatale <rick.denatale at gmail.com> wrote:> On 1/14/08, Corey Haines <coreyhaines at gmail.com> wrote: > > Hi, all! > > > > I would love if someone could help me figure this out. I can''t seem to > see > > why the following fails: > > > > Here''s the spec: > > it "should redirect back to the index page" do > > Coupon.should_receive > > > (:new).with({"name"=>@expectedName,"amount"=>@expectedAmount}).and_return(@coupon) > > @coupon.should_receive(:save) > > response.should redirect_to(:action => ''index'') > > post > > ''save_coupon'',{:coupon=>{:name=>@expectedName,:amount=>@expectedAmount}} > > I think you need to check the response after the post, not before. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- http://www.coreyhaines.com The Internet''s Premiere source of information about Corey Haines -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080114/862db91f/attachment.html