Justin W. Reagor on 18 Sep 2007 03:42:06 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PhillyOnRails] rspec slides

  • From: "Justin W. Reagor" <justinwr@gmail.com>
  • To: talk@phillyonrails.org
  • Subject: Re: [PhillyOnRails] rspec slides
  • Date: Mon, 17 Sep 2007 23:41:51 -0400
  • Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:in-reply-to:references:content-type:message-id:from:subject:date:to:x-mailer; bh=BVCB5UWXkNWiZzA4Wt3bBP8jT+pR9Bpbpi8EDY68j58=; b=g1KcZQWs3GZU+Hj3L7E3M1Y6CG/40gCcKZVodCyuhQzlRJp1uwUBn6WSGphvNCe4BhwZHmvV8ezOf7yL7ju9JAekjSQrmZzBMeC+2dwTRusjzcUZEKXOWKV5/Yp2t+QjzfaOI+IQ8nU1kxYdbXFXME8tMsypfVv4rANM8MteWpI=
  • List-archive: <http://lists.phillyonrails.org/pipermail/talk>
  • Reply-to: talk@phillyonrails.org
  • Sender: talk-bounces@phillyonrails.org

I'm just an observer in this conversation, but I think it is pointless
to test that it can throw an error but I don't think it's pointless to
test whether or not that validation is in your code.

I personally believe in speccing most cases with validations because I'm not trying to "test" whether Rails core functions are working... I don't use Rspec for testing.... I'm backing up my user stories and -behaviors- that my users will experience or functionality of a system I will be designing then coding. 

If I am going to require a user's name or password to be a certain length... of course Rails is going to handle the validation properly, code-wise (and write some unit tests if your not feeling that). But shouldn't anyone reading my "specs" (Rspec or written design spec, etc.) understand how my system handles user data regardless of the language its written in??? Not being surprised when some aspect of that system requires a certain sized string or specially formated email address???

Sure, the spec is only three lines, but it does add up.  At what point do we trust the Rails framework to be self-documenting, or defer psuedo-documentation to the spec file?  Should we be writing specs for dynamic finders?  What about saving an association?

With Rails, I hope that people don't start becoming naive to the subtleties they are becoming accustomed to. I think its naive to even pretend that just because some packaged core method is handed to us to help make our data more valid (validations), we should completely ignore acknowledging them in our system design specifications. Where do you draw that line?

But for small, quick apps with just a few and experienced programmers, I think [opinion flag] that it is more pragmatic to eschew full RSpec coverage and stick to specifying the logic that is interesting to your app.  Wasted time is wasted money.

It should be noted that this "opinion flag" is incredibly large, broad and colorful.

:: Justin Reagor


On Sep 13, 2007, at 5:07 PM, Cassius Rosenthal wrote:

Randy Schmidt wrote:
Just as it is frowned upon to rspec
whether ActiveRecord can save a record, I think it's equally pointless
to rspec whether validates_length_of can return an error.

    


I'm just an observer in this conversation, but I think it is pointless
to test that it can throw an error but I don't think it's pointless to
test whether or not that validation is in your code.

That is a good point, but do we really need:
it do
 user.login.length.should be_close( 8, 4 )
end
when all that we *want* to write is:
 validates_length_of :login, :within => 4..12

Sure, the spec is only three lines, but it does add up.  At what point do we trust the Rails framework to be self-documenting, or defer psuedo-documentation to the spec file?  Should we be writing specs for dynamic finders?  What about saving an association?

Take this one line:
has_many :dogs
Think of all of the things that this tells you about User and Dog.  Now think of how many lines of RSpec you would need to 'specify' the same behavior.

Now imagine that you wrote your login.length spec, and then the business logic changes -- turns out that the boss likes a login "iamthebossandyourarenot."  Now you have to change the spec to be_close( 14, 10 ) and the model validation to 4..24.  Remember the magic of just putting that one line "validates...of" in Rails and having it do what you wanted?  Now all of the sudden you are pre-documenting that line, and programming in Rails is starting to feel more like a drag.

To take another example, if you have map.resources :dog in routes, then do you really need:
route_for(:controller => "dogs", :action ="" "list").should eql("/dogs")
?  Do you really need that for *every single one* of the RESTful routes if you know that you have that one line in routes?  I would argue, "no" --  that one line in routes is much better at signifying application logic than the 30 or so lines that it takes to specify that in RSpec.

For large apps with long development times, absolutely -- the more documentation, the better.  [Although in that case you should be using Erlang/Yaws/mnesia anyway (^_^) ]  But for small, quick apps with just a few and experienced programmers, I think [opinion flag] that it is more pragmatic to eschew full RSpec coverage and stick to specifying the logic that is interesting to your app.  Wasted time is wasted money.

I am not alone in thinking this way, either.  Take a look at the 'rSpec Basics' peepcode for comparison, and they also mention that the default controller specs are excessive.  Excoriations for rSpec abound for the google-savvy; but again, I'm actually arguing that you *should* use RSpec, just be aware of it's drawbacks.

Thanks!
-Casey
_______________________________________________
To unsubscribe or change your settings, visit:

_______________________________________________
To unsubscribe or change your settings, visit:
http://lists.phillyonrails.org/mailman/listinfo/talk