PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Re: Unit testing an HTTP client
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: Unit testing an HTTP client

Réponse
 
LinkBack Outils de la discussion
Vieux 27/05/2008, 00h23   #1
John Mettraux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unit testing an HTTP client

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/rufus-verbs). I've written a test server
based on Webrick just for the unit tests :

http://github.com/jmettraux/rufus-ve.../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-ve...st/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,

--
John Mettraux - http://jmettraux.wordpress.com

  Réponse avec citation
Vieux 27/05/2008, 04h40   #2
Phlip
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Unit testing an HTTP client

> 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-ve.../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-ve...st/testbase.rb
>
> 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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08025 seconds with 10 queries