[rspec-users] Example controller spec no worky?

Brad Carson lists at ruby-forum.com
Wed Feb 13 12:46:18 EST 2008

I'm trying to spec a dead simple "show non-existent record should render
404" case, but it seems the RecordNotFound exception is making it
impossible for some reason.

def show
  @event = Event.find(params[:id])

#spec - pretty much straight from the rspec site
  before do
    get :show, :id => 'broken'

  # passes
  it "should not assign an event" do
    assigns[:event].should == nil

  # fails - expected 404 but got events/show
  it "should render 404" do
    response.should render_template("#{RAILS_ROOT}/public/404.html")
    response.response_code.should == 404
#end spec

Because I'm stubbing find does that mean the RecordNotFound exception
doesn't happen and thus the 404 doesn't render?   I tried stubbing and
using should_raise, and_raise, whatever the heck it is, but I just don't
get it, nothing seems to work.  It behaves as expected when browser
tested!  :O

I'm going to spontaneously combust!

[RSpec 1.1.2, Rails 2.0.2, ZenTest 3.8.0]
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list