From c02f3865100a1027ece2473f5fe2989d9295761a Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Wed, 1 Jan 2025 21:21:22 +0100 Subject: [PATCH] Suppress warnings about ignored blocks from do/all (fix #179) --- lib/dry/monads/do/all.rb | 13 +++++++++++++ spec/integration/do_all_spec.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/dry/monads/do/all.rb b/lib/dry/monads/do/all.rb index 536c2a6..03c239a 100644 --- a/lib/dry/monads/do/all.rb +++ b/lib/dry/monads/do/all.rb @@ -153,5 +153,18 @@ def extended(object) require "dry/monads/registry" register_mixin(:do, Do::All) + + if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("3.4.0") + ::Warning.prepend(Module.new { + def warn(message) + if message.include?("dry-monads/lib/dry/monads/do.rb") && + message.include?("warning: the block passed to") + nil + else + super + end + end + }) + end end end diff --git a/spec/integration/do_all_spec.rb b/spec/integration/do_all_spec.rb index 1edf121..c50a9b5 100644 --- a/spec/integration/do_all_spec.rb +++ b/spec/integration/do_all_spec.rb @@ -230,6 +230,22 @@ def self.call end end end + + context "warnings" do + let(:klass) do + Class.new do + include Dry::Monads[:do, :result] + + def without + Success() + end + end + end + + it "doesn't produce warnings in methods what don't yield block" do + expect { klass.new.without }.to_not output.to_stderr + end + end end context "Do" do