2012-02-17 23:19:57 -05:00
|
|
|
module FactoryGirl
|
|
|
|
class FactoryRunner
|
|
|
|
def initialize(name, strategy, traits_and_overrides)
|
|
|
|
@name = name
|
|
|
|
@strategy = strategy
|
|
|
|
|
2012-03-09 16:14:06 -05:00
|
|
|
@overrides = traits_and_overrides.extract_options!
|
|
|
|
@traits = traits_and_overrides
|
2012-02-17 23:19:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def run(strategy_override = nil, &block)
|
|
|
|
strategy_override ||= @strategy
|
|
|
|
factory = FactoryGirl.factory_by_name(@name)
|
|
|
|
|
2012-03-09 14:05:05 -05:00
|
|
|
factory.compile
|
|
|
|
|
2012-02-17 23:19:57 -05:00
|
|
|
if @traits.any?
|
|
|
|
factory = factory.with_traits(@traits)
|
|
|
|
end
|
|
|
|
|
|
|
|
factory.run(strategy_override, @overrides, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|