1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

This commit is contained in:
Jon Leighton 2011-06-06 13:54:05 +01:00
parent 2d3ba54b86
commit 62570e8626
31 changed files with 117 additions and 22 deletions

View file

@ -11,6 +11,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end

View file

@ -34,6 +34,10 @@ module ApplicationTests
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

View file

@ -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 file

@ -9,6 +9,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
def app_const
@app_const ||= Class.new(Rails::Application)
end

View file

@ -9,6 +9,10 @@ module ApplicationTests
# 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

View file

@ -9,6 +9,10 @@ module ApplicationTests
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 file

@ -5,15 +5,13 @@ module ApplicationTests
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 file

@ -10,6 +10,10 @@ module ApplicationTests
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 file

@ -11,6 +11,10 @@ module ApplicationTests
require "rails/all"
end
def teardown
teardown_app
end
def load_app
require "#{app_path}/config/environment"
end

View file

@ -5,15 +5,13 @@ module ApplicationTests
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 file

@ -9,6 +9,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
def instrument(*args, &block)
ActiveSupport::Notifications.instrument(*args, &block)
end

View file

@ -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 file

@ -12,6 +12,10 @@ module ApplicationTests
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"]

View file

@ -11,6 +11,10 @@ module ApplicationTests
extend Rack::Test::Methods
end
def teardown
teardown_app
end
def simple_controller
controller :expires, <<-RUBY
class ExpiresController < ApplicationController

View file

@ -10,6 +10,10 @@ module ApplicationTests
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end

View file

@ -10,6 +10,10 @@ module ApplicationTests
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end

View file

@ -10,6 +10,10 @@ module ApplicationTests
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end

View file

@ -11,6 +11,10 @@ module ApplicationTests
FileUtils.rm_rf "#{app_path}/config/environments"
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end

View file

@ -20,6 +20,10 @@ module ApplicationTests
@paths = Rails.application.config.paths
end
def teardown
teardown_app
end
def root(*path)
app_path(*path).to_s
end

View file

@ -14,6 +14,10 @@ module ApplicationTests
super
end
def teardown
teardown_app
end
def logs
@logs ||= @logger.logged(:info)
end

View file

@ -11,14 +11,12 @@ module ApplicationTests
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 file

@ -10,6 +10,10 @@ module ApplicationTests
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 file

@ -11,6 +11,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
test "rails/info/properties in development" do
app("development")
get "/rails/info/properties"

View file

@ -18,6 +18,10 @@ module ApplicationTests
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 file

@ -9,6 +9,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
test "truth" do
app_file 'test/unit/foo_test.rb', <<-RUBY
require 'test_helper'

View file

@ -91,6 +91,8 @@ module TestHelpers
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 @@ module TestHelpers
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

View file

@ -25,6 +25,10 @@ module RailtiesTest
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 file

@ -106,6 +106,10 @@ module ApplicationTests
boot_rails
end
def teardown
teardown_app
end
def app
@app ||= begin
require "#{app_path}/config/environment"
@ -171,4 +175,3 @@ module ApplicationTests
end
end
end

View file

@ -12,6 +12,10 @@ module RailtiesTest
plugin "c_plugin", "$arr << :c"
end
def teardown
teardown_app
end
def boot_rails
super
require "#{app_path}/config/environment"

View file

@ -15,6 +15,10 @@ module RailtiesTest
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 file

@ -11,6 +11,10 @@ module RailtiesTest
require "rails/all"
end
def teardown
teardown_app
end
def app
@app ||= Rails.application
end