Stephan Wehner wrote:
How can one get a hand on responses of a Rails application to arbitrary requests to perform tests?
So far I found a testing method
assert_routing
but I feel a direct test may be more robust
I'd rather look at the response directly, such as
get 'this/url/doesn't/exist' assert_equal @response.headers['Status'], '404'
get 'this!/!ur\l/doesn't/exist' assert_equal @response.headers['Status'], '404' # maybe even assert_template :controller => 'error_handler', :action => 'error_page'
You can use assert_response to check the response header after the get request as in:
get 'missing/url' assert_response :missing
or
get 'missing/url' assert_response 404
You can also check the template returned using assert_template and giving it a file system path to template file relative to the app/views directory and without the .rhtml. So if you had a template file as:
app/views/error_handler/error_page.rhtml
you could use:
assert_template 'error_handler/error_page'