# Test driven development advice

**URL:** <https://www.ruby-forum.com/t/test-driven-development-advice/176250>\
**Category:** Rails\
**Created:** [September 28, 2009, 12:52am UTC](https://www.ruby-forum.com/t/test-driven-development-advice/176250 "2009-09-28T00:52:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@drewB](https://www.ruby-forum.com/u/drewB)\
**Post date:** [September 28, 2009, 12:52am UTC](https://www.ruby-forum.com/t/test-driven-development-advice/176250/1 "2009-09-28T00:52:06Z")

</div>

I am attempting to use Test Driven Development for the first time and  
was hoping for a little advice. I am just starting a new section of  
the website that will ultimately contain a couple controllers and  
about 6 models. If I am going to write my tests before any code, I  
need to decide whether to start writing test with the models or the  
controllers. Do I write the test for the models and in the course of  
writing the code that will make them succeed build the models or  
should I start with the models, get them all working and then move on  
to the controllers? My guess is you can do it either way but I  
thought perhaps some folks who have worked in TDD environments might  
have some wisdom to share.

Thanks!

---

<div class="post-metadata">

**Author:** ![drewB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@drewB](https://www.ruby-forum.com/u/drewB)\
**Post date:** [September 28, 2009, 1:29am UTC](https://www.ruby-forum.com/t/test-driven-development-advice/176250/2 "2009-09-28T01:29:23Z")

</div>

drewB wrote:

> I am attempting to use Test Driven Development for the first time and  
> was hoping for a little advice.

Great! Give serious consideration to rSpec, if you haven’t already, and  
completely avoid Rails’ fixtures (use Machinist or similar instead).

> I am just starting a new section of  
> the website that will ultimately contain a couple controllers and  
> about 6 models.

You haven’t written tests yet. You don’t really know how many of either  
it will contain. Don’t do this level of design before writing tests.

> If I am going to write my tests before any code, I  
> need to decide whether to start writing test with the models or the  
> controllers. Do I write the test for the models and in the course of  
> writing the code that will make them succeed build the models or  
> should I start with the models, get them all working and then move on  
> to the controllers? My guess is you can do it either way but I  
> thought perhaps some folks who have worked in TDD environments might  
> have some wisdom to share.

You certainly can do it either way. I think in most cases, I would try  
to start by writing Cucumber features to establish how the application  
should present itself to the user, then write whatever classes (and unit  
tests) prove necessary to implement those features.

> Thanks!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![drewB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@drewB](https://www.ruby-forum.com/u/drewB)\
**Post date:** [September 28, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/test-driven-development-advice/176250/3 "2009-09-28T20:00:02Z")

</div>

Thanks for the tips. I just got the beta version Pragmatic Bookshelf  
Rspec and am working through it now.

On Sep 27, 4:29 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-
