Max Williams
2008-Feb-18 13:29 UTC
[rspec-users] Problem with testing for an exception from a controller method
I have a User controller where users aren''t added with the usual new/create actions. I''m trying to set it so that it raises when ''new'' is called but it doesn''t seem to be working - here''s the method, test and test result. Can anyone see why it''s not working? #in controller def new raise "Users should be added with ''batch_add'' rather than ''new" end #test describe "/new" do it "should raise an error when called" do lambda{get(''new'')}.should raise_error(RuntimeError) end end #test report ''Admin::UserController /new should raise an error when called'' FAILED expected RuntimeError but nothing was raised -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080218/73f1aad3/attachment-0001.html
Corey Haines
2008-Feb-18 13:30 UTC
[rspec-users] Problem with testing for an exception from a controller method
Won''t the exception get turned into a http return code from the get? On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> wrote:> I have a User controller where users aren''t added with the usual > new/create actions. I''m trying to set it so that it raises when ''new'' is > called but it doesn''t seem to be working - here''s the method, test and test > result. Can anyone see why it''s not working? > > #in controller > def new > raise "Users should be added with ''batch_add'' rather than ''new" > end > > #test > describe "/new" do > it "should raise an error when called" do > lambda{get(''new'')}.should raise_error(RuntimeError) > end > end > > #test report > ''Admin::UserController /new should raise an error when called'' FAILED > expected RuntimeError but nothing was raised > > > _______________________________________________ > 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/20080218/1a4b495e/attachment.html
David Chelimsky
2008-Feb-18 13:41 UTC
[rspec-users] Problem with testing for an exception from a controller method
On Feb 18, 2008 8:30 AM, Corey Haines <coreyhaines at gmail.com> wrote:> Won''t the exception get turned into a http return code from the get?It depends on a few things. Max - what versions of rspec and rails are you using?> > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> wrote: > > > > > > > > > I have a User controller where users aren''t added with the usual > new/create actions. I''m trying to set it so that it raises when ''new'' is > called but it doesn''t seem to be working - here''s the method, test and test > result. Can anyone see why it''s not working? > > > > #in controller > > def new > > raise "Users should be added with ''batch_add'' rather than ''new" > > end > > > > #test > > describe "/new" do > > it "should raise an error when called" do > > lambda{get(''new'')}.should raise_error(RuntimeError) > > end > > end > > > > #test report > > ''Admin::UserController /new should raise an error when called'' FAILED > > expected RuntimeError but nothing was raised > > > > > > _______________________________________________ > > 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Max Williams
2008-Feb-18 13:43 UTC
[rspec-users] Problem with testing for an exception from a controller method
ah yes of course :) So, now, "should_not be_success" passes ok, but should i be more specific and require a particular error code? If so, which would i get from a get call that''s failed because of a RuntimeError exception? thanks! On 18/02/2008, Corey Haines <coreyhaines at gmail.com> wrote:> > Won''t the exception get turned into a http return code from the get? > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> wrote: > > > I have a User controller where users aren''t added with the usual > > new/create actions. I''m trying to set it so that it raises when ''new'' is > > called but it doesn''t seem to be working - here''s the method, test and test > > result. Can anyone see why it''s not working? > > > > #in controller > > def new > > raise "Users should be added with ''batch_add'' rather than ''new" > > end > > > > #test > > describe "/new" do > > it "should raise an error when called" do > > lambda{get(''new'')}.should raise_error(RuntimeError) > > end > > end > > > > #test report > > ''Admin::UserController /new should raise an error when called'' FAILED > > expected RuntimeError but nothing was raised > > > > > > _______________________________________________ > > 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 > _______________________________________________ > 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/20080218/dbd3a4a2/attachment.html
David Chelimsky
2008-Feb-18 13:46 UTC
[rspec-users] Problem with testing for an exception from a controller method
On Feb 18, 2008 8:43 AM, Max Williams <toastkid.williams at gmail.com> wrote:> ah yes of course :) > > So, now, "should_not be_success" passes ok, but should i be more specific > and require a particular error code? If so, which would i get from a get > call that''s failed because of a RuntimeError exception?You should be able to discover that by specifying one (like 200) and seeing what you get. response.error_code.should == 200 Cheers, David> > thanks! > > > > On 18/02/2008, Corey Haines <coreyhaines at gmail.com> wrote: > > Won''t the exception get turned into a http return code from the get? > > > > > > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> wrote: > > > > > > > > I have a User controller where users aren''t added with the usual > new/create actions. I''m trying to set it so that it raises when ''new'' is > called but it doesn''t seem to be working - here''s the method, test and test > result. Can anyone see why it''s not working? > > > > > > #in controller > > > def new > > > raise "Users should be added with ''batch_add'' rather than ''new" > > > end > > > > > > #test > > > describe "/new" do > > > it "should raise an error when called" do > > > lambda{get(''new'')}.should raise_error(RuntimeError) > > > end > > > end > > > > > > #test report > > > ''Admin::UserController /new should raise an error when called'' FAILED > > > expected RuntimeError but nothing was raised > > > > > > > > > _______________________________________________ > > > 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 > > _______________________________________________ > > 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 >
Corey Haines
2008-Feb-18 13:46 UTC
[rspec-users] Problem with testing for an exception from a controller method
500? That''s internal server error. You could set up an expectation for the return, using a code you know isn''t right (200?), then see what the actual value is after you get the failing test. On Feb 18, 2008 8:43 AM, Max Williams <toastkid.williams at gmail.com> wrote:> ah yes of course :) > > So, now, "should_not be_success" passes ok, but should i be more specific > and require a particular error code? If so, which would i get from a get > call that''s failed because of a RuntimeError exception? > > thanks! > > > On 18/02/2008, Corey Haines <coreyhaines at gmail.com> wrote: > > > > Won''t the exception get turned into a http return code from the get? > > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> > > wrote: > > > > > I have a User controller where users aren''t added with the usual > > > new/create actions. I''m trying to set it so that it raises when ''new'' is > > > called but it doesn''t seem to be working - here''s the method, test and test > > > result. Can anyone see why it''s not working? > > > > > > #in controller > > > def new > > > raise "Users should be added with ''batch_add'' rather than ''new" > > > end > > > > > > #test > > > describe "/new" do > > > it "should raise an error when called" do > > > lambda{get(''new'')}.should raise_error(RuntimeError) > > > end > > > end > > > > > > #test report > > > ''Admin::UserController /new should raise an error when called'' FAILED > > > expected RuntimeError but nothing was raised > > > > > > > > > _______________________________________________ > > > 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 > > _______________________________________________ > > 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 >-- 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/20080218/23eea1ae/attachment.html
David Chelimsky
2008-Feb-18 13:48 UTC
[rspec-users] Problem with testing for an exception from a controller method
On Feb 18, 2008 8:46 AM, Corey Haines <coreyhaines at gmail.com> wrote:> 500? That''s internal server error. You could set up an expectation for the > return, using a code you know isn''t right (200?), then see what the actual > value is after you get the failing test.What he said :)> > > > On Feb 18, 2008 8:43 AM, Max Williams <toastkid.williams at gmail.com> wrote: > > ah yes of course :) > > > > So, now, "should_not be_success" passes ok, but should i be more specific > and require a particular error code? If so, which would i get from a get > call that''s failed because of a RuntimeError exception? > > > > thanks! > > > > > > > > > > > > On 18/02/2008, Corey Haines <coreyhaines at gmail.com> wrote: > > > Won''t the exception get turned into a http return code from the get? > > > > > > > > > > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> > wrote: > > > > > > > > > > > I have a User controller where users aren''t added with the usual > new/create actions. I''m trying to set it so that it raises when ''new'' is > called but it doesn''t seem to be working - here''s the method, test and test > result. Can anyone see why it''s not working? > > > > > > > > #in controller > > > > def new > > > > raise "Users should be added with ''batch_add'' rather than ''new" > > > > end > > > > > > > > #test > > > > describe "/new" do > > > > it "should raise an error when called" do > > > > lambda{get(''new'')}.should raise_error(RuntimeError) > > > > end > > > > end > > > > > > > > #test report > > > > ''Admin::UserController /new should raise an error when called'' FAILED > > > > expected RuntimeError but nothing was raised > > > > > > > > > > > > _______________________________________________ > > > > 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 > > > _______________________________________________ > > > 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 > > > > > > -- > 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 >
Max Williams
2008-Feb-18 13:48 UTC
[rspec-users] Problem with testing for an exception from a controller method
RAILS_GEM_VERSION = ''1.1.6'' rspec - Version 1.1.3 On 18/02/2008, David Chelimsky <dchelimsky at gmail.com> wrote:> > On Feb 18, 2008 8:30 AM, Corey Haines <coreyhaines at gmail.com> wrote: > > Won''t the exception get turned into a http return code from the get? > > It depends on a few things. > > Max - what versions of rspec and rails are you using? > > > > > > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> > wrote: > > > > > > > > > > > > > > I have a User controller where users aren''t added with the usual > > new/create actions. I''m trying to set it so that it raises when ''new'' > is > > called but it doesn''t seem to be working - here''s the method, test and > test > > result. Can anyone see why it''s not working? > > > > > > #in controller > > > def new > > > raise "Users should be added with ''batch_add'' rather than ''new" > > > end > > > > > > #test > > > describe "/new" do > > > it "should raise an error when called" do > > > lambda{get(''new'')}.should raise_error(RuntimeError) > > > end > > > end > > > > > > #test report > > > ''Admin::UserController /new should raise an error when called'' FAILED > > > expected RuntimeError but nothing was raised > > > > > > > > > _______________________________________________ > > > 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 > > _______________________________________________ > > 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/20080218/f97e3981/attachment.html
Max Williams
2008-Feb-18 13:52 UTC
[rspec-users] Problem with testing for an exception from a controller method
great minds :) thanks guys! On 18/02/2008, David Chelimsky <dchelimsky at gmail.com> wrote:> > On Feb 18, 2008 8:43 AM, Max Williams <toastkid.williams at gmail.com> wrote: > > ah yes of course :) > > > > So, now, "should_not be_success" passes ok, but should i be more > specific > > and require a particular error code? If so, which would i get from a > get > > call that''s failed because of a RuntimeError exception? > > You should be able to discover that by specifying one (like 200) and > seeing what you get. > > response.error_code.should == 200 > > Cheers, > David > > > > > thanks! > > > > > > > > On 18/02/2008, Corey Haines <coreyhaines at gmail.com> wrote: > > > Won''t the exception get turned into a http return code from the get? > > > > > > > > > > > > On Feb 18, 2008 8:29 AM, Max Williams <toastkid.williams at gmail.com> > wrote: > > > > > > > > > > > I have a User controller where users aren''t added with the usual > > new/create actions. I''m trying to set it so that it raises when ''new'' > is > > called but it doesn''t seem to be working - here''s the method, test and > test > > result. Can anyone see why it''s not working? > > > > > > > > #in controller > > > > def new > > > > raise "Users should be added with ''batch_add'' rather than ''new" > > > > end > > > > > > > > #test > > > > describe "/new" do > > > > it "should raise an error when called" do > > > > lambda{get(''new'')}.should raise_error(RuntimeError) > > > > end > > > > end > > > > > > > > #test report > > > > ''Admin::UserController /new should raise an error when called'' > FAILED > > > > expected RuntimeError but nothing was raised > > > > > > > > > > > > _______________________________________________ > > > > 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 > > > _______________________________________________ > > > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080218/caa2cb27/attachment.html