Unit testing an HTTP client

Hi,
my programm uses the HTTPClient gem to call a backend that was
originally made for AJAX-without-the-X. Mainly it does POST without
expecting any result.

How do you test this?

Writing a http server that logs when requests don’t conform to the API
is easy. But how to hook it up with the test methods in the client? I’ve
never used threads…

Or I could override the central network communication stuff to just call
another method instead.

On Tue, May 27, 2008 at 7:59 AM, Tobias W. [email protected] wrote:

Hi,
my programm uses the HTTPClient gem to call a backend that was
originally made for AJAX-without-the-X. Mainly it does POST without
expecting any result.

How do you test this?

Hello Tobias,

I’ve been through the same routine for an http client
(http://rufus.rubyforge.org/rufus-verbs). I’ve written a test server
based on Webrick just for the unit tests :

http://github.com/jmettraux/rufus-verbs/tree/master/test/items.rb

(see the class ItemServer as a starting point).

It’s then used in the startup/teadown of my unit tests :

http://github.com/jmettraux/rufus-verbs/tree/master/test/testbase.rb

Maybe that’ll inspire you.

Webrick comes with Ruby, it’s quite handy. You don’t have to worry
about threads [for now], the server will run in its own. I’m sure
someone else will come with an even better piece of advice.

Freundliche Gruesse,

In article
[email protected],
John M. [email protected] wrote:

(http://rufus.rubyforge.org/rufus-verbs). I’ve written a test server
based on Webrick just for the unit tests :

Your server returns defined results for certain requests. Those are
processed by your client and used in assertions.

As I wrote, my client does not expect (nor can handle) results. I want
to use the request that arrives at the server in my assertions, to see
if it gets build correctly.

In article [email protected],
Phlip [email protected] wrote:

I have done it that way, and I have also used Mocha to simply make
the HTTP client magically return whatever result you want.

Works really nice. Thanks!