Created
December 12, 2010 21:26
-
-
Save devpuppy/738343 to your computer and use it in GitHub Desktop.
trick to load factories from subdirectories of test/factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will go three levels deep to find Factory definitions within subdirectories of test/factories | |
path = Rails.root.join('test/factories') | |
levels = 3 | |
subdirectories = Dir[File.join(path, '*')].select {|name| File.directory?(name) } | |
(levels - 1).times do | |
subdirectories.each do |subdirectory| | |
subdirectories += Dir[File.join(subdirectory, '*')].select {|name| File.directory?(name) } | |
end | |
end | |
subdirectories.each do |subdirectory| | |
Dir[File.join(subdirectory, '*.rb')].sort.each do |file| | |
require file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment