So far I’ve been manually using curl to make get and post requests
against my Rails app to see if I’m responding to XML clients
correctly.
But this is silly, I need to write unit tests. I don’t see an obvious
way to do this in Rails unit tests. I’m about to invent an
‘xml_fixtures’ helper method that will pull in some hardcoded XML
files, and then use those to make post requests and/or make sure I get
the expected XML back from the server.
But before I invest the time - is there a better way?
get(path, parameters=nil, headers=nil)
Performs a GET request with the given parameters. The parameters may
be nil, a Hash, or a string that is appropriately encoded (application/
x-www-form-urlencoded or multipart/form-data). The headers should be a
hash. The keys will automatically be upcased, with the prefix ‘HTTP_’
added if needed.
You can also perform POST, PUT, DELETE, and HEAD requests with post,
put, delete, and head.
You can use all the REST verbs from within your functional and
integration tests. You should be able to set your ACCEPTS header to
have the call return whatever format you want to test against.
This really doesn’t make sense to be available from unit tests. The
format that is returned is controlled by the controller class, not the
model, so the proper place to test this is in functional and/or
integration test.