1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

-e / --environment for the test runner.

This commit is contained in:
Yves Senn 2015-01-29 15:03:08 +01:00
parent f4ea8dda1b
commit 090c83672f
3 changed files with 22 additions and 2 deletions

View file

@ -1,5 +1,5 @@
ENV["RAILS_ENV"] = "test"
require "rails/test_unit/runner"
$: << File.expand_path("../../test", APP_PATH)
Rails::TestRunner.run(ARGV)

View file

@ -7,11 +7,16 @@ module Rails
class TestRunner
class Options
def self.parse(args)
options = { backtrace: false, name: nil }
options = { backtrace: false, name: nil, environment: "test" }
opt_parser = ::OptionParser.new do |opts|
opts.banner = "Usage: bin/rails test [options] [file or directory]"
opts.separator ""
opts.on("-e", "--environment [ENV]",
"run tests in the ENV environment") do |env|
options[:environment] = env.strip
end
opts.separator ""
opts.separator "Filter options:"
opts.separator ""
@ -70,6 +75,7 @@ module Rails
def run
$rails_test_runner = self
ENV["RAILS_ENV"] = @options[:environment]
run_tests
end

View file

@ -19,6 +19,16 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase
assert options[:backtrace]
end
test "tests run in the test environment by default" do
options = @options.parse([])
assert_equal "test", options[:environment]
end
test "can run in a specific environment" do
options = @options.parse(["-e development"])
assert_equal "development", options[:environment]
end
test "parse the filename and line" do
options = @options.parse(["foobar.rb:20"])
assert_equal File.expand_path("foobar.rb"), options[:filename]
@ -52,4 +62,8 @@ class TestUnitTestRunnerTest < ActiveSupport::TestCase
assert_nil options[:filename]
assert_nil options[:line]
end
test "run multiple files" do
skip "needs implementation"
end
end