Hi --

On Sun, 3 Aug 2008, James Britt wrote:

> David A. Black wrote:
>> Hi --
>> 
>> On Sun, 3 Aug 2008, James Britt wrote:
>> 
>
>>> Isn't the idea of TDD and BDD that you discover what classes and method 
>>> are needed by writing the tests first?  So there *should* be no model in 
>>> place prior to writing the test; the initial failure of the test is what 
>>> drive the creation of the model.
>> 
>> That may be the ideal for some people, but not for me when I'm
>> modeling a domain and especially when I'm working out a database
>> schema. I don't consider unit tests to have superseded the other tools
>> that support those activities, including blank pieces of paper and
>> index cards and so on. I guess you could write unit tests for a Rails
>> app before creating the models, if you mocked up the objects'
>> attributes, their associated objects, and so on (since there would
>> presumably be no database yet), and then rename your files so they
>> don't get clobbered when you generate the test files... but it seems
>> like it would be terribly arduous, with no real gain, and I don't
>> think I've ever seen anyone do it.
>
> http://www.infoq.com/interviews/Dave-Astels-and-Steven-Baker#
>
> Quote:
>
> I guess you don't use the Rails code generation then.
>
> Steven: No, not at all. I use TDD to generate code manually.
>
> So you don't even do model generation with Rails?
>
> Steven: Not at all. Especially when I'm pairing with somebody who's never 
> used Rails before or who has never done TDD before I find it especially 
> important not to rely on the generator to give me test stubs, to give me 
> things that I should know or that I should be providing for myself. When the 
> failings specifications tell me that I need it, because that would be 
> contradicting what I'm trying to teach.

OK, now I've seen one person :-) I imagine there are more. Luckily we
don't need a consensus; we can all do what we're comfortable with.
It's interesting that Steve does it this way, and I'd like to see it
in person.

It doesn't appeal to me not to use the model generator. For one thing,
I assume that it would mean having to run sequential migrations, where
you wrote a test or spec that tested for the presence of, say, a
first_name attribute on the user; then add that column to the
database; then test for last_name; then add that column; and so forth.
I don't mean to sound like I'm parodying what Steve is describing. I
assume that this, or something like it, is what you'd end up doing.


I'm not sure what Steve means by test stubs in this context. The model
generation just gives you a file with an empty class definition for
your tests, and I think something similar happens with RSpec. (Just to
clarify: I'm talking about model generation, not scaffold generation,
which does give you all sorts of tests and which I dislike strongly
and consider manifestly counter-productive.)


David

-- 
Rails training from David A. Black and Ruby Power and Light:
  *  Advancing With Rails    August 18-21    Edison, NJ
  * Co-taught by D.A. Black and Erik Kastner
See http://www.rubypal.com for details and updates!