Permalink
Browse files

FactoryGirl.reload clears all registries and loads all known definitions

Closes #196
  • Loading branch information...
1 parent 7fd7d95 commit 3798144bd1728e818bbb34c37921f430f3dc27a8 @joshuaclayton joshuaclayton committed Sep 2, 2011
@@ -44,19 +44,32 @@ Feature: Factory girl can find factory definitions correctly
| name |
| great!!! |
- Scenario: Find definitions after clearing loaded factories
- Given a file named "nested/swell_factories.rb" with:
+ Scenario: Reload Factory Girl
+ Given a file named "nested/reload_factories.rb" with:
"""
FactoryGirl.define do
- factory :swell_category, :class => Category do
- name "swell!!!"
+ sequence(:great)
+ trait :admin do
+ admin true
+ end
+
+ factory :handy_category, :class => Category do
+ name "handy"
end
end
"""
When "nested" is added to Factory Girl's file definitions path
- And I clear out the factories
- And I find definitions
- And I create a "swell_category" instance from Factory Girl
+ And I append to "nested/reload_factories.rb" with:
+ """
+
+ FactoryGirl.modify do
+ factory :handy_category do
+ name "HANDY!!!"
+ end
+ end
+ """
+ And I reload factories
+ And I create a "handy_category" instance from Factory Girl
Then I should find the following for the last category:
| name |
- | swell!!! |
+ | HANDY!!! |
@@ -34,10 +34,10 @@ def append_file_to_factory_girl_definitions_path(path_to_file)
Given %{the following person exists:}, new_table
end
-When /^I clear out the factories$/ do
- FactoryGirl.factories.clear
-end
-
When /^I find definitions$/ do
FactoryGirl.find_definitions
end
+
+When /^I reload factories$/ do
+ FactoryGirl.reload
+end
View
@@ -22,6 +22,7 @@
require 'factory_girl/syntax/default'
require 'factory_girl/syntax/vintage'
require 'factory_girl/find_definitions'
+require 'factory_girl/reload'
require 'factory_girl/deprecated'
require 'factory_girl/version'
@@ -0,0 +1,8 @@
+module FactoryGirl
+ def self.reload
+ self.factories.clear
+ self.sequences.clear
+ self.traits.clear
+ self.find_definitions
+ end
+end

0 comments on commit 3798144

Please sign in to comment.