Permalink
Browse files

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

  • Loading branch information...
1 parent 2d3ba54 commit 62570e8626c67f9d38b28246304b938aab9d9fbe @jonleighton jonleighton committed Jun 6, 2011
Showing with 117 additions and 22 deletions.
  1. +4 −0 railties/test/application/assets_test.rb
  2. +4 −0 railties/test/application/configuration_test.rb
  3. +2 −4 railties/test/application/console_test.rb
  4. +4 −0 railties/test/application/generators_test.rb
  5. +5 −1 railties/test/application/initializers/boot_test.rb
  6. +4 −0 railties/test/application/initializers/check_ruby_version_test.rb
  7. +1 −3 railties/test/application/initializers/frameworks_test.rb
  8. +4 −0 railties/test/application/initializers/hooks_test.rb
  9. +4 −0 railties/test/application/initializers/i18n_test.rb
  10. +1 −3 railties/test/application/initializers/load_path_test.rb
  11. +4 −0 railties/test/application/initializers/notifications_test.rb
  12. +1 −3 railties/test/application/loading_test.rb
  13. +4 −0 railties/test/application/middleware/best_practices_test.rb
  14. +4 −0 railties/test/application/middleware/cache_test.rb
  15. +4 −0 railties/test/application/middleware/remote_ip_test.rb
  16. +4 −0 railties/test/application/middleware/sendfile_test.rb
  17. +4 −0 railties/test/application/middleware/show_exceptions_test.rb
  18. +5 −1 railties/test/application/middleware_test.rb
  19. +4 −0 railties/test/application/paths_test.rb
  20. +4 −0 railties/test/application/rack/logger_test.rb
  21. +1 −3 railties/test/application/rackup_test.rb
  22. +5 −1 railties/test/application/rake_test.rb
  23. +4 −0 railties/test/application/routing_test.rb
  24. +4 −0 railties/test/application/runner_test.rb
  25. +4 −0 railties/test/application/test_test.rb
  26. +6 −0 railties/test/isolation/abstract_unit.rb
  27. +4 −0 railties/test/railties/engine_test.rb
  28. +5 −2 railties/test/railties/mounted_engine_test.rb
  29. +5 −1 railties/test/railties/plugin_ordering_test.rb
  30. +4 −0 railties/test/railties/plugin_test.rb
  31. +4 −0 railties/test/railties/railtie_test.rb
@@ -11,6 +11,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end
@@ -34,6 +34,10 @@ def setup
FileUtils.rm_rf("#{app_path}/config/environments")
end
+ def teardown
+ teardown_app
+ end
+
@mike-burns

mike-burns Jun 6, 2011

Double definition of #teardown.

@jonleighton

jonleighton Jun 6, 2011

Member

Thanks for spotting.

def teardown
FileUtils.rm_rf(new_app) if File.directory?(new_app)
end
@@ -1,17 +1,15 @@
require 'isolation/abstract_unit'
class ConsoleTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
+ 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)
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def app_const
@app_const ||= Class.new(Rails::Application)
end
@@ -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
@@ -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
@@ -5,15 +5,13 @@ class FrameworksTest < 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
@@ -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"
@@ -11,6 +11,10 @@ def setup
require "rails/all"
end
+ def teardown
+ teardown_app
+ end
+
def load_app
require "#{app_path}/config/environment"
end
@@ -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
@@ -9,6 +9,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def instrument(*args, &block)
ActiveSupport::Notifications.instrument(*args, &block)
end
@@ -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
@@ -12,6 +12,10 @@ def setup
simple_controller
end
+ def teardown
+ teardown_app
+ end
+
test "simple controller in production mode returns best standards" do
get '/foo'
assert_equal "IE=Edge,chrome=1", last_response.headers["X-UA-Compatible"]
@@ -11,6 +11,10 @@ def setup
extend Rack::Test::Methods
end
+ def teardown
+ teardown_app
+ end
+
def simple_controller
controller :expires, <<-RUBY
class ExpiresController < ApplicationController
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end
@@ -10,6 +10,10 @@ def setup
FileUtils.rm_rf "#{app_path}/config/environments"
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= Rails.application
end
@@ -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
@@ -200,4 +204,4 @@ def middleware
AppTemplate::Application.middleware.map(&:klass).map(&:name)
end
end
-end
+end
@@ -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
@@ -14,6 +14,10 @@ def setup
super
end
+ def teardown
+ teardown_app
+ end
+
def logs
@logs ||= @logger.logged(:info)
end
@@ -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
@@ -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")
@@ -113,7 +117,7 @@ def test_loading_specific_fixtures
end
require "#{rails_root}/config/environment"
-
+
# loading a specific fixture
errormsg = Dir.chdir(app_path) { `rake db:fixtures:load FIXTURES=products` }
assert $?.success?, errormsg
@@ -11,6 +11,10 @@ def setup
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
test "rails/info/properties in development" do
app("development")
get "/rails/info/properties"
@@ -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
@@ -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'
@@ -91,6 +91,8 @@ def assert_body(expected, resp)
module Generation
# Build an application by invoking the generator and going through the whole stack.
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)
@@ -115,6 +117,10 @@ 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
@@ -25,6 +25,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)
@@ -106,6 +106,10 @@ def polymorphic_route
boot_rails
end
+ def teardown
+ teardown_app
+ end
+
def app
@app ||= begin
require "#{app_path}/config/environment"
@@ -116,7 +120,7 @@ def app
def reset_script_name!
Rails.application.routes.default_url_options = {}
end
-
+
def script_name(script_name)
Rails.application.routes.default_url_options = {:script_name => script_name}
end
@@ -171,4 +175,3 @@ def script_name(script_name)
end
end
end
-
@@ -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
Oops, something went wrong.

0 comments on commit 62570e8

Please sign in to comment.