我通常使用这个步骤来设置 factory_girl 的记录:
Given /^the following (.+) records?:$/ do |factory, table|
table.hashes.each do |hash|
Factory(factory, hash)
end
end
这是我在建立关联时的解决方法:
Given the following group record:
| id | name |
| 1 | foo |
And the following item records:
| name | group_id |
| bar | 1 |
| baz | 1 |
# ...
我知道这很糟糕。从域人员的角度来看,使用 ids 会使整个事情变得脆弱和神秘。
所以,我的问题是——建立与 factory_girl 的关联和上面的表参数的最佳做法是什么?