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

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.

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

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



Solution 1:[1]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 r3b00t