Forum: Ruby on Rails How do you test your REST API with XML?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2007-04-16 18:17
(Received via mailing list)
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

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?

21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-04-16 18:42
(Received via mailing list)
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.
94c40fd67ffecc80b479aa9d7df3c494?d=identicon&s=25 Jonathan del Strother (Guest)
on 2007-04-16 18:42
(Received via mailing list)
You can do it with integration tests, but I agree that there ought to
be a lower-level approach
21f7ed21f11a809050594c82eab11d67?d=identicon&s=25 Robert Walker (Guest)
on 2007-04-16 18:46
(Received via mailing list)
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.

On Apr 16, 12:40 pm, Jonathan del Strother <>
This topic is locked and can not be replied to.