diff --git a/lib/factory_girl/find_definitions.rb b/lib/factory_girl/find_definitions.rb index 8ef2575..c4d4fb0 100644 --- a/lib/factory_girl/find_definitions.rb +++ b/lib/factory_girl/find_definitions.rb @@ -14,7 +14,7 @@ module FactoryGirl require("#{path}.rb") if File.exists?("#{path}.rb") if File.directory? path - Dir[File.join(path, '*.rb')].sort.each do |file| + Dir[File.join(path, '**', '*.rb')].sort.each do |file| require file end end diff --git a/spec/factory_girl/find_definitions_spec.rb b/spec/factory_girl/find_definitions_spec.rb index 4824b64..6ec60a5 100644 --- a/spec/factory_girl/find_definitions_spec.rb +++ b/spec/factory_girl/find_definitions_spec.rb @@ -96,5 +96,14 @@ describe "definition loading" do it { should require_definitions_from("#{dir}/factories/person_factory.rb") } end end + + describe "with deeply nested factory files under #{dir}" do + in_directory_with_files File.join(dir, 'factories', 'subdirectory', 'post_factory.rb'), + File.join(dir, 'factories', 'subdirectory', 'person_factory.rb') + it_should_behave_like "finds definitions" do + it { should require_definitions_from("#{dir}/factories/subdirectory/post_factory.rb") } + it { should require_definitions_from("#{dir}/factories/subdirectory/person_factory.rb") } + end + end end end