spec/unit/hanami/config/logger_spec.rb in hanami-2.0.0.beta4 vs spec/unit/hanami/config/logger_spec.rb in hanami-2.0.0.rc1

- old
+ new

@@ -2,30 +2,23 @@ require "hanami/config/logger" require "hanami/slice_name" require "dry/inflector" require "logger" +require "stringio" RSpec.describe Hanami::Config::Logger do - subject { described_class.new(app_name: app_name, env: env) } - let(:app_name) { Hanami::SliceName.new(double(name: "MyApp::app"), inflector: -> { Dry::Inflector.new }) } - let(:env) { :development } + subject do + described_class.new(app_name: app_name, env: env) + end - describe "#logger_class" do - it "defaults to Hanami::Logger" do - expect(subject.logger_class).to eql Hanami::Logger - end - - it "can be changed to another class" do - another_class = Class.new - - expect { subject.logger_class = another_class } - .to change { subject.logger_class } - .to(another_class) - end + let(:app_name) do + Hanami::SliceName.new(double(name: "MyApp::app"), inflector: -> { Dry::Inflector.new }) end + let(:env) { :development } + describe "#level" do it "defaults to :debug" do expect(subject.level).to eq(:debug) end @@ -61,20 +54,28 @@ end end end describe "#stream=" do - it "accepts a IO object or a path to a file" do - expect { subject.stream = "/dev/null" } + it "accepts a path to a file" do + expect { subject.stream = File::NULL } .to change { subject.stream } - .to("/dev/null") + .to(File::NULL) end + + it "accepts a IO object" do + stream = StringIO.new + + expect { subject.stream = stream } + .to change { subject.stream } + .to(stream) + end end describe "#formatter" do - it "defaults to nil" do - expect(subject.formatter).to eq(nil) + it "defaults to :rack" do + expect(subject.formatter).to eq(:rack) end context "when :production environment" do let(:env) { :production } @@ -90,37 +91,21 @@ .to change { subject.formatter } .to(:json) end end - describe "#colors" do - it "defaults to nil" do - expect(subject.colors).to eq(nil) + describe "#template" do + it "defaults to false" do + expect(subject.template).to eq("[%<progname>s] [%<severity>s] [%<time>s] %<message>s") end - - context "when :test environment" do - let(:env) { :test } - - it "returns false" do - expect(subject.colors).to eq(false) - end - end - - context "when :production environment" do - let(:env) { :production } - - it "returns false" do - expect(subject.colors).to eq(false) - end - end end - describe "#colors=" do + describe "#template=" do it "accepts a value" do - expect { subject.colors = false } - .to change { subject.colors } - .to(false) + expect { subject.template = "%<message>s" } + .to change { subject.template } + .to("%<message>s") end end describe "#filters" do it "defaults to a standard array of sensitive param names" do @@ -143,33 +128,31 @@ .to ["secret"] end end describe "#options" do - it "defaults to empty array" do - expect(subject.options).to eq([]) + it "defaults to empty hash" do + expect(subject.options).to eq({}) end end describe "#options=" do it "accepts value" do - subject.options = expected = "daily" + subject.options = expected = {rotate: "daily"} - expect(subject.options).to eq([expected]) - end - - it "accepts values" do - subject.options = expected = [0, 1048576] - expect(subject.options).to eq(expected) end end end RSpec.describe Hanami::Config do subject(:config) { described_class.new(app_name: app_name, env: env) } - let(:app_name) { Hanami::SliceName.new(double(name: "SOS::app"), inflector: -> { Dry::Inflector.new }) } + + let(:app_name) do + Hanami::SliceName.new(double(name: "SOS::app"), inflector: -> { Dry::Inflector.new }) + end + let(:env) { :development } describe "#logger" do before do config.inflections do |inflections| @@ -185,11 +168,11 @@ end end end describe "#logger_instance" do - it "defaults to an Hanami::Logger instance, based on the default logger settings" do - expect(config.logger_instance).to be_an_instance_of config.logger.logger_class + it "defaults to using Dry::Logger, based on the default logger settings" do + expect(config.logger_instance).to be_a(Dry::Logger::Dispatcher) expect(config.logger_instance.level).to eq Logger::DEBUG end it "can be changed to a pre-initialized instance via #logger=" do logger_instance = Object.new