Permalink
Browse files

Make namespaced_generators_test pass

  • Loading branch information...
Rafael Mendonça França
Rafael Mendonça França committed Nov 27, 2012
1 parent 31a68c1 commit a259cf09ccc9785d9d097006b263d8f5975304ce
@@ -1,3 +1,5 @@
+require 'rails'
+
module Rails
module Generators
class ObserverGenerator < NamedBase #metagenerator
@@ -1,7 +1,54 @@
+require 'minitest/autorun'
+
+require 'fileutils'
+
+require 'rails/all'
+require 'rails/generators'
+require 'rails/generators/test_case'
+
+module Rails
+ def self.root
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
+ end
+end
+
+module TestApp
+ class Application < Rails::Application
+ end
+end
+
+# Call configure to load the settings from
+# Rails.application.config.generators to Rails::Generators
+Rails.application.load_generators
+
+module GeneratorsTestHelper
+ def self.included(base)
+ base.class_eval do
+ destination File.join(Rails.root, "tmp")
+ setup :prepare_destination
+
+ def teardown
+ FileUtils.rm_rf(File.join(Rails.root, "tmp"))
+ end
+
+ begin
+ base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ''))
+ rescue
+ end
+ end
+ end
+end
+
require 'rails/generators/rails/observer/observer_generator'
-class NamespacedObserverGeneratorTest < NamespacedGeneratorTestCase
+class NamespacedObserverGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
+
+ def setup
+ super
+ Rails::Generators.namespace = TestApp
+ end
+
arguments %w(account)
tests Rails::Generators::ObserverGenerator
@@ -20,4 +67,3 @@ def test_invokes_default_test_framework
assert_file "test/unit/test_app/account_observer_test.rb", /module TestApp/, / class AccountObserverTest < ActiveSupport::TestCase/
end
end
-

0 comments on commit a259cf0

Please sign in to comment.