summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2009-03-11 13:25:45 -0700
committerAdam Jacob <adam@hjksolutions.com>2009-03-11 13:25:45 -0700
commita136f9823b8b0fa01da4e758e64c89bbab0036dc (patch)
tree9eece42b81546f39e6fe460e093f41d646a285c4 /spec
downloadmixlib-log-a136f9823b8b0fa01da4e758e64c89bbab0036dc.tar.gz
Initial commit
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/log/formatter_spec.rb51
-rw-r--r--spec/mixlib/log_spec.rb62
-rw-r--r--spec/spec_helper.rb11
3 files changed, 124 insertions, 0 deletions
diff --git a/spec/mixlib/log/formatter_spec.rb b/spec/mixlib/log/formatter_spec.rb
new file mode 100644
index 0000000..909436a
--- /dev/null
+++ b/spec/mixlib/log/formatter_spec.rb
@@ -0,0 +1,51 @@
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'time'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Mixlib::Log::Formatter do
+ before(:each) do
+ @formatter = Mixlib::Log::Formatter.new
+ end
+
+ it "should print raw strings with msg2str(string)" do
+ @formatter.msg2str("nuthin new").should == "nuthin new"
+ end
+
+ it "should format exceptions properly with msg2str(e)" do
+ e = IOError.new("legendary roots crew")
+ @formatter.msg2str(e).should == "legendary roots crew (IOError)\n"
+ end
+
+ it "should format random objects via inspect with msg2str(Object)" do
+ @formatter.msg2str([ "black thought", "?uestlove" ]).should == '["black thought", "?uestlove"]'
+ end
+
+ it "should return a formatted string with call" do
+ time = Time.new
+ Mixlib::Log::Formatter.show_time = true
+ @formatter.call("monkey", time, "test", "mos def").should == "[#{time.rfc2822}] monkey: mos def\n"
+ end
+
+ it "should allow you to turn the time on and off in the output" do
+ Mixlib::Log::Formatter.show_time = false
+ @formatter.call("monkey", Time.new, "test", "mos def").should == "monkey: mos def\n"
+ end
+
+end \ No newline at end of file
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb
new file mode 100644
index 0000000..4621969
--- /dev/null
+++ b/spec/mixlib/log_spec.rb
@@ -0,0 +1,62 @@
+#
+# Author:: Adam Jacob (<adam@opscode.com>)
+# Copyright:: Copyright (c) 2008 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'tempfile'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+
+describe Mixlib::Log do
+
+ it "should accept regular options to Logger.new via init" do
+ tf = Tempfile.new("chef-test-log")
+ tf.open
+ lambda { Logit.init(STDOUT) }.should_not raise_error
+ lambda { Logit.init(tf) }.should_not raise_error
+ end
+
+ it "should set the log level with :debug, :info, :warn, :error, or :fatal" do
+ levels = {
+ :debug => Logger::DEBUG,
+ :info => Logger::INFO,
+ :warn => Logger::WARN,
+ :error => Logger::ERROR,
+ :fatal => Logger::FATAL
+ }
+ levels.each do |symbol, constant|
+ Logit.level(symbol)
+ Logit.logger.level.should == constant
+ end
+ end
+
+ it "should raise an ArgumentError if you try and set the level to something strange" do
+ lambda { Logit.level(:the_roots) }.should raise_error(ArgumentError)
+ end
+
+ it "should pass other method calls directly to logger" do
+ Logit.level(:debug)
+ Logit.should be_debug
+ lambda { Logit.debug("Gimme some sugar!") }.should_not raise_error
+ end
+
+ it "should default to STDOUT if init is called with no arguments" do
+ logger_mock = mock(Logger, :null_object => true)
+ Logger.stub!(:new).and_return(logger_mock)
+ Logger.should_receive(:new).with(STDOUT).and_return(logger_mock)
+ Logit.init
+ end
+
+end \ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..2680dba
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,11 @@
+$TESTING=true
+$:.push File.join(File.dirname(__FILE__), '..', 'lib')
+
+require 'mixlib/log'
+require 'mixlib/log/formatter'
+
+class Logit
+ class << self
+ include Mixlib::Log
+ end
+end \ No newline at end of file