Skip to content

Instantly share code, notes, and snippets.

@JanDintel
Created November 5, 2013 12:10
Show Gist options
  • Save JanDintel/7318148 to your computer and use it in GitHub Desktop.
Save JanDintel/7318148 to your computer and use it in GitHub Desktop.
Factories with `#initialize_with`
# spec/factories/factory.rb
factory :factory_name, class: Klass do
skip_create
ignore do
variable "Hello"
end
initialize_with do
object = FactoryGirl.create(:object)
FactoryGirl.create(:through_object, object: object)
Klass.new(object)
end
after(:create) { FactoryGirl.create(:callback_or_dependency) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment