2012-02-18 04:19:57 +00:00
|
|
|
module FactoryGirl
|
|
|
|
class FactoryRunner
|
|
|
|
def initialize(name, strategy, traits_and_overrides)
|
|
|
|
@name = name
|
|
|
|
@strategy = strategy
|
|
|
|
|
2012-03-09 21:14:06 +00:00
|
|
|
@overrides = traits_and_overrides.extract_options!
|
|
|
|
@traits = traits_and_overrides
|
2012-02-18 04:19:57 +00:00
|
|
|
end
|
|
|
|
|
2012-04-25 19:29:02 +00:00
|
|
|
def run(runner_strategy = @strategy, &block)
|
2012-02-18 04:19:57 +00:00
|
|
|
factory = FactoryGirl.factory_by_name(@name)
|
|
|
|
|
2012-03-09 19:05:05 +00:00
|
|
|
factory.compile
|
|
|
|
|
2012-02-18 04:19:57 +00:00
|
|
|
if @traits.any?
|
|
|
|
factory = factory.with_traits(@traits)
|
|
|
|
end
|
|
|
|
|
2015-05-20 03:18:34 +00:00
|
|
|
instrumentation_payload = {
|
|
|
|
name: @name,
|
|
|
|
strategy: runner_strategy,
|
|
|
|
traits: @traits,
|
|
|
|
overrides: @overrides,
|
|
|
|
factory: factory
|
|
|
|
}
|
2012-05-04 16:05:31 +00:00
|
|
|
|
2012-05-05 05:14:21 +00:00
|
|
|
ActiveSupport::Notifications.instrument('factory_girl.run_factory', instrumentation_payload) do
|
2012-05-04 16:05:31 +00:00
|
|
|
factory.run(runner_strategy, @overrides, &block)
|
|
|
|
end
|
2012-02-18 04:19:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|