Skip to content

Commit 9766eb4

Browse files
eileencodesmatthewd
andcommitted
Fix tests for minitest 5.16
In minitest/minitest@6e06ac9 minitest changed such that it now accepts `kwargs` instead of requiring kwargs to be shoved into the args array. This is a good change but required some updates to our test code to get the new version of minitest passing. Changes are as follows: 1) Lock minitest to 5.15 for Ruby 2.7. We don't love this change but it's pretty difficult to get 2.7 and 3.0 to play nicely together with the new kwargs changes. Dropping 2.7 support isn't an option right now for Rails. This is safe because all of the code changes here are internal methods to Rails like assert_called_with. Applications shouldn't be consuming them as they are no-doc'd. 2) Update the `assert_called_with` method to take any kwargs but also the returns kwarg. 3) Update callers of `assert_called_with` to move the kwargs outside the args array. 4) Update the message from marshaled exceptions. In 5.16 the exception message is "result not reported" instead of "Wrapped undumpable exception". Co-authored-by: Matthew Draper <[email protected]>
1 parent 2564b71 commit 9766eb4

File tree

16 files changed

+143
-103
lines changed

16 files changed

+143
-103
lines changed

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
66

77
gemspec
88

9-
gem "minitest", ">= 5.15.0", "< 5.16.0"
9+
if RUBY_VERSION < "3"
10+
gem "minitest", ">= 5.15.0", "< 5.16"
11+
else
12+
gem "minitest", ">= 5.15.0"
13+
end
1014

1115
# We need a newish Rake since Active Job sets its test tasks' descriptions.
1216
gem "rake", ">= 11.1"

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ GEM
322322
mini_magick (4.11.0)
323323
mini_mime (1.1.2)
324324
mini_portile2 (2.8.0)
325-
minitest (5.15.0)
325+
minitest (5.16.1)
326326
minitest-bisect (1.5.1)
327327
minitest-server (~> 1.0)
328328
path_expander (~> 1.1)
@@ -586,7 +586,7 @@ DEPENDENCIES
586586
kindlerb (~> 1.2.0)
587587
libxml-ruby
588588
listen (~> 3.3)
589-
minitest (>= 5.15.0, < 5.16.0)
589+
minitest (>= 5.15.0)
590590
minitest-bisect
591591
minitest-ci
592592
minitest-retry

actionpack/test/controller/integration_test.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,91 +36,91 @@ def test_follow_redirect_raises_when_no_redirect
3636
def test_get
3737
path = "/index"; params = "blah"; headers = { location: "blah" }
3838

39-
assert_called_with @session, :process, [:get, path, params: params, headers: headers] do
39+
assert_called_with @session, :process, [:get, path], params: params, headers: headers do
4040
@session.get(path, params: params, headers: headers)
4141
end
4242
end
4343

4444
def test_get_with_env_and_headers
4545
path = "/index"; params = "blah"; headers = { location: "blah" }; env = { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" }
46-
assert_called_with @session, :process, [:get, path, params: params, headers: headers, env: env] do
46+
assert_called_with @session, :process, [:get, path], params: params, headers: headers, env: env do
4747
@session.get(path, params: params, headers: headers, env: env)
4848
end
4949
end
5050

5151
def test_post
5252
path = "/index"; params = "blah"; headers = { location: "blah" }
53-
assert_called_with @session, :process, [:post, path, params: params, headers: headers] do
53+
assert_called_with @session, :process, [:post, path], params: params, headers: headers do
5454
@session.post(path, params: params, headers: headers)
5555
end
5656
end
5757

5858
def test_patch
5959
path = "/index"; params = "blah"; headers = { location: "blah" }
60-
assert_called_with @session, :process, [:patch, path, params: params, headers: headers] do
60+
assert_called_with @session, :process, [:patch, path], params: params, headers: headers do
6161
@session.patch(path, params: params, headers: headers)
6262
end
6363
end
6464

6565
def test_put
6666
path = "/index"; params = "blah"; headers = { location: "blah" }
67-
assert_called_with @session, :process, [:put, path, params: params, headers: headers] do
67+
assert_called_with @session, :process, [:put, path], params: params, headers: headers do
6868
@session.put(path, params: params, headers: headers)
6969
end
7070
end
7171

7272
def test_delete
7373
path = "/index"; params = "blah"; headers = { location: "blah" }
74-
assert_called_with @session, :process, [:delete, path, params: params, headers: headers] do
74+
assert_called_with @session, :process, [:delete, path], params: params, headers: headers do
7575
@session.delete(path, params: params, headers: headers)
7676
end
7777
end
7878

7979
def test_head
8080
path = "/index"; params = "blah"; headers = { location: "blah" }
81-
assert_called_with @session, :process, [:head, path, params: params, headers: headers] do
81+
assert_called_with @session, :process, [:head, path], params: params, headers: headers do
8282
@session.head(path, params: params, headers: headers)
8383
end
8484
end
8585

8686
def test_xml_http_request_get
8787
path = "/index"; params = "blah"; headers = { location: "blah" }
88-
assert_called_with @session, :process, [:get, path, params: params, headers: headers, xhr: true] do
88+
assert_called_with @session, :process, [:get, path], params: params, headers: headers, xhr: true do
8989
@session.get(path, params: params, headers: headers, xhr: true)
9090
end
9191
end
9292

9393
def test_xml_http_request_post
9494
path = "/index"; params = "blah"; headers = { location: "blah" }
95-
assert_called_with @session, :process, [:post, path, params: params, headers: headers, xhr: true] do
95+
assert_called_with @session, :process, [:post, path], params: params, headers: headers, xhr: true do
9696
@session.post(path, params: params, headers: headers, xhr: true)
9797
end
9898
end
9999

100100
def test_xml_http_request_patch
101101
path = "/index"; params = "blah"; headers = { location: "blah" }
102-
assert_called_with @session, :process, [:patch, path, params: params, headers: headers, xhr: true] do
102+
assert_called_with @session, :process, [:patch, path], params: params, headers: headers, xhr: true do
103103
@session.patch(path, params: params, headers: headers, xhr: true)
104104
end
105105
end
106106

107107
def test_xml_http_request_put
108108
path = "/index"; params = "blah"; headers = { location: "blah" }
109-
assert_called_with @session, :process, [:put, path, params: params, headers: headers, xhr: true] do
109+
assert_called_with @session, :process, [:put, path], params: params, headers: headers, xhr: true do
110110
@session.put(path, params: params, headers: headers, xhr: true)
111111
end
112112
end
113113

114114
def test_xml_http_request_delete
115115
path = "/index"; params = "blah"; headers = { location: "blah" }
116-
assert_called_with @session, :process, [:delete, path, params: params, headers: headers, xhr: true] do
116+
assert_called_with @session, :process, [:delete, path], params: params, headers: headers, xhr: true do
117117
@session.delete(path, params: params, headers: headers, xhr: true)
118118
end
119119
end
120120

121121
def test_xml_http_request_head
122122
path = "/index"; params = "blah"; headers = { location: "blah" }
123-
assert_called_with @session, :process, [:head, path, params: params, headers: headers, xhr: true] do
123+
assert_called_with @session, :process, [:head, path], params: params, headers: headers, xhr: true do
124124
@session.head(path, params: params, headers: headers, xhr: true)
125125
end
126126
end

actionview/test/template/date_helper_i18n_test.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_distance_of_time_in_words_calls_i18n_with_custom_scope
4949
end
5050

5151
def test_time_ago_in_words_passes_locale
52-
assert_called_with(I18n, :t, [:less_than_x_minutes, scope: :'datetime.distance_in_words', count: 1, locale: "ru"]) do
52+
assert_called_with(I18n, :t, [:less_than_x_minutes], scope: :'datetime.distance_in_words', count: 1, locale: "ru") do
5353
time_ago_in_words(15.seconds.ago, locale: "ru")
5454
end
5555
end
@@ -84,7 +84,7 @@ def assert_distance_of_time_in_words_translates_key(passed, expected, expected_o
8484
options = { locale: "en", scope: :'datetime.distance_in_words' }.merge!(expected_options)
8585
options[:count] = count if count
8686

87-
assert_called_with(I18n, :t, [key, options]) do
87+
assert_called_with(I18n, :t, [key], **options) do
8888
distance_of_time_in_words(@from, to, passed_options.merge(locale: "en"))
8989
end
9090
end
@@ -103,13 +103,13 @@ def test_select_month_given_use_month_names_option_does_not_translate_monthnames
103103
end
104104

105105
def test_select_month_translates_monthnames
106-
assert_called_with(I18n, :translate, [:'date.month_names', locale: "en"], returns: Date::MONTHNAMES) do
106+
assert_called_with(I18n, :translate, [:'date.month_names'], returns: Date::MONTHNAMES, locale: "en") do
107107
select_month(8, locale: "en")
108108
end
109109
end
110110

111111
def test_select_month_given_use_short_month_option_translates_abbr_monthnames
112-
assert_called_with(I18n, :translate, [:'date.abbr_month_names', locale: "en"], returns: Date::ABBR_MONTHNAMES) do
112+
assert_called_with(I18n, :translate, [:'date.abbr_month_names'], returns: Date::ABBR_MONTHNAMES, locale: "en") do
113113
select_month(8, locale: "en", use_short_month: true)
114114
end
115115
end
@@ -147,8 +147,8 @@ def test_date_or_time_select_given_an_order_options_does_not_translate_order
147147

148148
def test_date_or_time_select_given_no_order_options_translates_order
149149
mock = Minitest::Mock.new
150-
mock.expect(:call, ["year", "month", "day"], [:'date.order', { locale: "en", default: [] }])
151-
mock.expect(:call, [], [:'date.month_names', { locale: "en" }])
150+
expect_called_with(mock, [:'date.order'], locale: "en", default: [], returns: ["year", "month", "day"])
151+
expect_called_with(mock, [:'date.month_names'], locale: "en", returns: [])
152152

153153
I18n.stub(:translate, mock) do
154154
datetime_select("post", "updated_at", locale: "en")
@@ -158,7 +158,7 @@ def test_date_or_time_select_given_no_order_options_translates_order
158158
end
159159

160160
def test_date_or_time_select_given_invalid_order
161-
assert_called_with(I18n, :translate, [:'date.order', locale: "en", default: []], returns: %w(invalid month day)) do
161+
assert_called_with(I18n, :translate, [:'date.order'], returns: %w(invalid month day), locale: "en", default: []) do
162162
assert_raise StandardError do
163163
datetime_select("post", "updated_at", locale: "en")
164164
end
@@ -167,8 +167,8 @@ def test_date_or_time_select_given_invalid_order
167167

168168
def test_date_or_time_select_given_symbol_keys
169169
mock = Minitest::Mock.new
170-
mock.expect(:call, [:year, :month, :day], [:'date.order', { locale: "en", default: [] }])
171-
mock.expect(:call, [], [:'date.month_names', { locale: "en" }])
170+
expect_called_with(mock, [:'date.order'], locale: "en", default: [], returns: [:year, :month, :day])
171+
expect_called_with(mock, [:'date.month_names'], locale: "en", returns: [])
172172

173173
I18n.stub(:translate, mock) do
174174
datetime_select("post", "updated_at", locale: "en")

actionview/test/template/form_helper/form_with_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ def test_nested_fields_label_translation_with_more_than_10_records
17681768

17691769
mock = Minitest::Mock.new
17701770
@post.comments.each do
1771-
mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"])
1771+
expect_called_with(mock, ["post.comments.body"], default: [:"comment.body", ""], scope: "helpers.label", returns: "body")
17721772
end
17731773

17741774
I18n.stub(:t, mock) do

actionview/test/template/form_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3302,7 +3302,7 @@ def test_nested_fields_label_translation_with_more_than_10_records
33023302

33033303
mock = Minitest::Mock.new
33043304
@post.comments.each do
3305-
mock.expect(:call, "body", ["post.comments.body", default: [:"comment.body", ""], scope: "helpers.label"])
3305+
expect_called_with(mock, ["post.comments.body"], default: [:"comment.body", ""], scope: "helpers.label", returns: "body")
33063306
end
33073307

33083308
I18n.stub(:t, mock) do

actionview/test/template/form_options_helper_i18n_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def teardown
1616
end
1717

1818
def test_select_with_prompt_true_translates_prompt_message
19-
assert_called_with(I18n, :translate, ["helpers.select.prompt", { default: "Please select" }]) do
19+
assert_called_with(I18n, :translate, ["helpers.select.prompt"], default: "Please select") do
2020
select("post", "category", [], prompt: true)
2121
end
2222
end

actionview/test/template/translation_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_delegates_setting_to_i18n
6565

6666
def test_delegates_localize_to_i18n
6767
@time = Time.utc(2008, 7, 8, 12, 18, 38)
68-
assert_called_with(I18n, :localize, [@time, locale: "en"]) do
68+
assert_called_with(I18n, :localize, [@time], locale: "en") do
6969
localize @time, locale: "en"
7070
end
7171
assert_equal "Tue, 08 Jul 2008 12:18:38 +0000", localize(@time, locale: "en")

activerecord/test/cases/fixtures_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ def rollback_transaction(*args); end
995995
def lock_thread=(lock_thread); end
996996
end.new
997997

998-
assert_called_with(connection, :begin_transaction, [joinable: false, _lazy: false]) do
998+
assert_called_with(connection, :begin_transaction, [], joinable: false, _lazy: false) do
999999
fire_connection_notification(connection)
10001000
end
10011001
end
@@ -1035,14 +1035,14 @@ def rollback_transaction(*args); end
10351035
def lock_thread=(lock_thread); end
10361036
end.new
10371037

1038-
assert_called_with(connection, :begin_transaction, [joinable: false, _lazy: false]) do
1038+
assert_called_with(connection, :begin_transaction, [], joinable: false, _lazy: false) do
10391039
fire_connection_notification(connection, shard: :shard_two)
10401040
end
10411041
end
10421042

10431043
private
10441044
def fire_connection_notification(connection, shard: ActiveRecord::Base.default_shard)
1045-
assert_called_with(ActiveRecord::Base.connection_handler, :retrieve_connection, ["book", { shard: shard }], returns: connection) do
1045+
assert_called_with(ActiveRecord::Base.connection_handler, :retrieve_connection, ["book"], returns: connection, shard: shard) do
10461046
message_bus = ActiveSupport::Notifications.instrumenter
10471047
payload = {
10481048
spec_name: "book",

0 commit comments

Comments
 (0)