spec/mixlib/log_spec.rb in mixlib-log-2.0.3 vs spec/mixlib/log_spec.rb in mixlib-log-2.0.4
- old
+ new
@@ -172,13 +172,14 @@
it "should close File logger" do
opened_files_count_before = 0
ObjectSpace.each_object(File) do |f|
opened_files_count_before += 1 unless f.closed?
end
- Logit.init("/tmp/logger.log")
- Logit.init("/tmp/logger.log")
- Logit.init("/tmp/logger.log")
+ name = File.join(Dir.tmpdir, "logger.log")
+ Logit.init(name)
+ Logit.init(name)
+ Logit.init(name)
opened_files_count_after = 0
ObjectSpace.each_object(File) do |f|
opened_files_count_after += 1 unless f.closed?
end
expect(opened_files_count_after).to eq(opened_files_count_before + 1)
@@ -187,19 +188,20 @@
it "should not close IO logger" do
opened_files_count_before = 0
ObjectSpace.each_object(File) do |f|
opened_files_count_before += 1 unless f.closed?
end
- file = File.open("/tmp/logger.log")
- Logit.init(file)
- Logit.init(file)
- Logit.init(file)
- opened_files_count_after = 0
- ObjectSpace.each_object(File) do |f|
- opened_files_count_after += 1 unless f.closed?
+ Tempfile.open("chef-test-log") do |file|
+ Logit.init(file)
+ Logit.init(file)
+ Logit.init(file)
+ opened_files_count_after = 0
+ ObjectSpace.each_object(File) do |f|
+ opened_files_count_after += 1 unless f.closed?
+ end
+ expect(opened_files_count_after).to eq(opened_files_count_before + 1)
end
- expect(opened_files_count_after).to eq(opened_files_count_before + 1)
end
it "should return nil from its logging methods" do
expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object }
Logit.init
@@ -217,6 +219,16 @@
it "should set metadata correctly" do
Logit.metadata = { test: "data" }
expect(Logit.metadata).to eql({ test: "data" })
end
+ it "should format :trace level messages with TRACE: label" do
+ logdev = StringIO.new
+ Logit.init(logdev)
+ Logit.level = :trace
+ Logit.trace("this is a log message")
+ aggregate_failures do
+ expect(logdev.string).to_not match(/ANY:/)
+ expect(logdev.string).to match(/TRACE:/)
+ end
+ end
end