From 46b92c4d1274f7438b4e5e65bacc017693c3ffed Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 10 Jul 2015 23:24:47 +0200 Subject: [PATCH] Add multiple expected calls to assert_called_with. --- .../lib/active_support/testing/method_call_assertions.rb | 7 ++++++- activesupport/test/testing/method_call_assertions_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/testing/method_call_assertions.rb b/activesupport/lib/active_support/testing/method_call_assertions.rb index 0d7d62341c..e3cbe40308 100644 --- a/activesupport/lib/active_support/testing/method_call_assertions.rb +++ b/activesupport/lib/active_support/testing/method_call_assertions.rb @@ -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 } diff --git a/activesupport/test/testing/method_call_assertions_test.rb b/activesupport/test/testing/method_call_assertions_test.rb index b327492b3b..a9908aea0d 100644 --- a/activesupport/test/testing/method_call_assertions_test.rb +++ b/activesupport/test/testing/method_call_assertions_test.rb @@ -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