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

Change false to :verbose => false as in new Thor version.

上级 baa4781a
......@@ -16,12 +16,13 @@ module Actions
#
# apply "recipes/jquery.rb"
#
def apply(path, log_status=true)
def apply(path)
path = find_in_source_paths(path) unless path =~ /^http\:\/\//
log :apply, path, log_status
log :apply, path
shell.padding += 1
instance_eval(open(path).read)
log :applied, path, log_status
shell.padding -= 1
end
# Install a plugin. You must provide either a Subversion url or Git url.
......@@ -38,11 +39,11 @@ def plugin(name, options)
if options[:git] && options[:submodule]
in_root do
run "git submodule add #{options[:git]} vendor/plugins/#{name}", false
run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false
end
elsif options[:git] || options[:svn]
in_root do
run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", false
run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false
end
else
log "! no git or svn provided for #{name}. Skipping..."
......@@ -57,7 +58,7 @@ def plugin(name, options)
# gem "rspec", :env => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
#
def gem(name, options = {})
def gem(name, options={})
log :gem, name
env = options.delete(:env)
......@@ -82,10 +83,10 @@ def environment(data=nil, options={}, &block)
in_root do
if options[:env].nil?
inject_into_file 'config/environment.rb', "\n #{data}", { :after => sentinel }, false
inject_into_file 'config/environment.rb', "\n #{data}", :after => sentinel, :verbose => false
else
Array.wrap(options[:env]).each do|env|
append_file "config/environments/#{env}.rb", "\n#{data}", false
append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
end
end
end
......@@ -99,7 +100,7 @@ def environment(data=nil, options={}, &block)
# git :add => "this.file that.rb"
# git :add => "onefile.rb", :rm => "badfile.cxx"
#
def git(command = {})
def git(command={})
in_root do
if command.is_a?(Symbol)
run "git #{command}"
......@@ -125,7 +126,7 @@ def git(command = {})
#
def vendor(filename, data=nil, &block)
log :vendor, filename
create_file("vendor/#{filename}", data, false, &block)
create_file("vendor/#{filename}", data, :verbose => false, &block)
end
# Create a new file in the lib/ directory. Code can be specified
......@@ -141,7 +142,7 @@ def vendor(filename, data=nil, &block)
#
def lib(filename, data=nil, &block)
log :lib, filename
create_file("lib/#{filename}", data, false, &block)
create_file("lib/#{filename}", data, :verbose => false, &block)
end
# Create a new Rakefile with the provided code (either in a block or a string).
......@@ -164,7 +165,7 @@ def lib(filename, data=nil, &block)
#
def rakefile(filename, data=nil, &block)
log :rakefile, filename
create_file("lib/tasks/#{filename}", data, false, &block)
create_file("lib/tasks/#{filename}", data, :verbose => false, &block)
end
# Create a new initializer with the provided code (either in a block or a string).
......@@ -185,7 +186,7 @@ def rakefile(filename, data=nil, &block)
#
def initializer(filename, data=nil, &block)
log :initializer, filename
create_file("config/initializers/#{filename}", data, false, &block)
create_file("config/initializers/#{filename}", data, :verbose => false, &block)
end
# Generate something using a generator from Rails or a plugin.
......@@ -200,7 +201,7 @@ def generate(what, *args)
log :generate, what
argument = args.map {|arg| arg.to_s }.flatten.join(" ")
in_root { run_ruby_script("script/generate #{what} #{argument}", false) }
in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) }
end
# Runs the supplied rake task
......@@ -215,7 +216,7 @@ def rake(command, options={})
log :rake, command
env = options[:env] || 'development'
sudo = options[:sudo] && RUBY_PLATFORM !~ /mswin|mingw/ ? 'sudo ' : ''
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", false) }
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
end
# Just run the capify command in root
......@@ -226,7 +227,7 @@ def rake(command, options={})
#
def capify!
log :capify, ""
in_root { run("#{extify(:capify)} .", false) }
in_root { run("#{extify(:capify)} .", :verbose => false) }
end
# Add Rails to /vendor/rails
......@@ -237,7 +238,7 @@ def capify!
#
def freeze!(args = {})
log :vendor, "rails"
in_root { run("#{extify(:rake)} rails:freeze:edge", false) }
in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) }
end
# Make an entry in Rails routing file conifg/routes.rb
......@@ -251,7 +252,7 @@ def route(routing_code)
sentinel = "ActionController::Routing::Routes.draw do |map|"
in_root do
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel }, false
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
end
end
......
......@@ -22,7 +22,7 @@ def self.included(base) #:nodoc:
#
# migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb"
#
def migration_template(source, destination=nil, log_status=true)
def migration_template(source, destination=nil, config={})
destination = File.expand_path(destination || source, self.destination_root)
migration_dir = File.dirname(destination)
......@@ -37,7 +37,7 @@ def migration_template(source, destination=nil, log_status=true)
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
end
template(source, destination, log_status)
template(source, destination, config)
end
protected
......
......@@ -100,13 +100,13 @@ def create_log_files
inside "log" do
%w( server production development test ).each do |file|
create_file "#{file}.log"
chmod "#{file}.log", 0666, false
chmod "#{file}.log", 0666, :verbose => false
end
end
end
def create_public_files
directory "public", "public", false # Non-recursive. Do small steps, so anyone can overwrite it.
directory "public", "public", :recursive => false # Do small steps, so anyone can overwrite it.
end
def create_dispatch_files
......@@ -114,13 +114,13 @@ def create_dispatch_files
copy_file "dispatchers/config.ru", "config.ru"
template "dispatchers/dispatch.rb", "public/dispatch.rb"
chmod "public/dispatch.rb", 0755, false
chmod "public/dispatch.rb", 0755, :verbose => false
template "dispatchers/dispatch.rb", "public/dispatch.cgi"
chmod "public/dispatch.cgi", 0755, false
chmod "public/dispatch.cgi", 0755, :verbose => false
template "dispatchers/dispatch.fcgi", "public/dispatch.fcgi"
chmod "public/dispatch.fcgi", 0755, false
chmod "public/dispatch.fcgi", 0755, :verbose => false
end
def create_public_image_files
......@@ -138,7 +138,7 @@ def create_prototype_files
def create_script_files
directory "script"
chmod "script", 0755, false
chmod "script", 0755, :verbose => false
end
def create_test_files
......
......@@ -8,11 +8,11 @@ class PluginGenerator < NamedBase
check_class_collision
def create_root_files
directory '.', plugin_dir, false # non-recursive
directory '.', plugin_dir, :recursive => false
end
def create_lib_files
directory 'lib', plugin_dir('lib'), false # non-recursive
directory 'lib', plugin_dir('lib'), :recursive => false
end
def create_tasks_files
......
......@@ -164,8 +164,8 @@ def inside(dir='', &block)
# Same as inside, but log status and use padding.
#
def inside_with_padding(dir='', log_status=true, &block)
say_status :inside, dir, log_status
def inside_with_padding(dir='', config={}, &block)
say_status :inside, dir, config.fetch(:verbose, true)
shell.padding += 1
inside(dir, &block)
shell.padding -= 1
......@@ -182,17 +182,16 @@ def in_root
# ==== Parameters
# mode<Integer>:: the file mode
# path<String>:: the name of the file to change mode
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
# chmod "script/*", 0755
#
def chmod(path, mode, log_status=true)
def chmod(path, mode, config={})
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
say_status :chmod, relative_to_original_destination_root(path), log_status
say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true)
FileUtils.chmod_R(mode, path) unless options[:pretend]
end
......@@ -200,8 +199,7 @@ def chmod(path, mode, log_status=true)
#
# ==== Parameters
# command<String>:: the command to be executed.
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
......@@ -209,9 +207,10 @@ def chmod(path, mode, log_status=true)
# run('ln -s ~/edge rails')
# end
#
def run(command, log_status=true)
def run(command, config={})
return unless behavior == :invoke
say_status :run, "\"#{command}\" from #{relative_to_original_destination_root(destination_root, false)}", log_status
description = "#{command.inspect} from #{relative_to_original_destination_root(destination_root, false)}"
say_status :run, description, config.fetch(:verbose, true)
`#{command}` unless options[:pretend]
end
......@@ -219,12 +218,11 @@ def run(command, log_status=true)
#
# ==== Parameters
# command<String>:: the command to be executed.
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
def run_ruby_script(command, log_status=true)
def run_ruby_script(command, config={})
return unless behavior == :invoke
say_status File.basename(Thor::Util.ruby_command), command, log_status
say_status File.basename(Thor::Util.ruby_command), command, config.fetch(:verbose, true)
`#{Thor::Util.ruby_command} #{command}` unless options[:pretend]
end
......@@ -234,9 +232,8 @@ def run_ruby_script(command, log_status=true)
# ==== Parameters
# task<String>:: the task to be invoked
# args<Array>:: arguments to the task
# options<Hash>:: a hash with options used on invocation
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# options<Hash>:: give :verbose => false to not log the status. Other options
# are given as parameter to Thor.
#
# ==== Examples
#
......@@ -247,35 +244,33 @@ def run_ruby_script(command, log_status=true)
# #=> thor list --all --substring=rails
#
def thor(task, *args)
log_status = args.last.is_a?(Symbol) || [true, false].include?(args.last) ? args.pop : true
options = args.last.is_a?(Hash) ? args.pop : {}
config = args.last.is_a?(Hash) ? args.pop : {}
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
args.unshift task
args.push Thor::Options.to_switches(options)
args.push Thor::Options.to_switches(config)
command = args.join(' ').strip
say_status :thor, command, log_status
run "thor #{command}", false
say_status :thor, command, verbose
run "thor #{command}", :verbose => false
end
# Removes a file at the given location.
#
# ==== Parameters
# path<String>:: path of the file to be changed
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
# remove_file 'README'
# remove_file 'app/controllers/application_controller.rb'
#
def remove_file(path, log_status=true)
def remove_file(path, config={})
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
color = log_status.is_a?(Symbol) ? log_status : :red
say_status :remove, relative_to_original_destination_root(path), log_status
say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true)
::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path)
end
......@@ -285,8 +280,7 @@ def remove_file(path, log_status=true)
# path<String>:: path of the file to be changed
# flag<Regexp|String>:: the regexp or string to be replaced
# replacement<String>:: the replacement, can be also given as a block
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
......@@ -298,10 +292,10 @@ def remove_file(path, log_status=true)
#
def gsub_file(path, flag, *args, &block)
return unless behavior == :invoke
log_status = args.last.is_a?(Symbol) || [ true, false ].include?(args.last) ? args.pop : true
config = args.last.is_a?(Hash) ? args.pop : {}
path = File.expand_path(path, destination_root)
say_status :gsub, relative_to_original_destination_root(path), log_status
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
unless options[:pretend]
content = File.read(path)
......@@ -315,17 +309,16 @@ def gsub_file(path, flag, *args, &block)
# ==== Parameters
# path<String>:: path of the file to be changed
# data<String>:: the data to append to the file, can be also given as a block.
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
# append_file 'config/environments/test.rb', 'config.gem "rspec"'
#
def append_file(path, data=nil, log_status=true, &block)
def append_file(path, data=nil, config={}, &block)
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
say_status :append, relative_to_original_destination_root(path), log_status
say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true)
File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend]
end
......@@ -334,17 +327,16 @@ def append_file(path, data=nil, log_status=true, &block)
# ==== Parameters
# path<String>:: path of the file to be changed
# data<String>:: the data to prepend to the file, can be also given as a block.
# log_status<Boolean>:: if false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Example
#
# prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
#
def prepend_file(path, data=nil, log_status=true, &block)
def prepend_file(path, data=nil, config={}, &block)
return unless behavior == :invoke
path = File.expand_path(path, destination_root)
say_status :prepend, relative_to_original_destination_root(path), log_status
say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true)
unless options[:pretend]
content = data || block.call
......
......@@ -7,9 +7,9 @@ module Actions
# the destination is not given it's assumed to be equal to the source.
#
# ==== Parameters
# source<String>:: the relative path to the source root
# destination<String>:: the relative path to the destination root
# log_status<Boolean>:: if false, does not log the status. True by default.
# source<String>:: the relative path to the source root.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Examples
#
......@@ -17,8 +17,8 @@ module Actions
#
# copy_file "doc/README"
#
def copy_file(source, destination=nil, log_status=true)
action CopyFile.new(self, source, destination || source, log_status)
def copy_file(source, destination=nil, config={})
action CopyFile.new(self, source, destination || source, config)
end
class CopyFile < Templater #:nodoc:
......
......@@ -9,7 +9,7 @@ module Actions
# ==== Parameters
# destination<String>:: the relative path to the destination root.
# data<String|NilClass>:: the data to append to the file.
# log_status<Boolean>:: if false, does not log the status. True by default.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Examples
#
......@@ -20,8 +20,8 @@ module Actions
#
# create_file "config/apach.conf", "your apache config"
#
def create_file(destination, data=nil, log_status=true, &block)
action CreateFile.new(self, destination, block || data.to_s, log_status)
def create_file(destination, data=nil, config={}, &block)
action CreateFile.new(self, destination, block || data.to_s, config)
end
alias :add_file :create_file
......@@ -31,8 +31,8 @@ def create_file(destination, data=nil, log_status=true, &block)
class CreateFile < Templater #:nodoc:
attr_reader :data
def initialize(base, destination, data, log_status)
super(base, nil, destination, log_status)
def initialize(base, destination, data, config={})
super(base, nil, destination, config)
@data = data
end
......
......@@ -30,30 +30,27 @@ module Actions
# blog.rb
#
# ==== Parameters
# source<String>:: the relative path to the source root
# destination<String>:: the relative path to the destination root
# recursive<Boolean>:: if the directory must be copied recursively, true by default
# log_status<Boolean>:: if false, does not log the status. True by default.
# source<String>:: the relative path to the source root.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
# If :recursive => false, does not look for paths recursively.
#
# ==== Examples
#
# directory "doc"
# directory "doc", "docs", false
# directory "doc", "docs", :recursive => false
#
def directory(source, destination=nil, recursive=true, log_status=true)
action Directory.new(self, source, destination || source, recursive, log_status)
def directory(source, destination=nil, config={})
action Directory.new(self, source, destination || source, config)
end
class Directory < Templater #:nodoc:
attr_reader :recursive
def initialize(base, source, destination=nil, recursive=true, log_status=true)
@recursive = recursive
super(base, source, destination, log_status)
def initialize(base, source, destination=nil, config={})
super(base, source, destination, { :recursive => true }.merge(config))
end
def invoke!
base.empty_directory given_destination, @log_status
base.empty_directory given_destination, config
execute!
end
......@@ -64,7 +61,7 @@ def revoke!
protected
def execute!
lookup = recursive ? File.join(source, '**') : source
lookup = config[:recursive] ? File.join(source, '**') : source
lookup = File.join(lookup, '{*,.[a-z]*}')
Dir[lookup].each do |file_source|
......@@ -73,11 +70,11 @@ def execute!
case file_source
when /\.empty_directory$/
base.empty_directory(File.dirname(file_destination), @log_status)
base.empty_directory(File.dirname(file_destination), config)
when /\.tt$/
base.template(file_source, file_destination[0..-4], @log_status)
base.template(file_source, file_destination[0..-4], config)
else
base.copy_file(file_source, file_destination, @log_status)
base.copy_file(file_source, file_destination, config)
end
end
end
......
......@@ -6,21 +6,21 @@ module Actions
# Creates an empty directory.
#
# ==== Parameters
# destination<String>:: the relative path to the destination root
# log_status<Boolean>:: if false, does not log the status. True by default.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Examples
#
# empty_directory "doc"
#
def empty_directory(destination, log_status=true)
action EmptyDirectory.new(self, nil, destination, log_status)
def empty_directory(destination, config={})
action EmptyDirectory.new(self, nil, destination, config)
end
class EmptyDirectory < Templater #:nodoc:
def invoke!
invoke_with_options!(base.options) do
invoke_with_options!(base.options.merge(config)) do
::FileUtils.mkdir_p(destination)
end
end
......
......@@ -9,9 +9,9 @@ module Actions
# the url is yielded and used as location.
#
# ==== Parameters
# source<String>:: the address of the given content
# destination<String>:: the relative path to the destination root
# log_status<Boolean>:: if false, does not log the status. True by default.
# source<String>:: the address of the given content.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Examples
#
......@@ -21,8 +21,8 @@ module Actions
# content.split("\n").first
# end
#
def get(source, destination=nil, log_status=true, &block)
action Get.new(self, source, block || destination, log_status)
def get(source, destination=nil, config={}, &block)
action Get.new(self, source, block || destination, config)
end
class Get < Templater #:nodoc:
......
......@@ -9,9 +9,8 @@ module Actions
# ==== Parameters
# destination<String>:: Relative path to the destination root
# data<String>:: Data to add to the file. Can be given as a block.
# flag<String>:: Flag of where to add the changes.
# log_status<Boolean>:: If false, does not log the status. True by default.
# If a symbol is given, uses it as the output color.
# config<Hash>:: give :verbose => false to not log the status and the flag
# for injection (:after or :before).
#
# ==== Examples
#
......@@ -24,28 +23,29 @@ module Actions
#
def inject_into_file(destination, *args, &block)
if block_given?
data, flag = block, args.shift
data, config = block, args.shift
else
data, flag = args.shift, args.shift
data, config = args.shift, args.shift
end
log_status = args.empty? || args.pop
action InjectIntoFile.new(self, destination, data, flag, log_status)
action InjectIntoFile.new(self, destination, data, config)
end
class InjectIntoFile #:nodoc:
attr_reader :base, :destination, :relative_destination, :flag, :replacement
attr_reader :base, :destination, :relative_destination, :flag, :replacement, :config
def initialize(base, destination, data, flag, log_status=true)
@base, @log_status = base, log_status
behavior, @flag = flag.keys.first, flag.values.first
def initialize(base, destination, data, config)
@base, @config = base, { :verbose => true }.merge(config)
self.destination = destination
data = data.call if data.is_a?(Proc)
@replacement = if behavior == :after
@replacement = if @config.key?(:after)
@flag = @config.delete(:after)
@flag + data
else
@flag = @config.delete(:before)
data + @flag
end
end
......@@ -75,7 +75,7 @@ def destination=(destination)
# Shortcut to say_status shell method.
#
def say_status(status)
base.shell.say_status status, relative_destination, @log_status
base.shell.say_status status, relative_destination, config[:verbose]
end
# Adds the content to the file.
......
......@@ -9,9 +9,9 @@ module Actions
# to be equal to the source removing .tt from the filename.
#
# ==== Parameters
# source<String>:: the relative path to the source root
# destination<String>:: the relative path to the destination root
# log_status<Boolean>:: if false, does not log the status. True by default.
# source<String>:: the relative path to the source root.
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
#
# ==== Examples
#
......@@ -19,9 +19,9 @@ module Actions
#
# template "doc/README"
#
def template(source, destination=nil, log_status=true)
def template(source, destination=nil, config={})
destination ||= source.gsub(/.tt$/, '')
action Template.new(self, source, destination, log_status)
action Template.new(self, source, destination, config)
end
class Template < Templater #:nodoc:
......
......@@ -8,7 +8,7 @@ module Actions
# by Jonas Nicklas and Michael S. Klishin under MIT LICENSE.
#
class Templater #:nodoc:
attr_reader :base, :source, :destination, :given_destination, :relative_destination
attr_reader :base, :source, :destination, :given_destination, :relative_destination, :config
# Initializes given the source and destination.
#
......@@ -16,11 +16,10 @@ class Templater #:nodoc:
# base<Thor::Base>:: A Thor::Base instance
# source<String>:: Relative path to the source of this file
# destination<String>:: Relative path to the destination of this file
# log_status<Boolean>:: If false, does not log the status. True by default.
# Templater log status does not accept color.
# config<Hash>:: give :verbose => false to not log the status.
#
def initialize(base, source, destination, log_status=true)
@base, @log_status = base, log_status
def initialize(base, source, destination, config={})
@base, @config = base, { :verbose => true }.merge(config)
self.source = source
self.destination = destination
end
......@@ -56,7 +55,7 @@ def identical?
# but you can modify in the subclass.
#
def invoke!
invoke_with_options!(base.options) do
invoke_with_options!(base.options.merge(config)) do
::FileUtils.mkdir_p(::File.dirname(destination))
::File.open(destination, 'w'){ |f| f.write render }
end
......@@ -187,7 +186,7 @@ def force_on_collision?
# Shortcut to say_status shell method.
#
def say_status(status, color)
base.shell.say_status status, relative_destination, color if @log_status
base.shell.say_status status, relative_destination, color if config[:verbose]
end
end
......
......@@ -20,6 +20,17 @@ def test_apply_loads_and_evaluates_a_template
assert_equal generator.instance_variable_get("@foo"), "FOO"
end
def test_apply_uses_padding_in_the_applied_template
template = <<-TEMPLATE
say_status :cool, :padding
TEMPLATE
template.instance_eval "def read; self; end"
generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template)
content = action(:apply, "http://gist.github.com/103208.txt")
assert_match /cool padding/, content
end
def test_create_file_should_write_data_to_file_path
action :create_file, 'lib/test_file.rb', 'heres test data'
assert_file 'lib/test_file.rb', 'heres test data'
......@@ -31,17 +42,17 @@ def test_create_file_should_write_block_contents_to_file_path
end
def test_plugin_with_git_option_should_run_plugin_install
generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", false)
generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", :verbose => false)
action :plugin, 'restful-authentication', :git => @git_plugin_uri
end
def test_plugin_with_svn_option_should_run_plugin_install
generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", false)
generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", :verbose => false)
action :plugin, 'restful-authentication', :svn => @svn_plugin_uri
end
def test_plugin_with_git_option_and_submodule_should_use_git_scm
generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", false)
generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", :verbose => false)
action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true
end
......@@ -135,32 +146,32 @@ def test_initializer_should_write_date_to_file_in_config_initializers
end
def test_generate_should_run_script_generate_with_argument_and_options
generator.expects(:run_ruby_script).once.with('script/generate model MyModel', false)
generator.expects(:run_ruby_script).once.with('script/generate model MyModel', :verbose => false)
action :generate, 'model', 'MyModel'
end
def test_rake_should_run_rake_command_with_development_env
generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', false)
generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', :verbose => false)
action :rake, 'log:clear'
end
def test_rake_with_env_option_should_run_rake_command_in_env
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', false)
generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false)
action :rake, 'log:clear', :env => 'production'
end
def test_rake_with_sudo_option_should_run_rake_command_with_sudo
generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', false)
generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false)
action :rake, 'log:clear', :sudo => true
end
def test_capify_should_run_the_capify_command
generator.expects(:run).once.with('capify .', false)
generator.expects(:run).once.with('capify .', :verbose => false)
action :capify!
end
def test_freeze_should_freeze_rails_edge
generator.expects(:run).once.with('rake rails:freeze:edge', false)
generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false)
action :freeze!
end
......
......@@ -125,7 +125,8 @@ def test_shebang_when_is_the_same_as_default_use_env
end
def test_rails_is_frozen
generator(:freeze => true, :database => "sqlite3").expects(:run).with("rake rails:freeze:edge", false)
generator(:freeze => true, :database => "sqlite3").expects(:run).
with("rake rails:freeze:edge", :verbose => false)
silence(:stdout){ generator.invoke }
assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/
end
......
......@@ -13,6 +13,7 @@
require 'generators'
CURRENT_PATH = File.expand_path(Dir.pwd)
Rails::Generators.no_color!
class GeneratorsTestCase < Test::Unit::TestCase
include FileUtils
......
......@@ -117,12 +117,6 @@ def test_scaffold_on_revoke
assert_file "public/stylesheets/scaffold.css"
end
def test_invoke_output
output = run_generator
assert_match /invoke.{4} active_record/, output
assert_match /create.{4} app\/models\/product_line\.rb/, output
end
protected
def run_generator(config={})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册