From 5ab89d512daf998727dd524b6361c8ba4313128a Mon Sep 17 00:00:00 2001 From: Pavel Nikitin Date: Mon, 9 Oct 2023 12:39:15 +0200 Subject: [PATCH] Delegate keyword arguments in Prawn::View#method_missing --- lib/prawn/view.rb | 4 ++-- spec/prawn/view_spec.rb | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/prawn/view.rb b/lib/prawn/view.rb index dbee949e0..c51436bb8 100644 --- a/lib/prawn/view.rb +++ b/lib/prawn/view.rb @@ -69,10 +69,10 @@ def document # Delegates all unhandled calls to object returned by +document+ method. # (which is an instance of Prawn::Document by default) - def method_missing(method_name, *arguments, &block) + def method_missing(method_name, *args, **kwargs, &block) return super unless document.respond_to?(method_name) - document.public_send(method_name, *arguments, &block) + document.public_send(method_name, *args, **kwargs, &block) end def respond_to_missing?(method_name, _include_all = false) diff --git a/spec/prawn/view_spec.rb b/spec/prawn/view_spec.rb index 237822a0f..3d5520926 100644 --- a/spec/prawn/view_spec.rb +++ b/spec/prawn/view_spec.rb @@ -11,13 +11,22 @@ it 'delegates unhandled methods to object returned by document method' do doc = instance_double('Document') - allow(view_object).to receive(:document).and_return(doc) + allow(doc).to receive(:fill_gradient) do |*args, **kwargs, &block| + { args: args, kwargs: kwargs, block: block } + end - allow(doc).to receive(:some_delegated_method) + allow(view_object).to receive(:document).and_return(doc) - view_object.some_delegated_method + block = proc {} + arguments = view_object.fill_gradient('positional', keyword: 'argument', &block) - expect(doc).to have_received(:some_delegated_method) + expect(arguments).to eq( + { + args: ['positional'], + kwargs: { keyword: 'argument' }, + block: block + } + ) end it 'allows a block-like DSL via the update method' do