Skip to content

Commit

Permalink
- Fixed deprecation warning using stub with methods using keyword arg…
Browse files Browse the repository at this point in the history
…uments. (Nakilon)

[git-p4: depot-paths = "//src/minitest/dev/": change = 13019]
  • Loading branch information
zenspider committed Feb 14, 2021
1 parent 94faf7b commit 9eb312b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/minitest/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def stub name, val_or_callable, *block_args

metaclass.send :alias_method, new_name, name

metaclass.send :define_method, name do |*args, &blk|
metaclass.send :define_method, name do |*args, **kwargs, &blk|
if val_or_callable.respond_to? :call then
val_or_callable.call(*args, &blk)
val_or_callable.call(*args, **kwargs, &blk)
else
blk.call(*block_args) if blk
val_or_callable
Expand Down
12 changes: 12 additions & 0 deletions test/minitest/test_minitest_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,18 @@ def self.identity arg
end
end

class Keywords
def self.args req, kw1:, kw2:24
[req, kw1, kw2]
end
end

def test_stub_callable_keyword_args
Keywords.stub :args, ->(*args, **kws) { 42 } do
@tc.assert_equal 42, Keywords.args("woot", kw1:314)
end
end

def test_stub_callable_block_5 # from tenderlove
@assertion_count += 1
Foo.stub5 :blocking, Bar.new do
Expand Down

0 comments on commit 9eb312b

Please sign in to comment.