2017-10-20 15:20:28 -04:00
|
|
|
module FactoryBot
|
2010-06-24 09:45:57 -04:00
|
|
|
class << self
|
|
|
|
# An Array of strings specifying locations that should be searched for
|
2017-10-20 15:20:28 -04:00
|
|
|
# factory definitions. By default, factory_bot will attempt to require
|
2015-02-02 11:05:01 -05:00
|
|
|
# "factories", "test/factories" and "spec/factories". Only the first
|
2010-06-24 09:45:57 -04:00
|
|
|
# existing file will be loaded.
|
|
|
|
attr_accessor :definition_file_paths
|
|
|
|
end
|
2012-05-05 00:53:19 -04:00
|
|
|
|
2010-06-24 09:45:57 -04:00
|
|
|
self.definition_file_paths = %w(factories test/factories spec/factories)
|
|
|
|
|
2012-05-05 02:31:31 -04:00
|
|
|
def self.find_definitions
|
2013-12-14 22:33:15 -05:00
|
|
|
absolute_definition_file_paths = definition_file_paths.map { |path| File.expand_path(path) }
|
2011-07-22 14:47:47 -04:00
|
|
|
|
2011-07-29 12:22:29 -04:00
|
|
|
absolute_definition_file_paths.uniq.each do |path|
|
2014-06-14 11:10:05 -04:00
|
|
|
load("#{path}.rb") if File.exist?("#{path}.rb")
|
2010-06-24 09:45:57 -04:00
|
|
|
|
|
|
|
if File.directory? path
|
2018-10-07 21:45:51 -04:00
|
|
|
Dir[File.join(path, "**", "*.rb")].sort.each do |file|
|
2011-07-29 12:22:29 -04:00
|
|
|
load file
|
2010-06-24 09:45:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|