Vinchbr Vinchbr - 7 months ago 34
Ruby Question

Is it possible to use Factory Girl to update an already instanced factory?

So I am trying to streamline our cukes trying to leverage the wonderful factories built into our system for unit tests.

I am setting up a

@bread ||= FactoryGirl.create(:bread)
in a background step.

through out that feature, I want to add a trait which would be called
@bread ||= FactoryGirl.create(:bread, :organic)
if the background step did not exist.

already exists, is there a way for me to 'update' it with the trait?


Try something like this (I haven't tested this)

@bread.update(FactoryGirl.attributes_for(:bread, :organic)