From d226f17507805c145cc7a1727d46714b88910094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 3 Nov 2009 00:08:33 -0200 Subject: Ensure that generators can be invoked from any directory. Signed-off-by: Engine Yard --- railties/test/generators/generators_test_helper.rb | 15 ++++++++++----- railties/test/generators_test.rb | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index ccf08c347c..fdf6b4041f 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -1,8 +1,14 @@ # TODO: Fix this RAILS_ENV stuff -RAILS_ENV = 'test' - +RAILS_ENV = 'test' unless defined?(RAILS_ENV) require 'abstract_unit' -Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) + +module Rails + def self.root + @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures')) + end +end +Rails.application.config.root = Rails.root + require 'rails/generators' require 'rubygems' require 'active_record' @@ -15,8 +21,7 @@ class GeneratorsTestCase < Test::Unit::TestCase include FileUtils def destination_root - @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__), - '..', 'fixtures', 'tmp')) + File.join(Rails.root, "tmp") end def setup diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 178b5ef6de..8f1984c7d2 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -105,7 +105,7 @@ class GeneratorsTest < GeneratorsTestCase end def test_warning_is_shown_if_generator_cant_be_loaded - Rails::Generators.load_paths << File.expand_path("../fixtures/vendor/gems/gems/wrong", __FILE__) + Rails::Generators.load_paths << File.join(Rails.root, "vendor", "gems", "gems", "wrong") output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) } assert_match /\[WARNING\] Could not load generator at/, output assert_match /Error: uninitialized constant Rails::Generator/, output -- cgit v1.2.3