rubyfactory-botqabstracttablemodel

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

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

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