Write specs for new Ruby 3.3 features and changes
ruby/spec already contains some specs for 3.3, but we should aim to cover all new features and important changes. This will improve the test coverage of these features (and maybe discover a few bugs along the way), allow other Ruby implementations to implement the changes faster with more confidence and document clearly the new behavior.
The new specs should be within a version guard block:
ruby_version_is "3.3" do
# New specs
end
NOTE: https://rubyreferences.github.io/rubychanges/3.3.html gives more details for many features and changes.
From https://github.com/ruby/ruby/blob/master/doc/NEWS/NEWS-3.3.0.md:
NEWS for Ruby 3.3.0
Core classes updates
Note: We're only listing outstanding class updates.
Array
- [x] Array#pack now raises ArgumentError for unknown directives. [Bug #19150]
Dir
- [x] Dir.for_fd added for returning a Dir object for the directory specified by the provided directory file descriptor. [Feature #19347]
- [x] Dir.fchdir added for changing the directory to the directory specified by the provided directory file descriptor. [Feature #19347]
- [x] Dir#chdir added for changing the directory to the directory specified by
the provided
Dirobject. [Feature #19347]
Encoding
- [x]
Encoding#replicatehas been removed, it was already deprecated. [Feature #18949]
Fiber
- [x] Introduce Fiber#kill. [Bug #595]
fiber = Fiber.new do
while true
puts "Yielding..."
Fiber.yield
end
ensure
puts "Exiting..."
end
fiber.resume
# Yielding...
fiber.kill
# Exiting...
MatchData
- [x] MatchData#named_captures now accepts optional
symbolize_nameskeyword. [Feature #19591]
Module
- [x] Module#set_temporary_name added for setting a temporary name for a module. [Feature #19521]
ObjectSpace::WeakKeyMap
- [x] New core class to build collections with weak references. The class use equality semantic to lookup keys like a regular hash, but it doesn't hold strong references on the keys. [Feature #18498]
ObjectSpace::WeakMap
- [x] ObjectSpace::WeakMap#delete was added to eagerly clear weak map entries. [Feature #19561]
Proc
- [x] Now Proc#dup and Proc#clone call
#initialize_dupand#initialize_clonehooks respectively. [Feature #19362]
Process
- [x] New Process.warmup method that notify the Ruby virtual machine that the boot sequence is finished, and that now is a good time to optimize the application. This is useful for long-running applications. The actual optimizations performed are entirely implementation-specific and may change in the future without notice. [Feature #18885]
Process::Status
- [x] Process::Status#& and Process::Status#>> are deprecated. [Bug #19868]
Range
- [x] Range#reverse_each can now process beginless ranges with an Integer endpoint. [Feature #18515]
- [x] Range#reverse_each now raises TypeError for endless ranges. [Feature #18551]
- [x] Range#overlap? added for checking if two ranges overlap. [Feature #19839]
Refinement
- [x] Add Refinement#target as an alternative of Refinement#refined_class. Refinement#refined_class is deprecated and will be removed in Ruby 3.4. [Feature #19714]
Regexp
- [ ] The cache-based optimization now supports lookarounds and atomic groupings. That is, match for Regexp containing these extensions can now also be performed in linear time to the length of the input string. However, these cannot contain captures and cannot be nested. [Feature #19725]
String
- [x] String#unpack now raises ArgumentError for unknown directives. [Bug #19150]
- [x] String#bytesplice now accepts new arguments index/length or range of the source string to be copied. [Feature #19314]
Thread::Queue
- [x] Thread::Queue#freeze now raises TypeError. [Bug #17146]
Thread::SizedQueue
- [x] Thread::SizedQueue#freeze now raises TypeError. [Bug #17146]
Time
- [x] Time.new with a string argument became stricter. [Bug #19293]
Time.new('2023-12-20')
# no time information (ArgumentError)
TracePoint
- [x] TracePoint supports
rescueevent. When the raised exception was rescued, the TracePoint will fire the hook.rescueevent only supports Ruby-levelrescue. [Feature #19572]
Socket
-
[x] Socket#recv and Socket#recv_nonblock returns
nilinstead of an empty string on closed connections. Socket#recvmsg and Socket#recvmsg_nonblock returnsnilinstead of an empty packet on closed connections. [Bug #19012] -
[ ] Name resolution such as Socket.getaddrinfo, Socket.getnameinfo, Addrinfo.getaddrinfo, etc. can now be interrupted. [Feature #19965]
Random
- [x] Random::Formatter#alphanumeric is extended to accept optional
charskeyword argument. [Feature #18183]
Compatibility issues
-
[x] Subprocess creation/forking via the following file open methods is deprecated. [Feature #19630]
- Kernel#open
- URI.open
- IO.binread
- IO.foreach
- IO.readlines
- IO.read
- IO.write
-
[x] When given a non-lambda, non-literal block, Kernel#lambda with now raises ArgumentError instead of returning it unmodified. These usages have been issuing warnings under the
Warning[:deprecated]category since Ruby 3.0.0. [Feature #19777] -
[x]
itcalls without arguments in a block with no ordinary parameters are deprecated.itwill be a reference to the first block parameter in Ruby 3.4. [Feature #18980] -
[x] Error message for NoMethodError have changed to not use the target object's
#inspectfor efficiency, and says "instance of ClassName" instead. [Feature #18285]([1] * 100).nonexisting # undefined method `nonexisting' for an instance of Array (NoMethodError) -
[x] Now anonymous parameters forwarding is disallowed inside a block that uses anonymous parameters. [Feature #19370]
C API updates
rb_postponed_job updates
- [ ] New APIs and deprecated APIs (see comments for details)
- [ ] added:
rb_postponed_job_preregister() - [ ] added:
rb_postponed_job_trigger() - [ ] deprecated:
rb_postponed_job_register()(and semantic change. see below) - [ ] deprecated:
rb_postponed_job_register_one()
- [ ] added:
- [ ] The postponed job APIs have been changed to address some rare crashes.
To solve the issue, we introduced new two APIs and deprecated current APIs.
The semantics of these functions have also changed slightly;
rb_postponed_job_registernow behaves like theoncevariant in that multiple calls with the samefuncmight be coalesced into a single execution of thefunc[Feature #20057]
Some updates for internal thread event hook APIs
- [ ]
rb_internal_thread_event_data_twith a target Ruby thread (VALUE) and callback functions (rb_internal_thread_event_callback) receive it. https://github.com/ruby/ruby/pull/8885 - [ ] The following functions are introduced to manipulate Ruby thread local data
from internal thread event hook APIs (they are introduced since Ruby 3.2).
https://github.com/ruby/ruby/pull/8936
- [ ]
rb_internal_thread_specific_key_create() - [ ]
rb_internal_thread_specific_get() - [ ]
rb_internal_thread_specific_set()
- [ ]
-
[ ]
rb_profile_thread_frames()is introduced to get a frames from a specific thread. [Feature #10602] -
[ ]
rb_data_define()is introduced to defineData. [Feature #19757] -
[ ]
rb_ext_resolve_symbol()is introduced to search a function from extension libraries. [Feature #20005]
IO related updates:
- [x] The details of
rb_io_twill be hidden and deprecated attributes are added for each members. [Feature #19057] - [x]
rb_io_path(VALUE io)is introduced to get a path ofio. - [x]
rb_io_closed_p(VALUE io)to get opening or closing ofio. - [x]
rb_io_mode(VALUE io)to get the mode ofio. - [x]
rb_io_open_descriptor()is introduced to make an IO object from a file descriptor.
A couple of these items have already been implemented and can be marked as done:
Array#packnow raises ArgumentError for unknown directives (9d69b95a7bbac3d89e7218a98bd50ecf173d9c6f)Dir.fchdiradded for changing the directory to the directory specified by the provided directory file descriptor (3d7233ed2c36c730721a4fa0a9040f373d0bedac)Encoding#replicatehas been removed, it was already deprecated (4f4dd517e731d66b3ef42c4128484e10c17654d1, 81669f67d942a2875e8685821d810019b88ebabd)- Introduce
Fiber#kill(29c6f1e7a32205da29714b261bf9b2290ec6eee1) MatchData#named_capturesnow accepts optional symbolize_names keyword (43d55792065f68ac2a3a00d4bc63213f5a8930ba)Module#set_temporary_nameadded for setting a temporary name for a module (07a66bf6780606b89c2e200e1d4ad7a4134a24f0, 3db32e8e3479c5fc22fd6de75ad4dcb78f66def2)ObjectSpace::WeakKeyMap: New core class to build collections with weak references. The class use equality semantic to lookup keys like a regular hash, but it doesn't hold strong references on the keys (923a7687af6ef0de7e2865ba9861a890e7e845e9)ObjectSpace::WeakMap#deletewas added to eagerly clear weak map entries (b19eb32379a5fcecbb89dc5258e19dc8ff336e42)- New
Process.warmupmethod that notify the Ruby virtual machine that the boot sequence is finished ... (6ac8ed266aa709b4123cfd02078d94d8383a199e, 6f959e3f20513be35e955cbeecf4375c9ead517a) Range#reverse_eachcan now process beginless ranges with an Integer endpoint: #1169Range#reverse_eachnow raises TypeError for endless ranges: #1169String#unpacknow raises ArgumentError for unknown directives (9d69b95a7bbac3d89e7218a98bd50ecf173d9c6f)- String#bytesplice now accepts new arguments index/length or range of the source string to be copied (15c4b26f11e8d3f155d008cc035c2f5767c55d37)
Thread::Queue#freezenow raises TypeError (ae05448017805b0695d0c8fbb030ad49ffdc6cd7)Thread::SizedQueue#freezenow raises TypeError (ae05448017805b0695d0c8fbb030ad49ffdc6cd7)- Time.new with a string argument became stricter (7ae08bad096c775de68a1fa723d27f3cc6a0f264)
- Subprocess creation/forking via the following file open methods is deprecated (a38bf162bf896d4257bacca02b834c630d5ec65b)
- When given a non-lambda, non-literal block, Kernel#lambda with now raises ArgumentError instead of returning it unmodified (316ea5c1b13384d7cb058dbc9be33b3210c191ac)
- Error message for NoMethodError have changed to not use the target object's
#inspectfor efficiency, and says "instance of ClassName" instead: There is an implicit test at https://github.com/ruby/spec/blob/8e0b9e53eae1a7161cbe35544dca94c100643405/core/objectspace/weakkeymap/element_set_spec.rb#L27, but this should probably get a dedicated test. rb_io_path(VALUE io)is introduced to get a path ofio(f6102af26216ee282bd49ebbeb1fe959c59f7f86)rb_io_mode(VALUE io)to get the mode ofio(f6102af26216ee282bd49ebbeb1fe959c59f7f86)
@herwinw Thank you! I have updated the list.
In addition
Error message for NoMethodError have changed to not use the target object's #inspect for efficiency,
It seems it was also addressed, in 72cd673dc6c5b693328a58ef81fe37f8a768c533
Array#pack now raises ArgumentError for unknown directives String#unpack now raises ArgumentError for unknown directives
The mentioned tests check for NULL byte. I would say we need more explicit tests that check not supported directives
Time.new with a string argument became stricter
There is no any 3.3 specific test for String argument validation. So I assume that the change wasn't covered with specs.