Factory Girl: can one reopen factory definitions and complete them?
Asked Answered
S

1

8

Hi have this special use case, in which I have to define a factory in one file without a certain parameter, and then insert it in the factory definition later. This is a case where I am importing factory definitions from an external dependency (gem, plugin, whtv) and I need to extend it in my project. Something like:

# external def
FactoryGirl.define do
  factory :user do
    email "[email protected]"
  end
end


# proj def
FactoryGirl.define do
  factory :user do
    password "qwerty"
  end
end

this code doesn't work, cuz factory girl thinks I'm redefining the factory. But what I'd really want would be extending it. Is this possible?

Sapienza answered 11/10, 2012 at 9:43 Comment(0)
S
22

Ups... seems I found the answer. Next time, have to check the documentation a bit furtherer... Here's the answer for anyone interested:

# external def
FactoryGirl.define do
 factory :user do
   email "[email protected]"
 end
end


# proj def
FactoryGirl.modify do
  factory :user do
    password "qwerty"
  end
end
Sapienza answered 11/10, 2012 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.