Slide 86
Slide 86 text
FACTORY DEFAULT
module FactoryDefault
module CreateDefaultMethod
def create_default(name, args, &block)
res = create(name, args, &block)
FactoryDefault.register(name, res)
res
end
end
module StrategyExt
def association(runner)
return super unless FactoryDefault.exists?(runner.name)
FactoryDefault.get(runner.name)
end
end
# main stuff here
end
FactoryGirl: Syntax: Methods.include CreateDefaultMethod
FactoryGirl: Strategy: Create.prepend StrategyExt
* Complete example can be found here