diff --git a/lib/factory_girl.rb b/lib/factory_girl.rb index c59e844..e6fed35 100644 --- a/lib/factory_girl.rb +++ b/lib/factory_girl.rb @@ -2,6 +2,7 @@ require 'set' require 'active_support/core_ext/module/delegation' require 'active_support/notifications' +require 'factory_girl/configuration' require 'factory_girl/errors' require 'factory_girl/factory_runner' require 'factory_girl/strategy_syntax_method_registrar' @@ -39,8 +40,16 @@ require 'factory_girl/reload' require 'factory_girl/version' module FactoryGirl + def self.configuration + @configuration ||= Configuration.new + end + + def self.reset_configuration + @configuration = nil + end + def self.factories - @factories ||= DisallowsDuplicatesRegistry.new(Registry.new('Factory')) + configuration.factories end def self.register_factory(factory) @@ -55,7 +64,7 @@ module FactoryGirl end def self.sequences - @sequences ||= DisallowsDuplicatesRegistry.new(Registry.new('Sequence')) + configuration.sequences end def self.register_sequence(sequence) @@ -70,7 +79,7 @@ module FactoryGirl end def self.traits - @traits ||= DisallowsDuplicatesRegistry.new(Registry.new('Trait')) + configuration.traits end def self.register_trait(trait) @@ -85,7 +94,7 @@ module FactoryGirl end def self.strategies - @strategies ||= Registry.new('Strategy') + configuration.strategies end def self.register_strategy(strategy_name, strategy_class) @@ -113,7 +122,7 @@ module FactoryGirl end def self.callback_names - @callback_names ||= Set.new + configuration.callback_names end def self.register_callback(name) diff --git a/lib/factory_girl/configuration.rb b/lib/factory_girl/configuration.rb new file mode 100644 index 0000000..3f9aacc --- /dev/null +++ b/lib/factory_girl/configuration.rb @@ -0,0 +1,14 @@ +module FactoryGirl + # @api private + class Configuration + attr_reader :factories, :sequences, :traits, :strategies, :callback_names + + def initialize + @factories = DisallowsDuplicatesRegistry.new(Registry.new('Factory')) + @sequences = DisallowsDuplicatesRegistry.new(Registry.new('Sequence')) + @traits = DisallowsDuplicatesRegistry.new(Registry.new('Trait')) + @strategies = Registry.new('Strategy') + @callback_names = Set.new + end + end +end diff --git a/lib/factory_girl/reload.rb b/lib/factory_girl/reload.rb index 35244a1..99fbeab 100644 --- a/lib/factory_girl/reload.rb +++ b/lib/factory_girl/reload.rb @@ -1,10 +1,8 @@ module FactoryGirl def self.reload - self.factories.clear - self.sequences.clear - self.traits.clear - self.strategies.clear + self.reset_configuration self.register_default_strategies + self.register_default_callbacks self.find_definitions end end