I'm new to factory girl. I want to create a Share factory that belongs to both a Membership and a Stake factory (so that both have an association with the same Group instance). I'm trying to write my Share factory as follows instead of using the association method to avoid callbacks that would create the Share.
factory :share do
before(:create) do |share, evaluator|
stake = create(:shareless_stake, group: evaluator.same_group)
member = create(:shareless_membership, group: evaluator.same_group)
share.stake = stake
share.membership = member
share = create(:share, same_group: create(:group))
same_group without a default value causes Factory Girl to treat it as an association rather than an attribute (and attempt to look up a factory of the same name). Changing this line to e.g.
same_group nil would solve that problem. It's an admittedly confusing aspect of Factory Girl that the same method can be treated as either an attribute or an association depending on the number of arguments or presence of a block.