aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/test_unit/test_requirer.rb
blob: 92e5fcf0bcf31c12a9e8e22fe340092420c48c62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require "active_support/core_ext/object/blank"
require "rake/file_list"

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

        file_list = Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"]
        file_list.exclude(exclude_patterns)

        file_list.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"
            else
              arg
            end
          end
        end
    end
  end
end