[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Unit testing an HTTP client

Tobias Weber

5/26/2008 11:00:00 PM

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.

--
Tobias Weber
4 Answers

John Mettraux

5/26/2008 11:23:00 PM

0

On Tue, May 27, 2008 at 7:59 AM, Tobias Weber <towb@gmx.net> 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/r...). I've written a test server
based on Webrick just for the unit tests :

http://github.com/jmettraux/rufus-verbs/tree/master/tes...

(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/t...

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,

--
John Mettraux - http://jmettraux.wor...

Phlip

5/27/2008 3:41:00 AM

0

> I've been through the same routine for an http client
> (http://rufus.rubyforge.org/r...). I've written a test server
> based on Webrick just for the unit tests :
>
> http://github.com/jmettraux/rufus-verbs/tree/master/tes...
>
> (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/t...
>
> Maybe that'll inspire you.

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

I have to recommend Mocha over mocking a server over a wire - no
matter how short that wire may be! You are not inventing a web
application stack yourself, so you just need a mock that lets you
focus on cleaning and refactoring your own code.

Tobias Weber

5/27/2008 7:59:00 PM

0

In article
<983752850805261623s5b91b589n709f86102e939dbf@mail.gmail.com>,
John Mettraux <jmettraux@openwfe.org> wrote:

> (http://rufus.rubyforge.org/r...). 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.

--
Tobias Weber

Tobias Weber

5/27/2008 9:17:00 PM

0

In article <483b82c6$0$5141$4c368faf@roadrunner.com>,
Phlip <phlip2005@gmail.com> 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!

--
Tobias Weber