I think what you're after out-of-the-box would be something like this:
Given a child: "child1" exists
And the following parents exist:
| parent_alias | Child_alias |
| parent1 | child1 |
with step:
Given /^the following parent child: "(.*)" exists$/ do |
parent_child_table |
parent_child_table.hashes.each do |parent_child_hash|
parent = parent_child_hash[:parent]
child = parent_child_hash[:child]
Given "a parent: \"#{parent}\" exists with child: child "#{child}"
end
end
And that should be it. You may like to use the pickle create model
function rather than dynamically creating another given step. I used
it here, because to be honest I am yet to learn the pickle internals
properly, I re-use steps whenever I can as they are defined within my
app and much easier for me to find.
You may find these bits from the pickle rdoc useful:
http://ianwhite.github.com/pickle/doc/files/README_rdoc.html
You can refer to other models in the fields
-------------------------------------------
Given a user exists
And a post exists with author: the user
Given a person: "fred" exists
And a person: "ethel" exists
And a fatherhood exists with parent: user "fred", child: user "ethel"
And if you want to test your associations (rather than create, as you
are doing here)
Asserting associations
----------------------
One-to-one assocs: “Then a model should be other model’s association“,
e.g.
Then the person: "fred" should be person: "ethel"'s father
Many-to-one assocs: “Then a model should be [in|one of] other model’s
association“, e.g.
Then the person: "ethel" should be one of person: "fred"'s children
Then the comment should be in the post's comments