mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
27 lines
669 B
Ruby
27 lines
669 B
Ruby
|
module FactoryGirl
|
||
|
class FactoryRunner
|
||
|
def initialize(name, strategy, traits_and_overrides)
|
||
|
@name = name
|
||
|
@strategy = strategy
|
||
|
|
||
|
@overrides = if traits_and_overrides.last.respond_to?(:has_key?)
|
||
|
traits_and_overrides.pop
|
||
|
else
|
||
|
{}
|
||
|
end
|
||
|
@traits = traits_and_overrides
|
||
|
end
|
||
|
|
||
|
def run(strategy_override = nil, &block)
|
||
|
strategy_override ||= @strategy
|
||
|
factory = FactoryGirl.factory_by_name(@name)
|
||
|
|
||
|
if @traits.any?
|
||
|
factory = factory.with_traits(@traits)
|
||
|
end
|
||
|
|
||
|
factory.run(strategy_override, @overrides, &block)
|
||
|
end
|
||
|
end
|
||
|
end
|