Forum: Ruby on Rails Rails and TDD

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0f7716186bac5a8a2dc8007b70928c06?d=identicon&s=25 Luke Ivers (technodolt)
on 2007-01-18 15:20
I'm trying out the whole TDD on my newest project, and here's my

I am creating a login system (I know, I know... re-inventing the wheel,
blah blah blah; I'm doing this to teach myself things, not because I
don't think there's something out there that can handle what I want),
and so far, I've realized I'm going to need a User model and a User
controller.  I've created both of them, and I'm starting to write the
tests that I will be developing towards passing: my question is, should
I write tests for the controller, then the model; the model, then the
controller; or try to do them both in tandem?  I'm having problems
figuring out where to start with this, as I've never done TDD before and
I'm fairly new to the Rails game in general.
Db303dc84d03a992b33cd3ac978f89ae?d=identicon&s=25 Benjamin Curtis (Guest)
on 2007-01-18 15:23
(Received via mailing list)
Do the model first, since the controller will depend on the model.

Building an e-commerce site with Rails?

Meet up at RailsConf:
5301cef77ec4942463fae0ba820b6b57?d=identicon&s=25 Tim Case (Guest)
on 2007-01-18 16:02
(Received via mailing list)
I did this exact same exercise when I was learning rails and it's a
GREAT way to pick up both TDD and Rails because down the line you'll
be able to compare your results against some of the login generators
out there and see where you and the others differ.

It'll also give you a thorough understanding of your login system
which sadly, if generated, can be a hole in someone's intellectual
command of one of the most crucial pieces of their application.

For learning TDD I suggest checking out Geoffrey Grosenbach's peep cast
on it:

Oh and also if you want a headstart on the login system Chad Fowler's
Rails Recipes has some nuggets for both authentication and

I haven't viewed this particular peepcast but I've watched the others
and they are excellent.

Good luck,

Tim Case
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-01-18 17:04
(Received via mailing list)
On 1/18/07, Luke Ivers <> wrote:
> I'm trying out the whole TDD on my newest project, and here's my
> dilemma:
> I am creating a login system

Break this feature up into tasks, each representing one user
interaction. Example:

 - logout
 - login bad user name
 - log in bad password
 - log in first time

For each one, write enough Railage to enable only that interaction.
Each one may require tweaks to a database, model, controller, and/or

Write test cases before as many tweaks as possible. Pass all tests
after every few edits. If you can't think of a test (look up
assert_select and submit_form to test the view), then at least add a
test after you write the code

> (I know, I know... re-inventing the wheel,

Hardly. Many erudite, educated, senior, overpaid, world-class
programmers still don't TDD, and anyone who does will easily blow them

  Phlip  <-- NOT a blog!!
3299251223f55753ec84719de39e6e53?d=identicon&s=25 Jon Garvin (Guest)
on 2007-01-18 17:20
(Received via mailing list)
Definitely test the model first.  Check out Rcov as well.  It's a great
way to help make sure your tests are complete.  It won't make sure
you're testing *every* possible scenario, but it's a great start.
This topic is locked and can not be replied to.