Friday, November 09, 2007

Why I am a DataMapper convert (it makes BDD happy)

There’s lots of buzz around [DataMapper](http://datamapper.org/) right now, especially among the #merb crowd. I haven’t had any major issues with ActiveRecord, so I haven’t needed to look at a new ORM…but I like to play with new things, so last night I really gave the DM a try.

I’m a complete convert, if for no other reason that the awesome way automigrations play along with BDD.

First, tell your spec_helper to use automigrations:

Liquid error: No such file or directory – posix_spawnp

This will cause your database tables to be dropped and re-created so use with caution.

Next, let’s spec some behavior:

Liquid error: No such file or directory – posix_spawnp

And see what autotest says:

Liquid error: No such file or directory – posix_spawnp

Cool, that’s what we expected. Now, with ActiveRecord, to get to green, we’d need to create a migration and run it. With DataMapper, we stay in our model:

Liquid error: No such file or directory – posix_spawnp

And autotest says…

Liquid error: No such file or directory – posix_spawnp

Now, is this perfect? Not yet. DM has a good amount of work still. There’s some smart folks working on it, and I bet it will be pretty sweet in a few more weeks.

But, man…that’s just awesome.

Discussion

Follow me on Twitter. I don't have comments enabled, because I remember when we didn't have blog comments, and we did just fine, thank you very much.