Projects
openEuler:24.03:SP1:Everything
rubygem-actionview
_service:tar_scm:rubygem-actionview-7.0.2.3-Rem...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:rubygem-actionview-7.0.2.3-Remove-the-multi-call-form-of-assert_called_with.patch of Package rubygem-actionview
From df0de681dc1873534ecd2fc8371e1f2562984b68 Mon Sep 17 00:00:00 2001 From: John Crepezzi <john.crepezzi@gmail.com> Date: Thu, 16 Jun 2022 08:34:05 -0400 Subject: [PATCH] Remove the multi-call form of assert_called_with The `assert_called_with` helper allows passing a multi-dimensional array to mock multiple calls to the same method for a given block. This works fine now, but when adding support for real kwargs arguments to line up with recent upgrades in Minitest, this approach is no longer workable because we can't pass multiple sets of differing kwargs. Rather than complicated this method further, this commit removes the multi-call form of `assert_called_with` and modifies the tests that currently make use of that functionality to just use the underlying `Minitest::Mock` calls. Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com> --- .../test/template/date_helper_i18n_test.rb | 16 +++- .../template/form_helper/form_with_test.rb | 10 ++- actionview/test/template/form_helper_test.rb | 10 ++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/actionview/test/template/date_helper_i18n_test.rb b/actionview/test/template/date_helper_i18n_test.rb index f100a011a83f7..2f098e2f5158f 100644 --- a/actionview/test/template/date_helper_i18n_test.rb +++ b/actionview/test/template/date_helper_i18n_test.rb @@ -146,9 +146,15 @@ def test_date_or_time_select_given_an_order_options_does_not_translate_order end def test_date_or_time_select_given_no_order_options_translates_order - assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", { locale: "en" }] ], returns: %w(year month day)) do + mock = Minitest::Mock.new + mock.expect(:call, ["year", "month", "day"], [:'date.order', { locale: "en", default: [] }]) + mock.expect(:call, [], [:'date.month_names', { locale: "en" }]) + + I18n.stub(:translate, mock) do datetime_select("post", "updated_at", locale: "en") end + + assert_mock(mock) end def test_date_or_time_select_given_invalid_order @@ -160,8 +166,14 @@ def test_date_or_time_select_given_invalid_order end def test_date_or_time_select_given_symbol_keys - assert_called_with(I18n, :translate, [ [:'date.order', locale: "en", default: []], [:"date.month_names", { locale: "en" }] ], returns: [:year, :month, :day]) do + mock = Minitest::Mock.new + mock.expect(:call, [:year, :month, :day], [:'date.order', { locale: "en", default: [] }]) + mock.expect(:call, [], [:'date.month_names', { locale: "en" }]) + + I18n.stub(:translate, mock) do datetime_select("post", "updated_at", locale: "en") end + + assert_mock(mock) end end diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index eadddc15002ee..00e6ca42ea473 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -1745,14 +1745,20 @@ def test_nested_fields_arel_like def test_nested_fields_label_translation_with_more_than_10_records @post.comments = Array.new(11) { |id| Comment.new(id + 1) } - params = 11.times.map { ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"] } - assert_called_with(I18n, :t, params, returns: "Write body here") do + mock = Minitest::Mock.new + @post.comments.each do + mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"]) + end + + I18n.stub(:t, mock) do form_with(model: @post) do |f| f.fields(:comments) do |cf| concat cf.label(:body) end end end + + assert_mock(mock) end def test_nested_fields_with_existing_records_on_a_supplied_nested_attributes_collection_different_from_record_one diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index d08f00cd36c35..8560be2770ca4 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -3267,14 +3267,20 @@ def test_nested_fields_for_arel_like def test_nested_fields_label_translation_with_more_than_10_records @post.comments = Array.new(11) { |id| Comment.new(id + 1) } - params = 11.times.map { ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"] } - assert_called_with(I18n, :t, params, returns: "Write body here") do + mock = Minitest::Mock.new + @post.comments.each do + mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"]) + end + + I18n.stub(:t, mock) do form_for(@post) do |f| f.fields_for(:comments) do |cf| concat cf.label(:body) end end end + + assert_mock(mock) end def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection_different_from_record_one
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2