Class: FactoryGirl::FactoryRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_girl/factory_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, strategy, traits_and_overrides) ⇒ FactoryRunner

Returns a new instance of FactoryRunner.



3
4
5
6
7
8
9
# File 'lib/factory_girl/factory_runner.rb', line 3

def initialize(name, strategy, traits_and_overrides)
  @name     = name
  @strategy = strategy

  @overrides = traits_and_overrides.extract_options!
  @traits    = traits_and_overrides
end

Instance Method Details

#run(runner_strategy = @strategy, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/factory_girl/factory_runner.rb', line 11

def run(runner_strategy = @strategy, &block)
  factory = FactoryGirl.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_girl.run_factory', instrumentation_payload) do
    factory.run(runner_strategy, @overrides, &block)
  end
end