Skip to content

Commit

Permalink
Solve the RAILS_ENV problem in the railties tests in a more generic way
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Jun 6, 2011
1 parent e9b025e commit 6512af2
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 17 deletions.
4 changes: 4 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -35,6 +35,10 @@ def setup
FileUtils.rm_rf("#{app_path}/config/environments")
end

def teardown
teardown_app
end

def teardown
FileUtils.rm_rf(new_app) if File.directory?(new_app)
end
Expand Down
4 changes: 1 addition & 3 deletions railties/test/application/console_test.rb
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/generators_test.rb
Expand Up @@ -9,6 +9,10 @@ def setup
boot_rails
end

def teardown
teardown_app
end

def app_const
@app_const ||= Class.new(Rails::Application)
end
Expand Down
6 changes: 5 additions & 1 deletion railties/test/application/initializers/boot_test.rb
Expand Up @@ -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
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions railties/test/application/initializers/frameworks_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/initializers/hooks_test.rb
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/initializers/i18n_test.rb
Expand Up @@ -11,6 +11,10 @@ def setup
require "rails/all"
end

def teardown
teardown_app
end

def load_app
require "#{app_path}/config/environment"
end
Expand Down
4 changes: 1 addition & 3 deletions railties/test/application/initializers/load_path_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/initializers/notifications_test.rb
Expand Up @@ -9,6 +9,10 @@ def setup
boot_rails
end

def teardown
teardown_app
end

def instrument(*args, &block)
ActiveSupport::Notifications.instrument(*args, &block)
end
Expand Down
4 changes: 1 addition & 3 deletions railties/test/application/loading_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/middleware_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/paths_test.rb
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions railties/test/application/rackup_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/rake_test.rb
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/routing_test.rb
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/runner_test.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions railties/test/application/test_test.rb
Expand Up @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions railties/test/isolation/abstract_unit.rb
Expand Up @@ -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)

Expand All @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions railties/test/railties/engine_test.rb
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion railties/test/railties/plugin_ordering_test.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -69,4 +73,4 @@ def boot_rails
assert $bar
end
end
end
end
4 changes: 4 additions & 0 deletions railties/test/railties/plugin_test.rb
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions railties/test/railties/railtie_test.rb
Expand Up @@ -11,6 +11,10 @@ def setup
require "rails/all"
end

def teardown
teardown_app
end

def app
@app ||= Rails.application
end
Expand Down

0 comments on commit 6512af2

Please sign in to comment.