spec/mixlib/log_spec.rb in mixlib-log-1.7.1 vs spec/mixlib/log_spec.rb in mixlib-log-2.0.0
- old
+ new
@@ -17,29 +17,39 @@
# limitations under the License.
#
require "tempfile"
require "stringio"
-require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
+require "spec_helper"
class LoggerLike
attr_accessor :level
- attr_reader :messages
+ attr_reader :messages, :data
def initialize
@messages = ""
+ @data = []
end
- [:debug, :info, :warn, :error, :fatal].each do |method_name|
+ def add_data(severity, message = nil, progname = nil, data: {})
+ @messages << message
+ @data << data
+ end
+
+ def add(severity, message = nil, progname = nil, data: {})
+ @messages << message
+ end
+
+ [:trace, :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
+RSpec.describe Mixlib::Log do
# Since we are testing class behaviour for an instance variable
# that gets set once, we need to reset it prior to each example [cb]
before(:each) do
Logit.reset!
@@ -62,10 +72,11 @@
end
it "uses the logger provided when initialized with a logger like object" do
logger = LoggerLike.new
Logit.init(logger)
+ Logit.level = :debug
Logit.debug "qux"
expect(logger.messages).to match(/qux/)
end
it "should re-initialize the logger if init is called again" do
@@ -82,17 +93,18 @@
it "knows that it's been configured" do
Logit.init
expect(Logit.configured?).to be true
end
- it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
+ it "should set the log level using the binding form, with :trace, :debug, :info, :warn, :error, or :fatal" do
levels = {
- :debug => Logger::DEBUG,
- :info => Logger::INFO,
- :warn => Logger::WARN,
- :error => Logger::ERROR,
- :fatal => Logger::FATAL,
+ :trace => Mixlib::Log::TRACE,
+ :debug => Mixlib::Log::DEBUG,
+ :info => Mixlib::Log::INFO,
+ :warn => Mixlib::Log::WARN,
+ :error => Mixlib::Log::ERROR,
+ :fatal => Mixlib::Log::FATAL,
}
levels.each do |symbol, constant|
Logit.level = symbol
expect(Logit.logger.level).to eq(constant)
expect(Logit.level).to eq(symbol)
@@ -104,16 +116,17 @@
Logit.init(logdev)
Logit.fatal { "the_message" }
expect(logdev.string).to match(/the_message/)
end
- it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
+ it "should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal" do
levels = {
- :debug => Logger::DEBUG,
- :info => Logger::INFO,
- :warn => Logger::WARN,
- :error => Logger::ERROR,
- :fatal => Logger::FATAL,
+ :trace => Mixlib::Log::TRACE,
+ :debug => Mixlib::Log::DEBUG,
+ :info => Mixlib::Log::INFO,
+ :warn => Mixlib::Log::WARN,
+ :error => Mixlib::Log::ERROR,
+ :fatal => Mixlib::Log::FATAL,
}
levels.each do |symbol, constant|
Logit.level(symbol)
expect(Logit.logger.level).to eq(constant)
end