Skip to content

Commit

Permalink
Delegate keyword arguments in Prawn::View#method_missing
Browse files Browse the repository at this point in the history
  • Loading branch information
butcher committed Oct 9, 2023
1 parent 8ceaa10 commit 5ab89d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/prawn/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions spec/prawn/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ab89d5

Please sign in to comment.