aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/commands/server_test.rb
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2016-11-06 06:52:17 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2016-12-24 12:08:33 +0900
commit654704247eba742e139cfaa8d1385f13605d9e12 (patch)
tree8e8f803aab4723bea9cced7632f13e93ecac69e0 /railties/test/commands/server_test.rb
parent4e73ffa9b45904492815f8f67d4695ef719e0350 (diff)
downloadrails-654704247eba742e139cfaa8d1385f13605d9e12.tar.gz
rails-654704247eba742e139cfaa8d1385f13605d9e12.tar.bz2
rails-654704247eba742e139cfaa8d1385f13605d9e12.zip
use Thor option parser in server commands parse
The `ServerCommand` inherits Thor, but currently does not use Thor option parser. Therefore, if leave the argument of Thor as it is, it becomes an error by the argument checking of Thor. To avoid it, to use the Thor option parser instead of reimplementing it. Fixes #26964
Diffstat (limited to 'railties/test/commands/server_test.rb')
-rw-r--r--railties/test/commands/server_test.rb79
1 files changed, 43 insertions, 36 deletions
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index 391886bf33..dd5ff08921 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -7,31 +7,35 @@ class Rails::ServerTest < ActiveSupport::TestCase
include EnvHelpers
def test_environment_with_server_option
- args = ["thin", "-e", "production"]
- options = Rails::Server::Options.new.parse!(args)
+ args = ["thin", "-e", "production"]
+ options = parse_arguments(args)
assert_equal "production", options[:environment]
assert_equal "thin", options[:server]
end
def test_environment_without_server_option
- args = ["-e", "production"]
- options = Rails::Server::Options.new.parse!(args)
+ args = ["-e", "production"]
+ options = parse_arguments(args)
assert_equal "production", options[:environment]
assert_nil options[:server]
end
def test_server_option_without_environment
- args = ["thin"]
- options = Rails::Server::Options.new.parse!(args)
- assert_nil options[:environment]
- assert_equal "thin", options[:server]
+ args = ["thin"]
+ with_rack_env nil do
+ with_rails_env nil do
+ options = parse_arguments(args)
+ assert_equal "development", options[:environment]
+ assert_equal "thin", options[:server]
+ end
+ end
end
def test_environment_with_rails_env
with_rack_env nil do
with_rails_env "production" do
- server = Rails::Server.new
- assert_equal "production", server.options[:environment]
+ options = parse_arguments
+ assert_equal "production", options[:environment]
end
end
end
@@ -39,40 +43,39 @@ class Rails::ServerTest < ActiveSupport::TestCase
def test_environment_with_rack_env
with_rails_env nil do
with_rack_env "production" do
- server = Rails::Server.new
- assert_equal "production", server.options[:environment]
+ options = parse_arguments
+ assert_equal "production", options[:environment]
end
end
end
def test_environment_with_port
switch_env "PORT", "1234" do
- server = Rails::Server.new
- assert_equal 1234, server.options[:Port]
+ options = parse_arguments
+ assert_equal 1234, options[:Port]
end
end
def test_environment_with_host
switch_env "HOST", "1.2.3.4" do
- server = Rails::Server.new
- assert_equal "1.2.3.4", server.options[:Host]
+ options = parse_arguments
+ assert_equal "1.2.3.4", options[:Host]
end
end
def test_caching_without_option
args = []
- options = Rails::Server::Options.new.parse!(args)
- merged_options = Rails::Server.new.default_options.merge(options)
- assert_equal nil, merged_options[:caching]
+ options = parse_arguments(args)
+ assert_equal nil, options[:caching]
end
def test_caching_with_option
args = ["--dev-caching"]
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal true, options[:caching]
args = ["--no-dev-caching"]
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal false, options[:caching]
end
@@ -80,38 +83,38 @@ class Rails::ServerTest < ActiveSupport::TestCase
with_rack_env nil do
with_rails_env nil do
args = []
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal true, options[:log_stdout]
args = ["-e", "development"]
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal true, options[:log_stdout]
args = ["-e", "production"]
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal false, options[:log_stdout]
with_rack_env "development" do
args = []
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal true, options[:log_stdout]
end
with_rack_env "production" do
args = []
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal false, options[:log_stdout]
end
with_rails_env "development" do
args = []
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal true, options[:log_stdout]
end
with_rails_env "production" do
args = []
- options = Rails::Server::Options.new.parse!(args)
+ options = parse_arguments(args)
assert_equal false, options[:log_stdout]
end
end
@@ -119,25 +122,29 @@ class Rails::ServerTest < ActiveSupport::TestCase
end
def test_default_options
- server = Rails::Server.new
- old_default_options = server.default_options
+ old_default_options = parse_arguments
Dir.chdir("..") do
- assert_equal old_default_options, server.default_options
+ default_options = parse_arguments
+ assert_equal old_default_options, default_options
end
end
def test_restart_command_contains_customized_options
original_args = ARGV.dup
- args = ["-p", "4567"]
+ args = %w(-p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C)
ARGV.replace args
- options = Rails::Server::Options.new.parse! args
- server = Rails::Server.new options
- expected = "bin/rails server -p 4567"
+ options = parse_arguments(args)
+ expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C"
- assert_equal expected, server.default_options[:restart_cmd]
+ assert_equal expected, options[:restart_cmd]
ensure
ARGV.replace original_args
end
+
+ private
+ def parse_arguments(args = [])
+ Rails::Command::ServerCommand.new([], args).server_options
+ end
end