Sha256: b55b3ed7d30f8c42fb1908efe4239b5c4253e6cbdde3e1e4e5a9d97bb8bad0fd

Contents?: true

Size: 838 Bytes

Versions: 4

Compression:

Stored size: 838 Bytes

Contents

module FactoryBot
  class FactoryRunner
    def initialize(name, strategy, traits_and_overrides)
      @name     = name
      @strategy = strategy

      @overrides = traits_and_overrides.extract_options!
      @traits    = traits_and_overrides.map(&:to_sym)
    end

    def run(runner_strategy = @strategy, &block)
      factory = FactoryBot.factory_by_name(@name)

      factory.compile

      if @traits.any?
        factory = factory.with_traits(@traits)
      end

      instrumentation_payload = {
        name: @name,
        strategy: runner_strategy,
        traits: @traits,
        overrides: @overrides,
        factory: factory,
      }

      ActiveSupport::Notifications.instrument("factory_bot.run_factory", instrumentation_payload) do
        factory.run(runner_strategy, @overrides, &block)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
factory_bot-5.0.1 lib/factory_bot/factory_runner.rb
factory_bot-5.0.0 lib/factory_bot/factory_runner.rb
factory_bot-5.0.0.rc2 lib/factory_bot/factory_runner.rb
factory_bot-5.0.0.rc1 lib/factory_bot/factory_runner.rb