spec/timber/logger_spec.rb in timber-1.1.14 vs spec/timber/logger_spec.rb in timber-2.0.0
- old
+ new
@@ -56,21 +56,21 @@
expect(io.string).to start_with("select * from users @metadata {\"level\":\"info\",\"dt\":\"2016-09-01T12:00:00.000000Z\",")
expect(io.string).to include("\"event\":{\"server_side_app\":{\"sql_query\":{\"sql\":\"select * from users\",\"time_ms\":56.0}}}")
end
it "should allow :time_ms" do
- logger.info(message: "event complete", time_ms: 54.5)
+ logger.info("event complete", time_ms: 54.5)
expect(io.string).to include("\"time_ms\":54.5")
end
it "should allow :tag" do
- logger.info(message: "event complete", tag: "tag1")
+ logger.info("event complete", tag: "tag1")
expect(io.string).to include("\"tags\":[\"tag1\"]")
end
it "should allow :tags" do
- logger.info(message: "event complete", tags: ["tag1", "tag2"])
+ logger.info("event complete", tags: ["tag1", "tag2"])
expect(io.string).to include("\"tags\":[\"tag1\",\"tag2\"]")
end
it "should allow functions" do
logger.info do
@@ -117,19 +117,55 @@
end
end
end
describe "#formatter=" do
+ it "should not allow changing the formatter when the device is HTTP" do
+ http_device = Timber::LogDevices::HTTP.new("api_key")
+ logger = Timber::Logger.new(http_device)
+ expect { logger.formatter = ::Logger::Formatter.new }.to raise_error(ArgumentError)
+ end
+
+ it "should set the formatter" do
+ logger = Timber::Logger.new(STDOUT)
+ formatter = ::Logger::Formatter.new
+ logger.formatter = formatter
+ expect(logger.formatter).to eq(formatter)
+ end
+ end
+
+ describe "#info" do
let(:io) { StringIO.new }
let(:logger) { Timber::Logger.new(io) }
- it "should not allow non Timber::Logger::Formatter formatters" do
- logger.formatter = ::Logger::Formatter.new
- expect(logger.formatter).to be_kind_of(::Timber::Logger::HybridFormatter)
+ it "should allow default usage" do
+ logger.info("message")
+ expect(io.string).to start_with("message @metadata")
+ expect(io.string).to include('"level":"info"')
end
- it "should allow Timber::Logger::Formatter formatters" do
- logger.formatter = ::Timber::Logger::JSONFormatter.new
- expect(logger.formatter).to be_kind_of(::Timber::Logger::JSONFormatter)
+ it "should allow messages with options" do
+ logger.info("message", tag: "tag")
+ expect(io.string).to start_with("message @metadata")
+ expect(io.string).to include('"level":"info"')
+ expect(io.string).to include('"tags":["tag"]')
+ end
+ end
+
+ describe "#error" do
+ let(:io) { StringIO.new }
+ let(:logger) { Timber::Logger.new(io) }
+
+ it "should allow default usage" do
+ logger.error("message")
+ expect(io.string).to start_with("message @metadata")
+ expect(io.string).to include('"level":"error"')
+ end
+
+ it "should allow messages with options" do
+ logger.error("message", tag: "tag")
+ expect(io.string).to start_with("message @metadata")
+ expect(io.string).to include('"level":"error"')
+ expect(io.string).to include('"tags":["tag"]')
end
end
end
\ No newline at end of file