1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Tests for plugin generator.

This commit is contained in:
José Valim 2009-06-25 10:18:00 +02:00
parent a748bb7961
commit f596495556
6 changed files with 61 additions and 11 deletions

View file

@ -71,7 +71,7 @@ module Rails
# Small macro to add test_framework option and invoke it.
#
def self.add_test_framework_option!
def self.add_and_invoke_test_framework_option!
class_option :test_framework, :type => :string, :aliases => "-t", :default => "test_unit",
:desc => "Test framework to be invoked by this generator", :banner => "NAME"
@ -82,7 +82,7 @@ module Rails
begin
invoke name
rescue Thor::UndefinedTaskError
say "Could not find and invoke #{name}."
say "Could not find and invoke '#{name}'."
end
end
end

View file

@ -25,7 +25,7 @@ module Rails
directory 'lib'
end
add_test_framework_option!
add_and_invoke_test_framework_option!
def create_tasks_files
return unless options[:with_tasks]

View file

@ -1,7 +1,8 @@
require 'abstract_unit'
require 'generators/generator_test_helper'
require 'generators/generators_test_helper'
require 'generators/rails/app/app_generator'
class ActionsTest < GeneratorTestCase
class ActionsTest < GeneratorsTestCase
def setup
super
@git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git'

View file

@ -1,7 +1,8 @@
require 'abstract_unit'
require 'generators/generator_test_helper'
require 'generators/generators_test_helper'
require 'generators/rails/app/app_generator'
class AppTest < GeneratorTestCase
class AppGeneratorTest < GeneratorsTestCase
def test_application_skeleton_is_created
run_generator

View file

@ -2,12 +2,9 @@ require 'test/unit'
require 'fileutils'
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
# For this while, let's load all generators by hand
require 'generators'
require 'generators/rails/app/app_generator'
class GeneratorTestCase < Test::Unit::TestCase
class GeneratorsTestCase < Test::Unit::TestCase
include FileUtils
def destination_root

View file

@ -0,0 +1,51 @@
require 'abstract_unit'
require 'generators/generators_test_helper'
require 'generators/rails/plugin/plugin_generator'
require 'generators/test_unit/plugin/plugin_generator'
class PluginGeneratorTest < GeneratorsTestCase
def test_plugin_skeleton_is_created
run_generator
%w(
vendor/plugins
vendor/plugins/plugin_fu
vendor/plugins/plugin_fu/lib
).each{ |path| assert_file path }
end
def test_invokes_default_test_framework
run_generator
assert_file "vendor/plugins/plugin_fu/test/plugin_fu_test.rb"
end
def test_logs_if_the_test_framework_cannot_be_found
content = run_generator ["--test-framework=unknown"]
assert_match /Could not find and invoke 'unknown:generators:plugin'/, content
end
def test_creates_tasks_if_required
run_generator ["--with-tasks"]
assert_file "vendor/plugins/plugin_fu/tasks/plugin_fu_tasks.rake"
end
def test_creates_generator_if_required
run_generator ["--with-generator"]
assert_file "vendor/plugins/plugin_fu/generators/plugin_fu/templates"
flag = /class PluginFuGenerator < Rails::Generators::NamedBase/
assert_file "vendor/plugins/plugin_fu/generators/plugin_fu/plugin_fu_generator.rb", flag
end
protected
def run_generator(args=[])
silence(:stdout) { Rails::Generators::PluginGenerator.start ["plugin_fu"].concat(args), :root => destination_root }
end
def generator(options={})
@generator ||= Rails::Generators::PluginGenerator.new(["plugin_fu"], options, :root => destination_root)
end
end