aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2009-09-29 16:07:29 -0700
committerCarl Lerche <carllerche@mac.com>2009-09-29 16:07:29 -0700
commit6b086449bebc4ecbd11887c74f0c16c0c38089dc (patch)
treea586d299fc4f08ba301da36622272b8a6f13633a
parent6f6a589d4b564f5db78735ad0c7225c22ced57ac (diff)
downloadrails-6b086449bebc4ecbd11887c74f0c16c0c38089dc.tar.gz
rails-6b086449bebc4ecbd11887c74f0c16c0c38089dc.tar.bz2
rails-6b086449bebc4ecbd11887c74f0c16c0c38089dc.zip
Fix the broken railties isolation tests
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb13
-rw-r--r--railties/lib/rails/application.rb6
-rw-r--r--railties/test/application/load_test.rb21
-rw-r--r--railties/test/boot_test.rb4
-rw-r--r--railties/test/initializer/check_ruby_version_test.rb7
-rw-r--r--railties/test/initializer/install_gem_spec_stubs_test.rb86
-rw-r--r--railties/test/initializer/path_test.rb32
-rw-r--r--railties/test/isolation/abstract_unit.rb38
8 files changed, 86 insertions, 121 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index 30e194536b..cdd6d5f49b 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -31,10 +31,15 @@ module ActiveSupport
@_result = result
- proxy = run_in_isolation do |proxy|
- super(proxy) { }
+ serialized = run_in_isolation do |proxy|
+ begin
+ super(proxy) { }
+ rescue Exception => e
+ proxy.add_error(Test::Unit::Error.new(name, e))
+ end
end
+ proxy = Marshal.load(serialized)
proxy.__replay__(@_result)
yield(Test::Unit::TestCase::FINISHED, name)
@@ -55,7 +60,7 @@ module ActiveSupport
write.close
result = read.read
Process.wait2(pid)
- Marshal.load(result.unpack("m")[0])
+ return result.unpack("m")[0]
end
end
@@ -83,7 +88,7 @@ module ActiveSupport
ENV.delete("ISOLATION_TEST")
ENV.delete("ISOLATION_OUTPUT")
- return Marshal.load(tmpfile.read.unpack("m")[0])
+ return tmpfile.read.unpack("m")[0]
end
end
end
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index cadfc5010b..c70365e2f8 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -1,14 +1,14 @@
module Rails
class Application
- attr_accessor :routes, :config
+ attr_accessor :config
def self.load(environment_file)
environment = File.read(environment_file)
Object.class_eval(environment, environment_file)
end
- def initialize
- @routes = ActionController::Routing::Routes
+ def routes
+ ActionController::Routing::Routes
end
def middleware
diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb
index f2041d54c2..079aa09460 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -1,17 +1,32 @@
require "isolation/abstract_unit"
-require "rails"
-require 'action_dispatch'
+# require "rails"
+# require 'action_dispatch'
module ApplicationTests
class LoadTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
def rackup
- ActionDispatch::Utils.parse_config("#{app_path}/config.ru")
+ config = "#{app_path}/config.ru"
+ # Copied from ActionDispatch::Utils.parse_config
+ # ActionDispatch is not necessarily available at this point.
+ require 'rack'
+ if config =~ /\.ru$/
+ cfgfile = ::File.read(config)
+ if cfgfile[/^#\\(.*)/]
+ opts.parse! $1.split(/\s+/)
+ end
+ inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
+ nil, config
+ else
+ require config
+ inner_app = Object.const_get(::File.basename(config, '.rb').capitalize)
+ end
end
def setup
build_app
+ boot_rails
end
test "rails app is present" do
diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb
index 5b567e657c..f8f6d8f225 100644
--- a/railties/test/boot_test.rb
+++ b/railties/test/boot_test.rb
@@ -62,7 +62,7 @@ class VendorBootTest < Test::Unit::TestCase
def test_load_initializer_requires_from_vendor_rails
boot = VendorBoot.new
- boot.expects(:require).with("rails/initializer")
+ boot.expects(:require).with("rails")
Rails::Initializer.expects(:run).with(:install_gem_spec_stubs)
Rails::GemDependency.expects(:add_frozen_gem_path)
boot.load_initializer
@@ -76,7 +76,7 @@ class GemBootTest < Test::Unit::TestCase
boot = GemBoot.new
GemBoot.expects(:load_rubygems)
boot.expects(:load_rails_gem)
- boot.expects(:require).with('rails/initializer')
+ boot.expects(:require).with('rails')
boot.load_initializer
end
diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb
index 68feba058e..1852fea4df 100644
--- a/railties/test/initializer/check_ruby_version_test.rb
+++ b/railties/test/initializer/check_ruby_version_test.rb
@@ -1,9 +1,14 @@
-require "initializer/test_helper"
+require "isolation/abstract_unit"
module InitializerTests
class PathsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
+ def setup
+ build_app
+ boot_rails
+ end
+
test "rails does not initialize with ruby version 1.8.1" do
assert_rails_does_not_boot "1.8.1"
end
diff --git a/railties/test/initializer/install_gem_spec_stubs_test.rb b/railties/test/initializer/install_gem_spec_stubs_test.rb
deleted file mode 100644
index cfb12d7405..0000000000
--- a/railties/test/initializer/install_gem_spec_stubs_test.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require "initializer/test_helper"
-
-module InitializerTests
- class GemSpecStubsTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Isolation
-
- def setup
- $stderr = StringIO.new
- end
-
- test "user has an old boot.rb (defined by having no Rails.vendor_rails?)" do
- class << Rails
- undef vendor_rails?
- end
-
- assert_stderr(/outdated/) do
- assert_raises(SystemExit) do
- Rails::Initializer.run { |c| c.frameworks = [] }
- end
- end
- end
-
- test "requires rubygems" do
- Kernel.module_eval do
- alias old_require require
- def require(name)
- $rubygems_required = true if name == "rubygems"
- old_require(name)
- end
- end
-
- Rails.vendor_rails = true
- Rails::Initializer.run { |c| c.frameworks = [] }
- assert $rubygems_required
- end
-
- # Pending until we're further along
- # test "does not fail if rubygems does not exist" do
- # Kernel.module_eval do
- # alias old_require require
- # def require(name)
- # raise LoadError if name == "rubygems"
- # old_require(name)
- # end
- # end
- #
- # assert_nothing_raised do
- # Rails::Initializer.run { |c| c.frameworks = [] }
- # end
- # end
-
- test "adds fake Rubygems stubs if a framework is not loaded in Rubygems and we've vendored" do
- Rails.vendor_rails = true
-
- Rails::Initializer.run { |c| c.frameworks = [] }
-
- %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub|
- gem_spec = Gem.loaded_specs[stub]
- assert_equal Gem::Version.new(Rails::VERSION::STRING), gem_spec.version
- assert_equal stub, gem_spec.name
- assert_equal "", gem_spec.loaded_from
- end
- end
-
- test "doesn't replace gem specs that are already loaded" do
- Rails.vendor_rails = true
-
- Gem.loaded_specs["rails"] = Gem::Specification.new do |s|
- s.name = "rails"
- s.version = Rails::VERSION::STRING
- s.loaded_from = "/foo/bar/baz"
- end
-
- Rails::Initializer.run { |c| c.frameworks = [] }
-
- assert_equal "/foo/bar/baz", Gem.loaded_specs["rails"].loaded_from
-
- %w(activesupport activerecord actionpack actionmailer activeresource).each do |stub|
- gem_spec = Gem.loaded_specs[stub]
- assert_equal Gem::Version.new(Rails::VERSION::STRING), gem_spec.version
- assert_equal stub, gem_spec.name
- assert_equal "", gem_spec.loaded_from
- end
- end
- end
-end \ No newline at end of file
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb
index f3d70ad4ca..a4264bc31c 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -1,29 +1,36 @@
-require "initializer/test_helper"
+require "isolation/abstract_unit"
class PathsTest < Test::Unit::TestCase
include ActiveSupport::Testing::Isolation
- def self.setup
+ def setup
+ build_app
+ boot_rails
Rails::Initializer.run do |config|
config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record]
config.after_initialize do
ActionController::Base.session_store = nil
end
end
- end
-
- def setup
@paths = Rails::Initializer.default.config.paths
end
def root(*path)
- File.expand_path(File.join(File.dirname(__FILE__), "root", *path))
+ app_path(*path).to_s
end
def assert_path(paths, *dir)
assert_equal [root(*dir)], paths.paths
end
+ def assert_in_load_path(*path)
+ assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
+ end
+
+ def assert_not_in_load_path(*path)
+ assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
+ end
+
test "booting up Rails yields a valid paths object" do
assert_path @paths.app, "app"
assert_path @paths.app.metals, "app", "metal"
@@ -39,8 +46,7 @@ class PathsTest < Test::Unit::TestCase
assert_path @paths.config.locales, "config", "locales"
assert_path @paths.config.environments, "config", "environments"
- assert_equal Pathname.new(File.dirname(__FILE__)).join("root", "app", "controllers").expand_path,
- Pathname.new(@paths.app.controllers.to_a.first).expand_path
+ assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first
assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path,
Pathname.new(@paths.app.controllers.to_a[1]).expand_path
end
@@ -56,24 +62,16 @@ class PathsTest < Test::Unit::TestCase
assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob
end
- def assert_in_load_path(*path)
- assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
- end
-
- def assert_not_in_load_path(*path)
- assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----"
- end
-
test "load path includes each of the paths in config.paths as long as the directories exist" do
assert_in_load_path "app"
assert_in_load_path "app", "controllers"
- assert_in_load_path "app", "metal"
assert_in_load_path "app", "models"
assert_in_load_path "app", "helpers"
assert_in_load_path "lib"
assert_in_load_path "vendor"
assert_not_in_load_path "app", "views"
+ assert_not_in_load_path "app", "metal"
assert_not_in_load_path "app", "services"
assert_not_in_load_path "config"
assert_not_in_load_path "config", "locales"
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index d3fc1f3395..bc1b43acaa 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -14,10 +14,6 @@ require 'test/unit'
# TODO: Remove setting this magic constant
RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
-# These load paths usually get set inside of boot.rb
-$:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib"
-$:.unshift "#{RAILS_FRAMEWORK_ROOT}/actionpack/lib"
-
# These files do not require any others and are needed
# to run the tests
require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation"
@@ -71,8 +67,23 @@ module TestHelpers
end
module Generation
- def build_app
+ def build_app(options = {})
+ FileUtils.rm_rf(app_path)
FileUtils.cp_r(tmp_path('app_template'), app_path)
+
+ # Delete the initializers unless requested
+ unless options[:initializers]
+ Dir["#{app_path}/config/initializers/*.rb"].each do |initializer|
+ File.delete(initializer)
+ end
+ end
+
+ environment = File.read("#{app_path}/config/environment.rb")
+ if environment =~ /(\n\s*end\s*)\Z/
+ File.open("#{app_path}/config/environment.rb", 'w') do |f|
+ f.puts $` + %'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n' + $1
+ end
+ end
end
def app_file(path, contents)
@@ -84,6 +95,23 @@ module TestHelpers
def controller(name, contents)
app_file("app/controllers/#{name}_controller.rb", contents)
end
+
+ def boot_rails
+ # return if defined?(RAILS)
+ # TODO: Get this working with boot.rb
+ $:.unshift "#{RAILS_FRAMEWORK_ROOT}/railties/lib"
+ Object.class_eval <<-RUBY
+ RAILS_ROOT = "#{app_path}"
+ module ::Rails
+ def self.vendor_rails?
+ true
+ end
+ end
+ RUBY
+ require "rails"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
+ end
end
end