Skip to content

Commit 50daada

Browse files
committed
Update test suite for compatibility with Ruby 3.4-dev
https://bugs.ruby-lang.org/issues/19117 and https://bugs.ruby-lang.org/issues/16495 slightly change how backtrace are rendered which makes a few tests fail.
1 parent 9e01d93 commit 50daada

File tree

15 files changed

+149
-70
lines changed

15 files changed

+149
-70
lines changed

actionpack/test/dispatch/debug_exceptions_test.rb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def self.build_app(app, *args)
701701

702702
# assert application trace refers to line that calls method_that_raises is first
703703
assert_select "#Application-Trace-0" do
704-
assert_select "code a:first", %r{test/dispatch/debug_exceptions_test\.rb:\d+:in `call}
704+
assert_select "code a:first", %r{test/dispatch/debug_exceptions_test\.rb:\d+:in .*call}
705705
end
706706

707707
# assert framework trace that threw the error is first
@@ -747,19 +747,32 @@ def self.build_app(app, *args)
747747
assert_select "pre .line.active", /raise "Third error"/
748748
end
749749

750-
# assert application trace refers to line that raises the last exception
751-
assert_select "#Application-Trace-0" do
752-
assert_select "code a:first", %r{in `rescue in rescue in raise_nested_exceptions'}
753-
end
750+
if RUBY_VERSION >= "3.4"
751+
# Possible Ruby 3.4-dev bug: https://bugs.ruby-lang.org/issues/19117#note-45
752+
# assert application trace refers to line that raises the last exception
753+
assert_select "#Application-Trace-0" do
754+
assert_select "code a:first", %r{in '.*raise_nested_exceptions'}
755+
end
756+
757+
# assert the second application trace refers to the line that raises the second exception
758+
assert_select "#Application-Trace-1" do
759+
assert_select "code a:first", %r{in '.*raise_nested_exceptions'}
760+
end
761+
else
762+
# assert application trace refers to line that raises the last exception
763+
assert_select "#Application-Trace-0" do
764+
assert_select "code a:first", %r{in [`']rescue in rescue in .*raise_nested_exceptions'}
765+
end
754766

755-
# assert the second application trace refers to the line that raises the second exception
756-
assert_select "#Application-Trace-1" do
757-
assert_select "code a:first", %r{in `rescue in raise_nested_exceptions'}
767+
# assert the second application trace refers to the line that raises the second exception
768+
assert_select "#Application-Trace-1" do
769+
assert_select "code a:first", %r{in [`']rescue in .*raise_nested_exceptions'}
770+
end
758771
end
759772

760773
# assert the third application trace refers to the line that raises the first exception
761774
assert_select "#Application-Trace-2" do
762-
assert_select "code a:first", %r{in `raise_nested_exceptions'}
775+
assert_select "code a:first", %r{in [`'].*raise_nested_exceptions'}
763776
end
764777
end
765778
end
@@ -810,6 +823,6 @@ def self.build_app(app, *args)
810823

811824
assert_response 500
812825
assert_select "#container p", /Showing #{__FILE__} where line #\d+ raised/
813-
assert_select "#container code", /undefined local variable or method `string”'/
826+
assert_select "#container code", /undefined local variable or method ['`]string”'/
814827
end
815828
end

actionpack/test/dispatch/exception_wrapper_test.rb

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ def backtrace
114114
exception = begin index; rescue TestError => ex; ex; end
115115
wrapper = ExceptionWrapper.new(@cleaner, TopErrorProxy.new(exception, 1))
116116

117-
assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace.map(&:to_s)
117+
if RUBY_VERSION >= "3.4"
118+
assert_equal [ "lib/file.rb:42:in 'ActionDispatch::ExceptionWrapperTest#index'" ], wrapper.application_trace.map(&:to_s)
119+
else
120+
assert_equal [ "lib/file.rb:42:in `index'" ], wrapper.application_trace.map(&:to_s)
121+
end
118122
end
119123

120124
test "#status_code returns 400 for Rack::Utils::ParameterTypeError" do
@@ -182,30 +186,57 @@ def backtrace
182186
exception = begin in_rack; rescue TestError => ex; TopErrorProxy.new(ex, 2); end
183187
wrapper = ExceptionWrapper.new(@cleaner, exception)
184188

185-
assert_equal({
186-
"Application Trace" => [
187-
exception_object_id: exception.object_id,
188-
id: 0,
189-
trace: "lib/file.rb:42:in `index'"
190-
],
191-
"Framework Trace" => [
192-
exception_object_id: exception.object_id,
193-
id: 1,
194-
trace: "/gems/rack.rb:43:in `in_rack'"
195-
],
196-
"Full Trace" => [
197-
{
189+
if RUBY_VERSION >= "3.4"
190+
assert_equal({
191+
"Application Trace" => [
192+
exception_object_id: exception.object_id,
193+
id: 0,
194+
trace: "lib/file.rb:42:in 'ActionDispatch::ExceptionWrapperTest#index'"
195+
],
196+
"Framework Trace" => [
197+
exception_object_id: exception.object_id,
198+
id: 1,
199+
trace: "/gems/rack.rb:43:in 'ActionDispatch::ExceptionWrapperTest#in_rack'"
200+
],
201+
"Full Trace" => [
202+
{
203+
exception_object_id: exception.object_id,
204+
id: 0,
205+
trace: "lib/file.rb:42:in 'ActionDispatch::ExceptionWrapperTest#index'"
206+
},
207+
{
208+
exception_object_id: exception.object_id,
209+
id: 1,
210+
trace: "/gems/rack.rb:43:in 'ActionDispatch::ExceptionWrapperTest#in_rack'"
211+
}
212+
]
213+
}.inspect, wrapper.traces.inspect)
214+
else
215+
assert_equal({
216+
"Application Trace" => [
198217
exception_object_id: exception.object_id,
199218
id: 0,
200219
trace: "lib/file.rb:42:in `index'"
201-
},
202-
{
220+
],
221+
"Framework Trace" => [
203222
exception_object_id: exception.object_id,
204223
id: 1,
205224
trace: "/gems/rack.rb:43:in `in_rack'"
206-
}
207-
]
208-
}.inspect, wrapper.traces.inspect)
225+
],
226+
"Full Trace" => [
227+
{
228+
exception_object_id: exception.object_id,
229+
id: 0,
230+
trace: "lib/file.rb:42:in `index'"
231+
},
232+
{
233+
exception_object_id: exception.object_id,
234+
id: 1,
235+
trace: "/gems/rack.rb:43:in `in_rack'"
236+
}
237+
]
238+
}.inspect, wrapper.traces.inspect)
239+
end
209240
end
210241

211242
test "#show? returns false when using :rescuable and the exceptions is not rescuable" do

actionview/test/activerecord/polymorphic_routes_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_with_nil_in_list_does_not_generate_invalid_link
213213
@series.save
214214
polymorphic_url([nil, @series])
215215
end
216-
assert_match(/undefined method `series_url'/, exception.message)
216+
assert_match(/undefined method [`']series_url'/, exception.message)
217217
end
218218
end
219219

actionview/test/template/render_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_render_renderable_does_not_mask_nomethoderror_from_within_render_in
316316
renderable = Object.new
317317
renderable.define_singleton_method(:render_in) { |*| nil.render_in }
318318

319-
assert_raises NoMethodError, match: "undefined method `render_in' for nil" do
319+
assert_raises NoMethodError, match: /undefined method [`']render_in' for nil/ do
320320
@view.render renderable: renderable
321321
end
322322
end
@@ -390,7 +390,7 @@ def test_render_sub_template_with_errors
390390

391391
def test_undefined_method_error_references_named_class
392392
e = assert_raises(ActionView::Template::Error) { @view.render(inline: "<%= undefined %>") }
393-
assert_match(/undefined local variable or method `undefined'/, e.message)
393+
assert_match(/undefined local variable or method [`']undefined'/, e.message)
394394
end
395395

396396
def test_render_renderable_object

activejob/test/cases/logging_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ def test_job_error_logging
278278
RescueJob.perform_later "other"
279279
rescue RescueJob::OtherError
280280
assert_match(/Performing RescueJob \(Job ID: .*?\) from .*? with arguments:.*other/, @logger.messages)
281-
assert_match(/Error performing RescueJob \(Job ID: .*?\) from .*? in .*ms: RescueJob::OtherError \(Bad hair\):\n.*\brescue_job\.rb:\d+:in `perform'/, @logger.messages)
281+
assert_match(/Error performing RescueJob \(Job ID: .*?\) from .*? in .*ms: RescueJob::OtherError \(Bad hair\):\n.*\brescue_job\.rb:\d+:in .*perform'/, @logger.messages)
282282
end
283283
end
284284

285285
def test_job_no_error_logging_on_rescuable_job
286286
perform_enqueued_jobs { RescueJob.perform_later "david" }
287287
assert_match(/Performing RescueJob \(Job ID: .*?\) from .*? with arguments:.*david/, @logger.messages)
288-
assert_no_match(/Error performing RescueJob \(Job ID: .*?\) from .*? in .*ms: ArgumentError \(Hair too good\):\n.*\brescue_job\.rb:\d+:in `perform'/, @logger.messages)
288+
assert_no_match(/Error performing RescueJob \(Job ID: .*?\) from .*? in .*ms: ArgumentError \(Hair too good\):\n.*\brescue_job\.rb:\d+:in .*perform'/, @logger.messages)
289289
end
290290

291291
def test_enqueue_retry_logging

activemodel/test/cases/attribute_methods_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def attribute(name)
262262
assert_equal("Active Model Topic", topic_class.new.subject_to_be_undefined)
263263
topic_class.undefine_attribute_methods
264264

265-
assert_raises(NoMethodError, match: /undefined method `subject_to_be_undefined'/) do
265+
assert_raises(NoMethodError, match: /undefined method [`']subject_to_be_undefined'/) do
266266
topic_class.new.subject_to_be_undefined
267267
end
268268
end

activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ def test_overriding_default_journal_size_limit_pragma
291291
conn.execute("PRAGMA journal_size_limit")
292292
end
293293
end
294-
assert_match(/undefined method `to_i'/, error.message)
294+
assert_match(/undefined method [`']to_i'/, error.message)
295295

296296
error = assert_raises(ActiveRecord::StatementInvalid) do
297297
send(method_name, pragmas: { journal_size_limit: :false }) do |conn|
298298
conn.execute("PRAGMA journal_size_limit")
299299
end
300300
end
301-
assert_match(/undefined method `to_i'/, error.message)
301+
assert_match(/undefined method [`']to_i'/, error.message)
302302
end
303303

304304
def test_overriding_default_mmap_size_pragma
@@ -317,14 +317,14 @@ def test_overriding_default_mmap_size_pragma
317317
conn.execute("PRAGMA mmap_size")
318318
end
319319
end
320-
assert_match(/undefined method `to_i'/, error.message)
320+
assert_match(/undefined method [`']to_i'/, error.message)
321321

322322
error = assert_raises(ActiveRecord::StatementInvalid) do
323323
with_memory_connection(pragmas: { mmap_size: :false }) do |conn|
324324
conn.execute("PRAGMA mmap_size")
325325
end
326326
end
327-
assert_match(/undefined method `to_i'/, error.message)
327+
assert_match(/undefined method [`']to_i'/, error.message)
328328
else
329329
with_file_connection(pragmas: { mmap_size: 100 }) do |conn|
330330
assert_equal [{ "mmap_size" => 100 }], conn.execute("PRAGMA mmap_size")
@@ -339,14 +339,14 @@ def test_overriding_default_mmap_size_pragma
339339
conn.execute("PRAGMA mmap_size")
340340
end
341341
end
342-
assert_match(/undefined method `to_i'/, error.message)
342+
assert_match(/undefined method [`']to_i'/, error.message)
343343

344344
error = assert_raises(ActiveRecord::StatementInvalid) do
345345
with_file_connection(pragmas: { mmap_size: :false }) do |conn|
346346
conn.execute("PRAGMA mmap_size")
347347
end
348348
end
349-
assert_match(/undefined method `to_i'/, error.message)
349+
assert_match(/undefined method [`']to_i'/, error.message)
350350
end
351351
end
352352

@@ -366,14 +366,14 @@ def test_overriding_default_cache_size_pragma
366366
conn.execute("PRAGMA cache_size")
367367
end
368368
end
369-
assert_match(/undefined method `to_i'/, error.message)
369+
assert_match(/undefined method [`']to_i'/, error.message)
370370

371371
error = assert_raises(ActiveRecord::StatementInvalid) do
372372
send(method_name, pragmas: { cache_size: :false }) do |conn|
373373
conn.execute("PRAGMA cache_size")
374374
end
375375
end
376-
assert_match(/undefined method `to_i'/, error.message)
376+
assert_match(/undefined method [`']to_i'/, error.message)
377377
end
378378

379379
def test_setting_new_pragma

activesupport/test/callbacks_test.rb

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,33 @@ def test_tidy_call_stack
473473
# callbacks that have been invoked, if there are any (plus
474474
# whatever the callbacks do themselves, of course).
475475

476-
assert_equal [
477-
"block in save",
478-
"block in run_callbacks",
479-
"tweedle_deedle",
480-
"block in run_callbacks",
481-
"w0tyes",
482-
"block in run_callbacks",
483-
"tweedle_dum",
484-
"block in run_callbacks",
485-
"run_callbacks",
486-
"save"
487-
], call_stack.map(&:label)
476+
if RUBY_VERSION >= "3.4"
477+
assert_equal [
478+
"block in CallbacksTest::MySlate#save",
479+
"block in ActiveSupport::Callbacks#run_callbacks",
480+
"CallbacksTest::AroundPerson#tweedle_deedle",
481+
"block in ActiveSupport::Callbacks#run_callbacks",
482+
"CallbacksTest::AroundPerson#w0tyes",
483+
"block in ActiveSupport::Callbacks#run_callbacks",
484+
"CallbacksTest::AroundPerson#tweedle_dum",
485+
"block in ActiveSupport::Callbacks#run_callbacks",
486+
"ActiveSupport::Callbacks#run_callbacks",
487+
"CallbacksTest::MySlate#save",
488+
].join("\n"), call_stack.map(&:label).join("\n")
489+
else
490+
assert_equal [
491+
"block in save",
492+
"block in run_callbacks",
493+
"tweedle_deedle",
494+
"block in run_callbacks",
495+
"w0tyes",
496+
"block in run_callbacks",
497+
"tweedle_dum",
498+
"block in run_callbacks",
499+
"run_callbacks",
500+
"save",
501+
].join("\n"), call_stack.map(&:label).join("\n")
502+
end
488503
end
489504

490505
def test_short_call_stack
@@ -503,11 +518,19 @@ def test_short_call_stack
503518
# there should be just one line. run_callbacks yields directly
504519
# back to its caller.
505520

506-
assert_equal [
507-
"block in save",
508-
"run_callbacks",
509-
"save"
510-
], call_stack.map(&:label)
521+
if RUBY_VERSION >= "3.4"
522+
assert_equal [
523+
"block in CallbacksTest::Person#save",
524+
"ActiveSupport::Callbacks#run_callbacks",
525+
"CallbacksTest::Person#save",
526+
].join("\n"), call_stack.map(&:label).join("\n")
527+
else
528+
assert_equal [
529+
"block in save",
530+
"run_callbacks",
531+
"save",
532+
].join("\n"), call_stack.map(&:label).join("\n")
533+
end
511534
end
512535
end
513536

activesupport/test/core_ext/module_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,15 @@ def test_delegate_missing_to_does_not_delegate_to_private_methods
426426
DecoratedReserved.new(@david).private_name
427427
end
428428

429-
assert_match(/undefined method `private_name' for/, e.message)
429+
assert_match(/undefined method [`']private_name' for/, e.message)
430430
end
431431

432432
def test_delegate_missing_to_does_not_delegate_to_fake_methods
433433
e = assert_raises(NoMethodError) do
434434
DecoratedReserved.new(@david).my_fake_method
435435
end
436436

437-
assert_match(/undefined method `my_fake_method' for/, e.message)
437+
assert_match(/undefined method [`']my_fake_method' for/, e.message)
438438
end
439439

440440
def test_delegate_missing_to_raises_delegation_error_if_target_nil

activesupport/test/core_ext/time_with_zone_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def test_no_method_error_has_proper_context
10801080
e = assert_raises(NoMethodError) {
10811081
@twz.this_method_does_not_exist
10821082
}
1083-
assert_match(/undefined method `this_method_does_not_exist' for.*ActiveSupport::TimeWithZone/, e.message)
1083+
assert_match(/undefined method [`']this_method_does_not_exist' for.*ActiveSupport::TimeWithZone/, e.message)
10841084
assert_no_match "rescue", e.backtrace.first
10851085
end
10861086
end

0 commit comments

Comments
 (0)