From 378a65a909439ebca909125fdfada23ed89cec63 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 2 Jul 2009 17:52:46 -0700 Subject: Added tests for the :install_gem_spec_stubs initializer --- .../initializer/install_gem_spec_stubs_test.rb | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 railties/test/initializer/install_gem_spec_stubs_test.rb (limited to 'railties/test/initializer/install_gem_spec_stubs_test.rb') 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 -- cgit v1.2.3