aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/rails/test_unit/test_requirer.rb
blob: 84c225672924ad871fd67c8904713272a3f80a4b (plain) (tree)



















                                                                                            
                                 






                 
require 'active_support/core_ext/object/blank'
require 'rake/file_list'

module Rails
  class TestRequirer # :nodoc:
    class << self
      def require_files(patterns)
        patterns = expand_patterns(patterns)

        Rake::FileList[patterns.compact.presence || 'test/**/*_test.rb'].to_a.each do |file|
          require File.expand_path(file)
        end
      end

      private
        def expand_patterns(patterns)
          patterns.map do |arg|
            arg = arg.gsub(/:(\d+)?$/, '')
            if Dir.exist?(arg)
              "#{arg}/**/*_test.rb"
            elsif File.file?(arg)
              arg
            end
          end
        end
    end
  end
end