From a60624d6c08af9ed7e514ed8b4f87c8915c8bb55 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 09:16:15 +0200 Subject: Clean up engine's generator test and use bundle exec for invoking generators --- railties/test/engine/generators_test.rb | 43 +++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb index f335c16a8c..bda1f0a23b 100644 --- a/railties/test/engine/generators_test.rb +++ b/railties/test/engine/generators_test.rb @@ -1,5 +1,3 @@ -# require 'isolation/abstract_unit' - require 'fileutils' require 'test/unit' @@ -16,20 +14,24 @@ require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kerne require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" module EngineTests - class ControllerGenerator < Rails::Generators::TestCase + class GeneratorTest < Rails::Generators::TestCase include ActiveSupport::Testing::Isolation - + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) self.destination_root = File.join(TMP_PATH, "foo_bar") def tmp_path(*args) File.join(TMP_PATH, *args) end - + def engine_path tmp_path('foo_bar') end + def bundle_exec(cmd) + `bundle exec rails #{cmd}` + end + def rails(cmd) environment = File.expand_path('../../../../load_paths', __FILE__) if File.exist?("#{environment}.rb") @@ -37,29 +39,44 @@ module EngineTests end `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` end - + def build_engine FileUtils.mkdir_p(engine_path) FileUtils.rm_r(engine_path) - + rails("plugin new #{engine_path} --full --mountable") + + Dir.chdir(engine_path) do + File.open("Gemfile", "w") do |f| + f.write <<-GEMFILE.gsub(/^ {12}/, '') + source "http://rubygems.org" + + gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}' + gem 'sqlite3' + + if RUBY_VERSION < '1.9' + gem "ruby-debug", ">= 0.10.3" + end + GEMFILE + end + end end def setup build_engine end - + def test_controllers_are_correctly_namespaced Dir.chdir(engine_path) do - rails("g controller topics") - assert_file "app/controllers/foo_bar/topics_controller.rb" + bundle_exec("g controller topics") + assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ end end - + def test_models_are_correctly_namespaced Dir.chdir(engine_path) do - rails("g model topic") - assert_file "app/models/foo_bar/topic.rb" + bundle_exec("g model topic") + assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ end end end -- cgit v1.2.3