Skip to content

Commit

Permalink
Suppress warnings about ignored blocks from do/all (fix #179)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 1, 2025
1 parent a803a77 commit c02f386
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/dry/monads/do/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions spec/integration/do_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c02f386

Please sign in to comment.