From e806c0325e522c54a6a3d54639fbb65f47745cff Mon Sep 17 00:00:00 2001 From: RobL Date: Thu, 23 Jul 2026 10:34:29 +0200 Subject: [PATCH] Support Ruby 4.0 and Rails 8 Widen the activerecord dependency range (Gemfile and gemspec) so Rails 8 can be resolved, and drop the ruby_dep pin that hard-capped Ruby below 3.x. Add compatibility fixes needed to run the test suite on Ruby 4.0: a File.exists? shim for the unmaintained `files` test gem, and backtrace assertions that accept both the old and new Ruby quote styles. CI now also runs the test matrix against Ruby 4.0. --- .github/workflows/ci.yml | 3 ++- Gemfile | 3 +-- annotate.gemspec | 2 +- spec/lib/annotate/annotate_models_spec.rb | 4 ++-- spec/spec_helper.rb | 10 ++++++++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f907097..a775d36a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ['2.7'] + ruby: ['2.7', '4.0'] steps: - name: Checkout @@ -30,4 +30,5 @@ jobs: run: bundle exec rspec - name: Rubocop + if: matrix.ruby == '2.7' run: bundle exec rubocop diff --git a/Gemfile b/Gemfile index 0998ee0d..063acf81 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' ruby '>= 2.4.0' -gem 'activerecord', '>= 4.2.5', '< 6', require: false +gem 'activerecord', '>= 4.2.5', '< 9', require: false gem 'rake', require: false group :development do @@ -29,7 +29,6 @@ group :development, :test do gem 'coveralls' gem 'overcommit' - gem 'ruby_dep', '1.5.0' platforms :mri, :mingw do gem 'pry', require: false diff --git a/annotate.gemspec b/annotate.gemspec index 43b2ac99..9f262572 100644 --- a/annotate.gemspec +++ b/annotate.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.specification_version = 4 if s.respond_to? :specification_version s.add_runtime_dependency(%q, '>= 10.4', '< 14.0') - s.add_runtime_dependency(%q, ['>= 3.2', '< 8.0']) + s.add_runtime_dependency(%q, ['>= 3.2', '< 9.0']) s.metadata = { "bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/", diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index 09647461..349bbc43 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -3083,12 +3083,12 @@ class User < ActiveRecord::Base it 'displays just the error message with trace disabled (default)' do expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true }.to output(a_string_including("Unable to deannotate #{@model_dir}/user.rb: oops")).to_stderr - expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true }.not_to output(a_string_including("/user.rb:2:in `'")).to_stderr + expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true }.not_to output(%r{/user\.rb:2:in [`']'}).to_stderr end it 'displays the error message and stacktrace with trace enabled' do expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true }.to output(a_string_including("Unable to deannotate #{@model_dir}/user.rb: oops")).to_stderr - expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true }.to output(a_string_including("/user.rb:2:in `'")).to_stderr + expect { AnnotateModels.remove_annotations model_dir: @model_dir, is_rake: true, trace: true }.to output(%r{/user\.rb:2:in [`']'}).to_stderr end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e461e55b..a2d8b672 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,6 +34,16 @@ require 'annotate/constants' require 'byebug' +# The `files` gem (test-only) still calls the `File.exists?` alias, which was +# removed in Ruby 3.2+. Restore it for the test run only. +class File + unless respond_to?(:exists?) + def self.exists?(path) + exist?(path) + end + end +end + RSpec.configure do |config| config.order = 'random' config.filter_run_when_matching :focus