[rspec-users] How do I best setup data for Story Runner?
badcarl at gmail.com
Thu Sep 27 18:11:57 EDT 2007
On Sep 27, 2007, at 12:41 PM, Pat Maddox wrote:
> 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.
>> rspec-users mailing list
>> rspec-users at rubyforge.org
> 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.
> rspec-users mailing list
> rspec-users at rubyforge.org
I've adopted a factory pattern for organizing my tests inspired by:
More information about the rspec-users