diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/initializer/check_ruby_version_test.rb | 10 | ||||
-rw-r--r-- | railties/test/initializer/install_gem_spec_stubs_test.rb | 85 | ||||
-rw-r--r-- | railties/test/initializer/path_test.rb | 10 | ||||
-rw-r--r-- | railties/test/initializer/test_helper.rb | 24 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 2 | ||||
-rw-r--r-- | railties/test/plugin_test_helper.rb | 2 |
6 files changed, 113 insertions, 20 deletions
diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 12503fb481..33de653906 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -1,12 +1,4 @@ -require 'abstract_unit' -require 'active_support/ruby/shim' -require 'initializer' - -RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") - -module Rails - def self.vendor_rails? ; false ; end -end +require "initializer/test_helper" module InitializerTests class PathsTest < ActiveSupport::TestCase diff --git a/railties/test/initializer/install_gem_spec_stubs_test.rb b/railties/test/initializer/install_gem_spec_stubs_test.rb new file mode 100644 index 0000000000..2e94c9968f --- /dev/null +++ b/railties/test/initializer/install_gem_spec_stubs_test.rb @@ -0,0 +1,85 @@ +require "initializer/test_helper" + +module InitializerTests + class GemSpecStubsTest < ActiveSupport::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 + + 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 db62796ea5..26f796f93d 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -1,12 +1,4 @@ -require 'abstract_unit' -require 'active_support/ruby/shim' -require 'initializer' - -RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") - -module Rails - def self.vendor_rails? ; false ; end -end +require "initializer/test_helper" class PathsTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation diff --git a/railties/test/initializer/test_helper.rb b/railties/test/initializer/test_helper.rb new file mode 100644 index 0000000000..ddb03397ab --- /dev/null +++ b/railties/test/initializer/test_helper.rb @@ -0,0 +1,24 @@ +require 'abstract_unit' +require 'active_support/ruby/shim' +require 'initializer' + +RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") + +module Rails + class << self + attr_accessor :vendor_rails + def vendor_rails?() @vendor_rails end + end +end + +class ActiveSupport::TestCase + def assert_stderr(match) + $stderr = StringIO.new + yield + $stderr.rewind + err = $stderr.read + assert_match match, err + ensure + $stderr = STDERR + end +end
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 5caa5858a4..550cb7de76 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -178,7 +178,7 @@ class ConfigurationFrameworkPathsTests < Test::Unit::TestCase end end -require File.dirname(__FILE__) + '/plugin_test_helper' +require 'plugin_test_helper' class InitializerPluginLoadingTests < Test::Unit::TestCase def setup diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 55d1a1fa96..893095fa66 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -4,7 +4,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" require 'test/unit' require 'active_support' require 'initializer' -require File.join(File.dirname(__FILE__), 'abstract_unit') +require 'abstract_unit' # We need to set RAILS_ROOT if it isn't already set RAILS_ROOT = '.' unless defined?(RAILS_ROOT) |