Skip to content

Commit

Permalink
spec: add tests to logging module (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancyq authored Jun 28, 2024
2 parents ab2decc + 6c1f9d6 commit 271db39
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions spec/mime_actor/logging_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

require "mime_actor/logging"
require "logger"

RSpec.describe MimeActor::Logging do
let(:klazz) { Class.new.include described_class }
let(:klazz_instance) { klazz.new }
let(:stub_logger_class) { Class.new(Logger) }

describe "#logger" do
it "returns default logger" do
expect(klazz.logger).to be_present
expect(klazz.logger).to be_a(ActiveSupport::TaggedLogging)
end

it "allows reassignment" do
expect(klazz.logger).to be_present
klazz.logger = stub_logger_class.new($stdout)
expect(klazz.logger).to be_a(stub_logger_class)
end
end

describe "#config" do
it "allows configure" do
expect(klazz.logger).not_to be_a(stub_logger_class)
expect do
klazz.configure do |config|
config.logger = stub_logger_class.new($stdout)
end
end.not_to raise_error
expect(klazz.logger).to be_a(stub_logger_class)
end
end

describe "#fill_run_sheet" do
let(:log_formatter) { klazz.logger.formatter }

it "include default tag \"MimeActor\"" do
expect(log_formatter.current_tags).not_to include("MimeActor")
klazz_instance.send(:fill_run_sheet) do
expect(log_formatter.current_tags).to include("MimeActor")
end
expect(log_formatter.current_tags).not_to include("MimeActor")
end

it "allows tagging" do
expect(log_formatter.current_tags).not_to include("my_tag_a")
klazz_instance.send(:fill_run_sheet, "my_tag_a", "my_tag_b") do
expect(log_formatter.current_tags).to include("my_tag_a")
expect(log_formatter.current_tags).to include("my_tag_b")
end
expect(log_formatter.current_tags).not_to include("my_tag")
end
end
end

0 comments on commit 271db39

Please sign in to comment.