spec/mixlib/log_spec.rb in mixlib-log-1.1.0 vs spec/mixlib/log_spec.rb in mixlib-log-1.2.0
- old
+ new
@@ -27,15 +27,26 @@
before(:each) do
Logit.instance_variable_set("@logger",nil)
end
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
+ Tempfile.open("chef-test-log") do |tf|
+ lambda { Logit.init(STDOUT) }.should_not raise_error
+ lambda { Logit.init(tf) }.should_not raise_error
+ end
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)
+ Logit.fatal "FIRST"
+ first_logdev.string.should match(/FIRST/)
+ Logit.init(second_logdev)
+ Logit.fatal "SECOND"
+ first_logdev.string.should_not match(/SECOND/)
+ second_logdev.string.should match(/SECOND/)
+ end
it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
levels = {
:debug => Logger::DEBUG,
:info => Logger::INFO,
@@ -47,10 +58,18 @@
Logit.level = symbol
Logit.logger.level.should == constant
Logit.level.should == symbol
end
end
-
+
+ it "passes blocks to the underlying logger object" do
+ logdev = StringIO.new
+ Logit.init(logdev)
+ Logit.fatal { "the_message" }
+ logdev.string.should match(/the_message/)
+ end
+
+
it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
levels = {
:debug => Logger::DEBUG,
:info => Logger::INFO,
:warn => Logger::WARN,