diff options
Diffstat (limited to 'railties/test/generators_test.rb')
-rw-r--r-- | railties/test/generators_test.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 7e6b7b183c..a8716d9992 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'generators', 'generators_test_helper') +require 'generators/generators_test_helper' require 'rails/generators/rails/model/model_generator' require 'rails/generators/test_unit/model/model_generator' require 'mocha' @@ -45,6 +45,12 @@ class GeneratorsTest < GeneratorsTestCase assert_equal "test_unit:generators:model", klass.namespace end + def test_find_by_namespace_with_duplicated_name + klass = Rails::Generators.find_by_namespace(:foobar) + assert klass + assert_equal "foobar:foobar", klass.namespace + end + def test_find_by_namespace_add_generators_to_raw_lookups klass = Rails::Generators.find_by_namespace("test_unit:model") assert klass @@ -80,7 +86,7 @@ class GeneratorsTest < GeneratorsTestCase Rails::Generators.instance_variable_set(:@load_paths, nil) spec = Gem::Specification.new - spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec')) + spec.expects(:full_gem_path).returns(File.join(Rails.root, 'vendor', 'another_gem_path', 'xspec')) Gem.expects(:respond_to?).with(:loaded_specs).returns(true) Gem.expects(:loaded_specs).returns(:spec => spec) @@ -101,13 +107,15 @@ class GeneratorsTest < GeneratorsTestCase def test_rails_generators_with_others_information output = capture(:stdout){ Rails::Generators.help }.split("\n").last - assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts, wrong.", output + assert_equal "Others: active_record:fixjour, fixjour, foobar, mspec, rails:javascripts.", output end def test_warning_is_shown_if_generator_cant_be_loaded + 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 + assert_match /Rails 2\.x generator/, output end def test_no_color_sets_proper_shell @@ -118,7 +126,7 @@ class GeneratorsTest < GeneratorsTestCase end def test_rails_root_templates - template = File.join(RAILS_ROOT, "lib", "templates", "active_record", "model", "model.rb") + template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb") # Create template mkdir_p(File.dirname(template)) @@ -158,10 +166,7 @@ class GeneratorsTest < GeneratorsTestCase Rails::Generators.options[:new_generator] = { :generate => false } klass = Class.new(Rails::Generators::Base) do - def self.name - "NewGenerator" - end - + def self.name() 'NewGenerator' end class_option :generate, :default => true end @@ -170,6 +175,6 @@ class GeneratorsTest < GeneratorsTestCase def test_source_paths_for_not_namespaced_generators mspec = Rails::Generators.find_by_namespace :mspec - assert mspec.source_paths.include?(File.join(RAILS_ROOT, "lib", "templates", "mspec")) + assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "mspec")) end end |