Merge pull request #407 from hcatlin/master

Actions should obey options[:quiet]
This commit is contained in:
Scott Davis 2011-05-30 12:25:29 -07:00
commit 47ad8f17aa
2 changed files with 30 additions and 5 deletions

View File

@ -17,13 +17,14 @@ module Compass
# create a directory and all the directories necessary to reach it.
def directory(dir, options = nil)
options ||= self.options if self.respond_to?(:options)
options ||= {}
if File.exists?(dir) && File.directory?(dir)
# logger.record :exists, basename(dir) unless options[:quiet]
elsif File.exists?(dir)
msg = "#{basename(dir)} already exists and is not a directory."
raise Compass::FilesystemConflict.new(msg)
else
logger.record :directory, separate("#{basename(dir)}/")
logger.record(:directory, separate("#{basename(dir)}/")) unless options[:quiet]
FileUtils.mkdir_p(dir) unless options[:dry_run]
end
end
@ -37,16 +38,16 @@ module Compass
if File.exists?(file_name)
existing_contents = IO.read(file_name)
if existing_contents == contents
logger.record :identical, basename(file_name), extra
logger.record(:identical, basename(file_name), extra) unless options[:quiet]
skip_write = true
elsif options[:force]
logger.record :overwrite, basename(file_name), extra
logger.record(:overwrite, basename(file_name), extra) unless options[:quiet]
else
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
raise Compass::FilesystemConflict.new(msg)
end
else
logger.record :create, basename(file_name), extra
logger.record(:create, basename(file_name), extra) unless options[:quiet]
end
if skip_write
FileUtils.touch file_name unless options[:dry_run]
@ -67,7 +68,7 @@ module Compass
def remove(file_name)
if File.exists?(file_name)
File.unlink file_name
logger.record :remove, basename(file_name)
logger.record(:remove, basename(file_name)) unless options[:quiet]
end
end

View File

@ -0,0 +1,24 @@
require 'test_helper'
require 'compass'
class ActionsTest < Test::Unit::TestCase
class BaseActionExtender
include Compass::Actions
def options
@@options ||= {}
end
def working_path
"/tmp"
end
end
# When log4r is included, it sometimes breaks the Actions
def test_quiet_option
b = BaseActionExtender.new
b.logger = ""
b.options[:quiet] = true
# logger shouldn't be called... if it is, this will error
b.directory("/tmp/#{(rand * 1000000).to_i}")
end
end