1
0
Fork 0
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:
Rafael Mendonça França 2021-12-08 18:04:51 -05:00 committed by GitHub
commit bed112de8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -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

View file

@ -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