# frozen_string_literal: true require "hanami/config/logger" require "hanami/slice_name" require "dry/inflector" require "logger" require "stringio" RSpec.describe Hanami::Config::Logger do subject do described_class.new(app_name: app_name, env: env) 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 context "when :production environment" do let(:env) { :production } it "returns :info" do expect(subject.level).to eq(:info) end end end describe "#level=" do it "a value" do expect { subject.level = :warn } .to change { subject.level } .to(:warn) end end describe "#stream" do it "defaults to $stdout" do expect(subject.stream).to eq($stdout) end context "when :test environment" do let(:env) { :test } it "returns a file" do expected = File.join("log", "test.log") expect(subject.stream).to eq(expected) end end end describe "#stream=" do it "accepts a path to a file" do expect { subject.stream = File::NULL } .to change { subject.stream } .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 :rack" do expect(subject.formatter).to eq(:rack) end context "when :production environment" do let(:env) { :production } it "returns :json" do expect(subject.formatter).to eq(:json) end end end describe "#formatter=" do it "accepts a formatter" do expect { subject.formatter = :json } .to change { subject.formatter } .to(:json) end end describe "#template" do it "defaults to false" do expect(subject.template).to eq("[%s] [%s] [%