Getting RESTful and wondering how to test your respond_to block in your controller to make sure its returning the right format? Drop these into your test_helper.rb.
def assert_xml assert_match 'application/xml', @response.headers['Content-Type'] end def assert_rss assert_match 'application/rss+xml', @response.headers['Content-Type'] end
Then in your functional tests, use them like this:
def test_return_xml get :index, :format => 'xml' assert_xml end def test_return_rss get :index, :format => 'rss' assert_rss end
Yay!
Popularity: 4% [?]




About
Mmm, Del.icio.us
How about a matching one for setting the Accept header simply?
You mean something like this?
That's how you'd do it for pre 1.2 stuff, but I thought the convention was moving towards using formats over accept headers.