Today I learned that Ruby 3.2.2 introduced a breaking change in the patch update from Ruby 3.2.1
This may be a sensational way to look at things since the “breaking change” was to remove a deprcated feature; let me explain why I see this as a violation of Semantic Versioning.
According to an answer to StackOverflow: undefined method
exists? for File:Class (NoMethodError)? the plural version of
File.exists? was removed in Ruby 3.2.0 (see “Removed methods”) although the embedded version of Ruby version 3.2.1 that ships with cinc 18.2.7 includes
File.exists? while a straight install of Ruby version 3.2.2 does not.
[root ~]# chef-client --version Cinc Client: 18.2.7 [root ~]# /opt/cinc/embedded/bin/ruby --version ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Doing some more digging into the ruby git repo
git log --graph --pretty=tformat:'%Cred%h%Creset -%C(yellow)%d%Creset %s %-n%Cgreen(%ci)%Creset [%C(yellow)%an%Creset]%-n' --date=relative -S "exists?"
reveals that the
File.exists? method was removed then reverted (re-added) in December 2020 then removed again a year later in December 2021:
... * bb2c360138 - Update NEWS.md for 3.3.0 [ci skip] | (2022-12-26 11:43:08 +0900) [Kazuhiro NISHIYAMA] | * 7d264e8e7b - Copy NEWS.md to doc/NEWS/NEWS-3.2.0.md [ci skip] | (2022-12-26 11:43:08 +0900) [Kazuhiro NISHIYAMA] | ... * 0d9f4ea0d4 - Import spec examples from ruby/syntax_suggest | (2022-08-26 12:15:47 +0900) [Hiroshi SHIBATA] | ... * f59b2e440e - NEWS: Removed methods | (2021-12-31 23:59:50 +0900) [Nobuyoshi Nakada] | ... * bf97415c02 - Removed deprecated Dir.exists? and File.exists? | (2021-12-28 18:36:30 +0900) [Nobuyoshi Nakada] | ... * 4e01ab342a - Revert "Removed deprecated Dir.exists? and File.exists?" | (2020-12-02 19:11:01 +0900) [Nobuyoshi Nakada] | * 1a5205536f - Removed deprecated Dir.exists? and File.exists? | (2020-12-02 17:24:34 +0900) [Nobuyoshi Nakada] | ... * eada635033 - Add category to `rb_warn_deprecated` | (2020-09-02 12:44:33 -0700) [eileencodes] | ... * 67f616c523 - Show the deprecated name in the warning | (2020-04-07 12:49:33 +0900) [Nobuyoshi Nakada] | * d827c718db - [DOC] Removed RDoc of deprecated methods [ci skip] | (2020-04-06 23:06:03 +0900) [Nobuyoshi Nakada] | ... * a58bbd6a51 - Use `rb_warn_deprecated` for `File.exists?` and `Dir.exists?` | (2020-04-06 21:43:32 +0900) [Nobuyoshi Nakada] | ... * fac60be324 - shell.rb is no longer bundled [ci skip] | (2019-12-20 09:40:06 +0900) [Nobuyoshi Nakada] | ... * 3b56a0934f - Removed Shell from the ruby repository. | (2019-09-20 12:56:18 +0900) [Hiroshi SHIBATA] | ... * 4afd897524 - File.exists? is deprecated. | (2019-07-31 07:47:03 +0800) [Hiroshi SHIBATA] | ... * 2a81d3a26a - [rubygems/rubygems] Skip integration test for rake package task. | (2019-07-31 07:47:02 +0800) [Hiroshi SHIBATA] | ... * 6204e0804b - Update to ruby/spec@35a9fba
I am not sure yet which of these commits were released when but safe to say that a library using
File.exists? seems to work in Ruby v3.2.1 and fail in Ruby 3.2.2.
TL;DR if you run into this error when using chefspec with v18.2.7 of the
undefined method `exists?' for File:Class (NoMethodError)?
consider downgrading ruby to match the embedded version in use on your servers.