[rspec-users] Problem with testing for an exception from a controller method

Max Williams toastkid.williams at gmail.com
Mon Feb 18 08:29:09 EST 2008


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 


More information about the rspec-users mailing list