On 10/09/2011, at 5:06 PM, Brian Guthrie wrote:

>> if you're doing proper BDD or TDD, a lot of unit tests are just unnecessary
> 
> Could you maybe clarify this a bit? If you mean unit tests of private
> methods, or avoiding overarchitecting (YAGNI), then I agree. But to me
> testing the existence of associations certainly falls within the remit
> of BDD--it's part of your class's public API, it's one of its
> responsibilities, and to test it exercises the behavior of that class.

Yes, but are you delivering a class, or are you delivering an application? If 
you're treating your application as the "public" interface, there's a strong 
case to be made that the underlying implementation details should be as fluid 
as possible. This doesn't mean "don't test them" but it means, let the required 
behaviours emerge as you develop the code, rather than trying to design it up 
front.

> 
> All a basic test of an association says is that there exists a method
> with that name, and when you call it under certain circumstances then
> it responds in certain ways--for example, with an empty array when
> called on a new instance of an object. It doesn't say anything about
> the way you've gone about declaring that method, nor should it (in
> this case, with an assist from ActiveRecord). If you decided to ditch
> those ActiveRecord associations tomorrow and custom-design a method
> that does the same thing, those tests would have value, because you'd
> want to make sure that class's behavior with regard to its
> collaborators remains unchanged.

And in that case, I would THEN write the specs that ensured that the class 
still implemented the same contract as the ActiveRecord association. Not before.

> 
> If you skip these tests, you're technically cheating a bit, aren't
> you? You have knowledge about the contents of that class, and you're
> choosing not to exercise that behavior because it seems self-evident.
> 

No, it's choosing to only exercise the code that you care about, in the ways 
that you care about it working. If my job is to deliver an app that does X, Y 
and Z, I don't care about how the guts of rails works, I just care that it 
works. Exercising a bog-standard has_many association is a waste of my time and 
the clients' money.

> Brian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby or Rails Oceania" group.
> To post to this group, send email to rails-oceania@googlegroups.com.
> To unsubscribe from this group, send email to 
> rails-oceania+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rails-oceania?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to rails-oceania@googlegroups.com.
To unsubscribe from this group, send email to 
rails-oceania+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to