提交 f5964955 编写于 作者: J José Valim

Tests for plugin generator.

上级 a748bb79
......@@ -71,7 +71,7 @@ def self.add_shebang_option!
# 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 @@ def self.add_test_framework_option!
begin
invoke name
rescue Thor::UndefinedTaskError
say "Could not find and invoke #{name}."
say "Could not find and invoke '#{name}'."
end
end
end
......
......@@ -25,7 +25,7 @@ def create_lib_files
directory 'lib'
end
add_test_framework_option!
add_and_invoke_test_framework_option!
def create_tasks_files
return unless options[:with_tasks]
......
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'
......
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
......
......@@ -2,12 +2,9 @@
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
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册