Browse files

Solve the RAILS_ENV problem in the railties tests in a more generic way

  • Loading branch information...
1 parent e9b025e commit 6512af232c2d8e284030d859b12f5efa80f0f5ed @jonleighton jonleighton committed Jun 6, 2011
View
4 railties/test/application/configuration_test.rb
@@ -36,6 +36,10 @@ def setup
end
def teardown
+ teardown_app
+ end
+
+ def teardown
FileUtils.rm_rf(new_app) if File.directory?(new_app)
end
View
4 railties/test/application/console_test.rb
@@ -4,14 +4,12 @@ class ConsoleTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
- @prev_rails_env = ENV['RAILS_ENV']
- ENV['RAILS_ENV'] = 'development'
build_app
boot_rails
end
def teardown
- ENV['RAILS_ENV'] = @prev_rails_env
+ teardown_app
end
def load_environment(sandbox = false)
View
4 railties/test/application/generators_test.rb
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def app_const
@app_const ||= Class.new(Rails::Application)
end
View
6 railties/test/application/initializers/boot_test.rb
@@ -9,8 +9,12 @@ def setup
# boot_rails
end
+ def teardown
+ # teardown_app
+ end
+
test "booting rails sets the load paths correctly" do
# This test is pending reworking the boot process
end
end
-end
+end
View
4 railties/test/application/initializers/check_ruby_version_test.rb
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
test "rails initializes with ruby 1.8.7 or later, except for 1.9.1" do
if RUBY_VERSION < '1.8.7'
assert_rails_does_not_boot
View
4 railties/test/application/initializers/frameworks_test.rb
@@ -5,15 +5,13 @@ class FrameworlsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
- @prev_rails_env = ENV['RAILS_ENV']
- ENV['RAILS_ENV'] = 'development'
build_app
boot_rails
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
- ENV['RAILS_ENV'] = @prev_rails_env
+ teardown_app
end
# AC & AM
View
4 railties/test/application/initializers/hooks_test.rb
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def teardown
+ teardown_app
+ end
+
test "load initializers" do
app_file "config/initializers/foo.rb", "$foo = true"
require "#{app_path}/config/environment"
View
4 railties/test/application/initializers/i18n_test.rb
@@ -11,6 +11,10 @@ def setup
require "rails/all"
end
+ def teardown
+ teardown_app
+ end
+
def load_app
require "#{app_path}/config/environment"
end
View
4 railties/test/application/initializers/load_path_test.rb
@@ -5,15 +5,13 @@ class LoadPathTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
- @prev_rails_env = ENV['RAILS_ENV']
- ENV['RAILS_ENV'] = 'development'
build_app
boot_rails
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
- ENV['RAILS_ENV'] = @prev_rails_env
+ teardown_app
end
test "initializing an application adds the application paths to the load path" do
View
4 railties/test/application/initializers/notifications_test.rb
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def instrument(*args, &block)
ActiveSupport::Notifications.instrument(*args, &block)
end
View
4 railties/test/application/loading_test.rb
@@ -4,14 +4,12 @@ class LoadingTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def setup
- @prev_rails_env = ENV['RAILS_ENV']
- ENV['RAILS_ENV'] = 'development'
build_app
boot_rails
end
def teardown
- ENV['RAILS_ENV'] = @prev_rails_env
+ teardown_app
end
def app
View
4 railties/test/application/middleware_test.rb
@@ -11,6 +11,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end
View
4 railties/test/application/paths_test.rb
@@ -20,6 +20,10 @@ def setup
@paths = Rails.application.config.paths
end
+ def teardown
+ teardown_app
+ end
+
def root(*path)
app_path(*path).to_s
end
View
4 railties/test/application/rackup_test.rb
@@ -11,14 +11,12 @@ def rackup
end
def setup
- @prev_rails_env = ENV['RAILS_ENV']
- ENV['RAILS_ENV'] = 'development'
build_app
boot_rails
end
def teardown
- ENV['RAILS_ENV'] = @prev_rails_env
+ teardown_app
end
test "rails app is present" do
View
4 railties/test/application/rake_test.rb
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf("#{app_path}/config/environments")
end
+ def teardown
+ teardown_app
+ end
+
def test_gems_tasks_are_loaded_first_than_application_ones
app_file "lib/tasks/app.rake", <<-RUBY
$task_loaded = Rake::Task.task_defined?("db:create:all")
View
4 railties/test/application/routing_test.rb
@@ -39,6 +39,10 @@ def index
RUBY
end
+ def teardown
+ teardown_app
+ end
+
test "rails/info/properties in development" do
app("development")
get "/rails/info/properties"
View
4 railties/test/application/runner_test.rb
@@ -18,6 +18,10 @@ def self.count
MODEL
end
+ def teardown
+ teardown_app
+ end
+
def test_should_include_runner_in_shebang_line_in_help
assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help` }
end
View
4 railties/test/application/test_test.rb
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
test "truth" do
app_file 'test/unit/foo_test.rb', <<-RUBY
require 'test_helper'
View
8 railties/test/isolation/abstract_unit.rb
@@ -79,6 +79,8 @@ def assert_body(expected, resp)
module Generation
def build_app(options = {})
+ @prev_rails_env = ENV.delete('RAILS_ENV')
+
FileUtils.rm_rf(app_path)
FileUtils.cp_r(tmp_path('app_template'), app_path)
@@ -103,6 +105,12 @@ def build_app(options = {})
add_to_config 'config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"; config.active_support.deprecation = :log'
end
+ def teardown_app
+ ENV['RAILS_ENV'] = @prev_rails_env if @prev_rails_env
+ end
+
+ # Make a very basic app, without creating the whole directory structure.
+ # This is faster and simpler than the method above.
def make_basic_app
require "rails"
require "action_controller/railtie"
View
4 railties/test/railties/engine_test.rb
@@ -20,6 +20,10 @@ class Engine < ::Rails::Engine
end
end
+ def teardown
+ teardown_app
+ end
+
test "Rails::Engine itself does not respond to config" do
boot_rails
assert !Rails::Engine.respond_to?(:config)
View
6 railties/test/railties/plugin_ordering_test.rb
@@ -12,6 +12,10 @@ def setup
plugin "c_plugin", "$arr << :c"
end
+ def teardown
+ teardown_app
+ end
+
def boot_rails
super
require "#{app_path}/config/environment"
@@ -69,4 +73,4 @@ def boot_rails
assert $bar
end
end
-end
+end
View
4 railties/test/railties/plugin_test.rb
@@ -15,6 +15,10 @@ def setup
end
end
+ def teardown
+ teardown_app
+ end
+
test "Rails::Plugin itself does not respond to config" do
boot_rails
assert !Rails::Plugin.respond_to?(:config)
View
4 railties/test/railties/railtie_test.rb
@@ -11,6 +11,10 @@ def setup
require "rails/all"
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end

0 comments on commit 6512af2

Please sign in to comment.