From 3bf3ddac725bdaebb883d0b1a4a39b96715780b1 Mon Sep 17 00:00:00 2001 From: Hampton Catlin Date: Mon, 30 May 2011 16:17:28 +0100 Subject: [PATCH] Following a similar API to how the Complier works, don't log anything (don't even load up the logger!) if we pass in the :quiet option. I need this because of some conflicts with Compass::Logger, being referred to as "Logger", which seemed to be pulling out the main Logger. This is a seperate issue, but making this options[:quiet] API functional is a nice work-around that keeps things from getting too messy. Tests included, obviously. --- lib/compass/actions.rb | 10 +++++----- test/units/actions_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 test/units/actions_test.rb diff --git a/lib/compass/actions.rb b/lib/compass/actions.rb index 926482f0..3e956a0d 100644 --- a/lib/compass/actions.rb +++ b/lib/compass/actions.rb @@ -24,7 +24,7 @@ module Compass 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 @@ -38,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] @@ -68,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 diff --git a/test/units/actions_test.rb b/test/units/actions_test.rb new file mode 100644 index 00000000..21b26414 --- /dev/null +++ b/test/units/actions_test.rb @@ -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 \ No newline at end of file