[rspec-users] RSpec makes me want to write better code
tastapod at gmail.com
Sat Sep 27 14:26:49 EDT 2008
2008/9/26 David Chelimsky <dchelimsky at gmail.com>
> On Fri, Sep 26, 2008 at 12:18 PM, Mark Wilden <mark at mwilden.com> wrote:
> > On Fri, Sep 26, 2008 at 9:47 AM, Ashley Moran
> > <ashley.moran at patchspace.co.uk> wrote:
> To me, spec'ing attributes is a red flag. It is not always a bad thing
> or wrong, but it suggests that the focus is on structure instead of
What David said. A lot.
It seems these conversations come up time and again because Rails overloads
the idea of "model". In a Rails app the model serves as both your domain
model and your persistence strategy, because of the coupling inherent in the
Active Record pattern. Your domain model should evolve out of solving
problems in your domain. For any non-trivial domain model the persistence
strategy should be an entirely separate concern.
At the risk of going off on one, Active Record scales to *exactly zero
behaviour* in your model. In other words it is perfect for
data-on-the-screen apps, which to be fair is about 90% of web apps. As soon
as your domain model becomes sufficiently interesting it becomes a contest
between us and the AR pixies. Luckily we have the likes of David and Pat
Maddox on our side :)
If you start by specifying what you want your application to do in the form
of a single user example (a scenario), the model should fall out of solving
this. Unfortunately this doesn't fit the model-driven (generators) approach
that Rails encourages.
I'm not sure what advice to offer here, other than to be aware that Rails
"best practices" are usually counter to an outside-in, behaviour-driven
approach to writing applications. So if you want to use all the code-gen
magic in Rails you will always be making these trade-offs.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users