Class: Rails::TestUnit::Runner

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

Constant Summary collapse

TEST_FOLDERS =
[:models, :helpers, :channels, :controllers, :mailers, :integration, :jobs, :mailboxes]
PATH_ARGUMENT_PATTERN =
%r"^(?!/.+/$)[.\w]*[/\\]"

Class Method Summary collapse

Class Method Details

.attach_before_load_options(opts) ⇒ Object



17
18
19
20
# File 'railties/lib/rails/test_unit/runner.rb', line 17

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
60
61
# File 'railties/lib/rails/test_unit/runner.rb', line 53

def compose_filter(runnable, filter)
  filter = escape_declarative_test_filter(filter)

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

.load_tests(argv) ⇒ Object



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

def load_tests(argv)
  patterns = extract_filters(argv)
  tests = list_tests(patterns)
  tests.to_a.each { |path| require File.expand_path(path) }
end

.parse_options(argv) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'railties/lib/rails/test_unit/runner.rb', line 22

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

.run(argv = []) ⇒ Object



41
42
43
44
45
# File 'railties/lib/rails/test_unit/runner.rb', line 41

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

  require "active_support/testing/autorun"
end

.run_from_rake(test_command, argv = []) ⇒ Object



35
36
37
38
39
# File 'railties/lib/rails/test_unit/runner.rb', line 35

def run_from_rake(test_command, argv = [])
  # Ensure the tests run during the Rake Task action, not when the process exits
  success = system("rails", test_command, *argv, *Shellwords.split(ENV["TESTOPTS"] || ""))
  success || exit(false)
end