How can I test ActiveRecord::RecordNotFound in my rails app?

Posted by fursie on Stack Overflow See other posts from Stack Overflow or by fursie
Published on 2010-03-22T12:51:00Z Indexed on 2010/03/22 13:11 UTC
Read the original article Hit count: 337

Hi,

I have this code in my controller and want to test this code line with a functional test.

raise ActiveRecord::RecordNotFound if @post.nil?

which assert method should I use? I use the built-in rails 2.3.5 test framework.

I tried it with this code:

  test "should return 404 if page doesn't exist." do
    get :show, :url => ["nothing", "here"]
    assert_response :missing
  end

but it doesn't work for me. Got this test output:

test_should_return_404_if_page_doesn't_exist.(PageControllerTest):
ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound
app/controllers/page_controller.rb:7:in `show'
/test/functional/page_controller_test.rb:21:in `test_should_return_404_if_page_doesn't_exist.'

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about ruby-on-rails