[rspec-users] How do I best setup data for Story Runner?

Pat Maddox pergesu at gmail.com
Thu Sep 27 15:41:33 EDT 2007

On 9/26/07, Simon Peter Nicholls <simon at mintsource.org> wrote:
> Just started looking at the Story Runner integration, and am
> converting a few Rails integration tests to get a feel for it.
> My integration tests relied on fixtures, and since my models have a
> significant amount of validation (and hence need valid data unless I
> save without validation), this has made setup easy.
> With stories however, I'm wondering what the recommended approach is.
> Mocks are out I assume, since the point is testing the stack, but are
> fixtures out too? Should we be meeting our more complex or repetitive
> setup needs by treating it as plain ruby code that needs refactoring
> via regular Ruby/OO techniques (Object Mother et al)?
> A typical scenario for me might involve a couple of users with
> different roles, plus a collection of other collaborating objects.
> Thanks
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

I don't use fixtures (the yaml type, anyway) in story runner stories.
I construct objects in the given blocks.  I find that that does two
things for me.  First, it clearly expresses what a given really means.
 So when I say Given "an activated user," I don't have to go dig
around some YAML files.  If I need to understand it I can just look at
the code and see
u = User.create! :login => "pat"

Secondly, constructing your object graph instead of using fixtures
means you're actually exercising your code.  With fixtures you just
instantiate some objects and fill them with data, which may not
necessarily be valid (they require maintenance).  Also if you're using
stuff like before/after create hooks to create child objects, using
fixtures bypasses that.

I look at fixtures as a weird kind of mock.  You're not using the full
implementation, so what's the point really?  I'd rather use a real
object or a proper mock object.  In stories I don't use mocks at all,
so obviously I'll go for the full implementation.


More information about the rspec-users mailing list