Mam ten kod w moim kontrolerze i chcę przetestować tę linię kodu za pomocą testu funkcjonalnego.Jak mogę przetestować ActiveRecord :: RecordNotFound w mojej aplikacji rails?
raise ActiveRecord::RecordNotFound if @post.nil?
Którą metodę należy zastosować? Używam wbudowanej ramy testowej 2.3.5.
Próbowałem z tym kodem:
test "should return 404 if page doesn't exist." do
get :show, :url => ["nothing", "here"]
assert_response :missing
end
ale to nie działa dla mnie. Mam dane wyjściowe testu:
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.'
dziękuję, lubię to! – xaver23
Lubię 'rescue_from ActiveRecord :: RecordNotFound' w moim ApplicationController (w application_controller.rb), ponieważ nie lubię bloków' assert_raises'. –