On Jun 25, 2008, at 9:38 PM, Mikel Lindsaar wrote:

On Thu, Jun 26, 2008 at 4:37 AM, Christopher Bailey
<[EMAIL PROTECTED]> wrote:
If there's already been a thread on this, let me know (and if you can,
point me to it)...

I asked something similar about a week or so ago, you can see it here:

http://www.ruby-forum.com/topic/156392

It is on 'reusing story specs'

But I have done some more work since then...

In building my stories, I often need to setup a bunch of data where
you have multiple levels of models that depend on each other.  For

Scenario: view doctors
Given: existing locations
And: existing organizations
And: existing doctors

You can use plain text stories and use multiple steps_for to get a
similar effect.

But in this case, on that set of stories, it would make sense to
reduce that Given block down to:

# viewing doctors story file...
Scenario: view doctors
 Given: existing doctors in organizations that have a location
 When...

And then I would use some helpers or fixture loading to handle your
data loading...

# spec helper file...
def build_valid_doctor(params)
 location = Location.create(:blah...)
 org = Organization.create(:location => location)
 Doctor.create({:organization => org}.merge(params))
end

# steps file....
steps_for :viewing_doctors do

 Given "existing doctors in organizations that have a location"
   build_valid_doctor(:surname => 'Hyde')
   build_valid_doctor(:surname => 'Jeckle')
 end

end


Of course you can make those factory methods do all sorts of things...


It really seems you are asking two questions: One about reusability, and one about setting up data.

I can't add anything to the first, but factories are definitely the way to go regarding the second issue (setting up the data). Check out this post by Dan Manges (and look at the fixture options at the end of the post):

http://www.dcmanges.com/blog/38

Scott



Hope that helps

Mikel

--
http://lindsaar.net/
Rails, RSpec, Puppet andLife blog....
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to