[rspec-users] a better "should have valid associations"
work at ashleymoran.me.uk
Thu Mar 29 05:38:29 EDT 2007
On 29 Mar 2007, at 09:18, Courtenay wrote:
> Note: I usually feel that testing associations is really testing the
> framework, and such code belongs in the framework itself.
All the fancy details that load and save are part of the framework,
but you still have to write has_whatever in your model class. My
test-code ratio for models is 3.8:1, almost entirely due to copy-and-
past coding to verify the associations. I'd love a really expressive
way of testing associations like "Car.should have_many(:wheels)" or
"Bull.should have_one(:udder)" or whatever. But looking at my own
code it would be hard to factor out a one-size-fits-all expectation,
especially through associations.
More information about the rspec-users