【发布时间】:2010-03-22 12:51:00
【问题描述】:
我的控制器中有这段代码,想通过功能测试来测试这段代码。
raise ActiveRecord::RecordNotFound if @post.nil?
我应该使用哪种断言方法? 我使用内置的 rails 2.3.5 测试框架。
我用这段代码试了一下:
test "should return 404 if page doesn't exist." do
get :show, :url => ["nothing", "here"]
assert_response :missing
end
但这对我不起作用。得到这个测试输出:
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.'
【问题讨论】:
标签: ruby-on-rails ruby testing activerecord