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
|
|
|
|
|
2012-04-25 15:29:02 -04:00
|
|
|
def run(runner_strategy = @strategy, &block)
|
2012-02-17 23:19:57 -05:00
|
|
|
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
|
|
|
|
|
2012-05-04 12:05:31 -04:00
|
|
|
instrumentation_payload = { name: @name, strategy: runner_strategy }
|
|
|
|
|
|
|
|
ActiveSupport::Notifications.instrument("factory_girl.run_factory", instrumentation_payload) do
|
|
|
|
factory.run(runner_strategy, @overrides, &block)
|
|
|
|
end
|
2012-02-17 23:19:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|