diff options
Diffstat (limited to 'railties/test/commands')
-rw-r--r-- | railties/test/commands/console_test.rb | 24 | ||||
-rw-r--r-- | railties/test/commands/server_test.rb | 24 |
2 files changed, 14 insertions, 34 deletions
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 4062905c16..9e449856f4 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -1,14 +1,14 @@ require 'abstract_unit' +require 'env_helpers' require 'rails/commands/console' class Rails::ConsoleTest < ActiveSupport::TestCase + include EnvHelpers + class FakeConsole def self.start; end end - def setup - end - def test_sandbox_option console = Rails::Console.new(app, parse_arguments(["--sandbox"])) assert console.sandbox? @@ -85,7 +85,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase assert_match(/\sproduction\s/, output) end end - + def test_e_option start ['-e', 'special-production'] assert_match(/\sspecial-production\s/, output) @@ -133,20 +133,4 @@ class Rails::ConsoleTest < ActiveSupport::TestCase def parse_arguments(args) Rails::Console.parse_arguments(args) end - - def with_rails_env(env) - rails = ENV['RAILS_ENV'] - ENV['RAILS_ENV'] = env - yield - ensure - ENV['RAILS_ENV'] = rails - end - - def with_rack_env(env) - rack = ENV['RACK_ENV'] - ENV['RACK_ENV'] = env - with_rails_env(nil) { yield } - ensure - ENV['RACK_ENV'] = rack - end end diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index 6a75207ebb..cb57b3c0cd 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -1,7 +1,9 @@ require 'abstract_unit' +require 'env_helpers' require 'rails/commands/server' class Rails::ServerTest < ActiveSupport::TestCase + include EnvHelpers def test_environment_with_server_option args = ["thin", "-e", "production"] @@ -25,22 +27,16 @@ class Rails::ServerTest < ActiveSupport::TestCase end def test_environment_with_rails_env - rails = ENV['RAILS_ENV'] - ENV['RAILS_ENV'] = 'production' - server = Rails::Server.new - assert_equal 'production', server.options[:environment] - ensure - ENV['RAILS_ENV'] = rails + with_rails_env 'production' do + server = Rails::Server.new + assert_equal 'production', server.options[:environment] + end end def test_environment_with_rack_env - rack, rails = ENV['RACK_ENV'], ENV['RAILS_ENV'] - ENV['RAILS_ENV'] = nil - ENV['RACK_ENV'] = 'production' - server = Rails::Server.new - assert_equal 'production', server.options[:environment] - ensure - ENV['RACK_ENV'] = rack - ENV['RAILS_ENV'] = rails + with_rack_env 'production' do + server = Rails::Server.new + assert_equal 'production', server.options[:environment] + end end end |