File: factory_runner.rb

package info (click to toggle)
ruby-factory-bot 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: ruby: 7,827; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
    end

    def run(runner_strategy = @strategy, &block)
      factory = FactoryBot::Internal.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