Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: unit testing rails model validation? - why bother? what's rails best practice?
Eric Hodel
6/12/2007 8:26:00 AM
On Jun 10, 2007, at 23:16, Greg Hauptmann wrote:
> Is there any need to write unit test cases for model validation
> when such
> validation is implemented by a single rails validate_* line in the
> model?
> e.g. "validates_presence_of :email".
>
> Conservatively I would say 'yes' however applying the following
> arguments
> below I'd actually re-consider and say 'no':
>
> [1] Any test should clearly have a clear objective in terms of what
> it is
> trying to test. In this case what is really being tested in the rails
> framework "validates_" command and associated rails framework that
> handles
> this.
No. You need to assert that you have validates_presence_of :email in
your model.
> If you take this as already been tested as part of the Rails release
> process then there is no reason to focus re-testing this. In other
> words
> why write a test for a situation for which you wrote no code yourself.
You don't need to exhaustively test it, only assert the failing case.
> [2] Any DRY? - By writing test cases you are really breaking the
> DRY (don't
> repeat yourself content) by everytime you put a simple rails
> framework line
> (i.e. a validates_* in a model) you have to put extra straight-
> forward lines
> in test cases. Also would such test cases focused at testing such
> Rails
> commands already be present in the rails code base.
Your implementation shouldn't repeat itself, your tests shouldn't
repeat themselves, but if your tests repeat your implementation,
that's probably ok.
Your tests are your project's safety net. If you don't have a test
for a line of code I can come along and delete it and not know I
broke something. Broken software sucks almost as much as falling off
the high wire with a half set-up safety net.
PS: If you don't want to wait for me to delete the line of code, run
heckle. It'll delete it for you.
http://seattlerb.rubyforge.o...
--
Poor workers blame their tools. Good workers build better tools. The
best
workers get their tools to do the work for them. -- Syndicate Wars
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: unit testing rails model validation? - why bother? what's rails best practice?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password