mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #43807 from jonathanhefner/assert_called_with-empty-args-array
Fix `assert_called_with` with empty `args` array
This commit is contained in:
commit
bed112de8b
2 changed files with 4 additions and 4 deletions
|
@ -68,11 +68,11 @@ class SecurePasswordTest < ActiveRecord::TestCase
|
||||||
test "authenticate_by accepts any object that implements to_h" do
|
test "authenticate_by accepts any object that implements to_h" do
|
||||||
params = Enumerator.new { raise "must access via to_h" }
|
params = Enumerator.new { raise "must access via to_h" }
|
||||||
|
|
||||||
assert_called_with(params, :to_h, [[]], returns: { token: @user.token, password: @user.password }) do
|
assert_called_with(params, :to_h, [], returns: { token: @user.token, password: @user.password }) do
|
||||||
assert_equal @user, User.authenticate_by(params)
|
assert_equal @user, User.authenticate_by(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_called_with(params, :to_h, [[]], returns: { token: "wrong", password: @user.password }) do
|
assert_called_with(params, :to_h, [], returns: { token: "wrong", password: @user.password }) do
|
||||||
assert_nil User.authenticate_by(params)
|
assert_nil User.authenticate_by(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,8 +20,8 @@ module ActiveSupport
|
||||||
def assert_called_with(object, method_name, args, returns: nil, &block)
|
def assert_called_with(object, method_name, args, returns: nil, &block)
|
||||||
mock = Minitest::Mock.new
|
mock = Minitest::Mock.new
|
||||||
|
|
||||||
if args.all?(Array)
|
if !args.empty? && args.all?(Array)
|
||||||
args.each { |arg| mock.expect(:call, returns, arg) }
|
args.each { |argv| mock.expect(:call, returns, argv) }
|
||||||
else
|
else
|
||||||
mock.expect(:call, returns, args)
|
mock.expect(:call, returns, args)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue