14Jun/100
Testing 404/500, Error Pages with Webrat visit method
This is a super simple snippet, and maybe there is something built into webrat, but I didn't find it. I needed to test for 404 pages in some of my tests (I was writing tests that made sure a page didnt show for disabled content). Purposely getting 404's can be annoying though since webrat opens up the 404 page in your default browser. There is a variable available in Webrat's configuration that you can use to temporarily disable this functionality. I wrapped it in the following method:
1 2 3 4 5 | def visit_but_dont_open(url) Webrat.configuration.instance_variable_set("@open_error_files", false) visit url Webrat.configuration.instance_variable_set("@open_error_files", true) end |
Throw that in your test_helper and you can start doing:
1 2 | visit_but_dont_open "Http://example.com/page/that/doesnt/exist" assert !response.ok? |
Yay, 404.