Class: Rails::TestUnit::Runner

Inherits:
Object
  • Object
show all
Defined in:
railties/lib/rails/test_unit/runner.rb

Class Method Summary collapse

Class Method Details

.attach_before_load_options(opts) ⇒ Object



14
15
16
17
# File 'railties/lib/rails/test_unit/runner.rb', line 14

def attach_before_load_options(opts)
  opts.on("--warnings", "-w", "Run with Ruby warnings enabled") { }
  opts.on("-e", "--environment ENV", "Run tests in the ENV environment") { }
end

.compose_filter(runnable, filter) ⇒ Object



53
54
55
56
57
58
59
# File 'railties/lib/rails/test_unit/runner.rb', line 53

def compose_filter(runnable, filter)
  if filters.any? { |_, lines| lines.any? }
    CompositeFilter.new(runnable, filter, filters)
  else
    filter
  end
end

.load_tests(argv) ⇒ Object



44
45
46
47
48
49
50
51
# File 'railties/lib/rails/test_unit/runner.rb', line 44

def load_tests(argv)
  patterns = extract_filters(argv)

  tests = Rake::FileList[patterns.any? ? patterns : "test/**/*_test.rb"]
  tests.exclude("test/system/**/*", "test/dummy/**/*") if patterns.empty?

  tests.to_a.each { |path| require File.expand_path(path) }
end

.parse_options(argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'railties/lib/rails/test_unit/runner.rb', line 19

def parse_options(argv)
  # Perform manual parsing and cleanup since option parser raises on unknown options.
  env_index = argv.index("--environment") || argv.index("-e")
  if env_index
    argv.delete_at(env_index)
    environment = argv.delete_at(env_index).strip
  end
  ENV["RAILS_ENV"] = environment || "test"

  w_index = argv.index("--warnings") || argv.index("-w")
  $VERBOSE = argv.delete_at(w_index) if w_index
end

.rake_run(argv = []) ⇒ Object



32
33
34
35
36
# File 'railties/lib/rails/test_unit/runner.rb', line 32

def rake_run(argv = [])
  ARGV.replace Shellwords.split(ENV["TESTOPTS"] || "")

  run(argv)
end

.run(argv = []) ⇒ Object



38
39
40
41
42
# File 'railties/lib/rails/test_unit/runner.rb', line 38

def run(argv = [])
  load_tests(argv)

  require "active_support/testing/autorun"
end