2016-08-06 13:15:47 -04:00
|
|
|
require "active_support/core_ext/object/blank"
|
|
|
|
require "rake/file_list"
|
2015-03-21 08:15:56 -04:00
|
|
|
|
|
|
|
module Rails
|
|
|
|
class TestRequirer # :nodoc:
|
|
|
|
class << self
|
|
|
|
def require_files(patterns)
|
|
|
|
patterns = expand_patterns(patterns)
|
|
|
|
|
2016-08-06 13:15:47 -04:00
|
|
|
Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"].to_a.each do |file|
|
2015-03-21 08:15:56 -04:00
|
|
|
require File.expand_path(file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def expand_patterns(patterns)
|
|
|
|
patterns.map do |arg|
|
2016-08-06 13:15:47 -04:00
|
|
|
arg = arg.gsub(/(:\d+)+?$/, "")
|
2015-03-21 08:15:56 -04:00
|
|
|
if Dir.exist?(arg)
|
|
|
|
"#{arg}/**/*_test.rb"
|
2015-09-06 08:21:18 -04:00
|
|
|
else
|
2015-03-21 08:15:56 -04:00
|
|
|
arg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|