summaryrefslogtreecommitdiff
path: root/spec/mixlib
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2011-03-17 09:13:33 -0700
committerDaniel DeLeo <dan@opscode.com>2011-03-17 09:13:33 -0700
commite80574b33439ffbcd20b8401a0ce0fa6acb63cb9 (patch)
treec543adec8ddbf3f3513f80211a5de3b342167fc0 /spec/mixlib
parentdc1c69935b1516e8f9bc7dd7c25dc234ba8e5740 (diff)
downloadmixlib-log-e80574b33439ffbcd20b8401a0ce0fa6acb63cb9.tar.gz
Add support for initializing Mixlib::Log with a logger
Diffstat (limited to 'spec/mixlib')
-rw-r--r--spec/mixlib/log_spec.rb40
1 files changed, 36 insertions, 4 deletions
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb
index 1d1c4f7..00307f2 100644
--- a/spec/mixlib/log_spec.rb
+++ b/spec/mixlib/log_spec.rb
@@ -21,6 +21,22 @@ require 'tempfile'
require 'stringio'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+class LoggerLike
+ attr_accessor :level
+ attr_reader :messages
+ def initialize
+ @messages = ""
+ end
+
+ [:debug, :info, :warn, :error, :fatal].each do |method_name|
+ class_eval(<<-E)
+ def #{method_name}(message)
+ @messages << message
+ end
+ E
+ end
+end
+
describe Mixlib::Log do
# Since we are testing class behaviour for an instance variable
@@ -29,13 +45,29 @@ describe Mixlib::Log do
Logit.reset!
end
- it "should accept regular options to Logger.new via init" do
- Tempfile.open("chef-test-log") do |tf|
- lambda { Logit.init(STDOUT) }.should_not raise_error
- lambda { Logit.init(tf) }.should_not raise_error
+ it "creates a logger using an IO object" do
+ io = StringIO.new
+ Logit.init(io)
+ Logit << "foo"
+ io.string.should match(/foo/)
+ end
+
+ it "creates a logger with a file name" do
+ Tempfile.open("chef-test-log") do |tempfile|
+ Logit.init(tempfile.path)
+ Logit << "bar"
+ tempfile.rewind
+ tempfile.read.should match(/bar/)
end
end
+ it "uses the logger provided when initialized with a logger like object" do
+ logger = LoggerLike.new
+ Logit.init(logger)
+ Logit.debug "qux"
+ logger.messages.should match(/qux/)
+ end
+
it "should re-initialize the logger if init is called again" do
first_logdev, second_logdev = StringIO.new, StringIO.new
Logit.init(first_logdev)