From a7ec26988ecf0a3379a0a2bbfd2cacca99c979b4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 9 Dec 2024 17:11:18 +1300 Subject: [PATCH] Always return `nil`. --- lib/console/filter.rb | 4 ++++ test/console/filter.rb | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/console/filter.rb b/lib/console/filter.rb index e6e3566..5fb240b 100644 --- a/lib/console/filter.rb +++ b/lib/console/filter.rb @@ -37,6 +37,8 @@ def self.[] **levels if self.enabled?(subject, level) @output.call(subject, *arguments, severity: name, **@options, **options, &block) end + + return nil end define_immutable_method("#{name}!") do @@ -150,6 +152,8 @@ def call(subject, *arguments, **options, &block) if self.enabled?(subject, level) @output.call(subject, *arguments, **options, &block) end + + return nil end end end diff --git a/test/console/filter.rb b/test/console/filter.rb index f1db614..ef8ea5a 100644 --- a/test/console/filter.rb +++ b/test/console/filter.rb @@ -66,29 +66,52 @@ def before end end + with "#info" do + it "ignores messages below the level" do + logger.level = Console::Logger::INFO + + result = logger.debug(MySubject, "Hello World") + + expect(output).to be(:empty?) + expect(result).to be_nil + end + + it "logs messages at the level" do + logger.level = Console::Logger::INFO + + result = logger.info(MySubject, "Hello World", severity: :info) + + expect(output).to be(:include?, "Hello World") + expect(result).to be_nil + end + end + with "#call" do it "ignores messages below the level" do logger.level = Console::Logger::INFO - logger.call(MySubject, "Hello World", severity: :debug) + result = logger.call(MySubject, "Hello World", severity: :debug) expect(output).to be(:empty?) + expect(result).to be_nil end it "logs messages at the level" do logger.level = Console::Logger::INFO - logger.call(MySubject, "Hello World", severity: :info) + result = logger.call(MySubject, "Hello World", severity: :info) expect(output).to be(:include?, "Hello World") + expect(result).to be_nil end it "logs messages above the level" do logger.level = Console::Logger::INFO - logger.call(MySubject, "Hello World", severity: :warn) + result = logger.call(MySubject, "Hello World", severity: :warn) expect(output).to be(:include?, "Hello World") + expect(result).to be_nil end end end