The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Why Should I 'Test Rails Itself?'

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Amos King

Posts: 78
Nickname: adkron
Registered: Jan, 2007

Amos King is a Web Developer for the US Postal Service and for Ramped Media.
Why Should I 'Test Rails Itself?' Posted: Mar 21, 2007 3:45 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Amos King.
Original Post: Why Should I 'Test Rails Itself?'
Feed Title: DirtyInformation
Feed URL: http://feeds.feedburner.com/Dirtyinformation
Feed Description: Information about Ruby/Rails/JRuby/WebDevelpoment/whatever.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Amos King
Latest Posts From DirtyInformation

Advertisement

I was reading Google Groups' Rails Group the other day when I ran into someone talking about why should I test the validates functions. Here is a quote from his email:

For example, what is the point of writing a unit test that simply tests a validate statement in the model? Yes, it's interesting (the first time, at least) that the test works and that, golly-gee, Rails works as advertised, as well, but is there any real use in doing this?
I can imagine a scenario where a I update Rails and suddenly a unit test that tests a Rails validator fails, but I expect the Rails development team would find this before me. Or is that too naive?

I just thought I would post my response for anyone who has the same question. Also, sorry if the format is bad or to quick, but I was trying to hurry when I wrote him the response.

Don't look it as testing Rails. You are testing your model on testing validates. Let's say you write this class:

class Person < ActiveRecord::Base
  validates_length_of :phone_number, :within => 7..10
  ...
end

So you write a test:

def test_phone_number_length_correct
  person = Person.new(:phone_number => '1234567')
  person.valid?
  assert !person.errors.invalid?(:phone_number), 'Valid Phone Number Coming Back as Invalid'
end

I think we would all agree that this test makes sure that a valid phone number passes.

Now not thinking you do a find and replace and replace all 7s with 8s or maybe number with numbers is more likely. So you have:

class Person < ActiveRecord::Base
  validates_length_of :phone_numbers, :within => 7..10
  ...
end

Now you can place :phone_number => '12' into your database because you are now validating :phone_numbers.

If you have a test you run tests after you completed the find and replace, and this error would be caught right away. That is why you 'test Rails.'

Read: Why Should I 'Test Rails Itself?'

Topic: Where are all the Groovy (and/or Grails) benchmarks? Previous Topic   Next Topic Topic: Review: Highrise, part 2

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use