What's the use of writing tests matching configuration-like code line by line?

Posted by Pascal Van Hecke on Stack Overflow See other posts from Stack Overflow or by Pascal Van Hecke
Published on 2011-02-10T14:50:35Z Indexed on 2011/02/10 15:25 UTC
Read the original article Hit count: 195

Hi,

I have been wondering about the usefulness of writing tests that match code one-by-one.

Just an example: in Rails, you can define 7 restful routes in one line in routes.rb using:

resources :products

BDD/TDD proscribes you test first and then write code. In order to test the full effect of this line, devs come up with macros e.g. for shoulda: http://kconrails.com/2010/01/27/route-testing-with-shoulda-in-ruby-on-rails/

class RoutingTest < ActionController::TestCase
  # simple
  should_map_resources :products
end

I'm not trying to pick on the guy that wrote the macros, this is just an example of a pattern that I see all over Rails.

I'm just wondering what the use of it is... in the end you're just duplicating code and the only thing you test is that Rails works. You could as well write a tool that transforms your test macros into actual code...

When I ask around, people answer me that:

"the tests should document your code, so yes it makes sense to write them, even if it's just one line corresponding to one line"

What are your thoughts?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about unit-testing