Unit testing an HTTP client

T

Tobias Weber

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.
 
J

John Mettraux

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,
 
T

Tobias Weber

John Mettraux said:
(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.
 
T

Tobias Weber

Phlip said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top