mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add multiple expected calls to assert_called_with.
This commit is contained in:
parent
3c5bd78ddb
commit
46b92c4d12
2 changed files with 13 additions and 1 deletions
|
@ -15,7 +15,12 @@ module ActiveSupport
|
|||
|
||||
def assert_called_with(object, method_name, args = [], returns: nil)
|
||||
mock = Minitest::Mock.new
|
||||
mock.expect(:call, returns, args)
|
||||
|
||||
if args.all? { |arg| arg.is_a?(Array) }
|
||||
args.each { |arg| mock.expect(:call, returns, arg) }
|
||||
else
|
||||
mock.expect(:call, returns, args)
|
||||
end
|
||||
|
||||
object.stub(method_name, mock) { yield }
|
||||
|
||||
|
|
|
@ -73,6 +73,13 @@ class MethodCallAssertionsTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_called_with_multiple_expected_arguments
|
||||
assert_called_with(@object, :<<, [ [ 1 ], [ 2 ] ]) do
|
||||
@object << 1
|
||||
@object << 2
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_not_called
|
||||
assert_not_called(@object, :decrement) do
|
||||
@object.increment
|
||||
|
|
Loading…
Reference in a new issue