From 40f0456e3b4dc1fb24928e1a9f4063a276a3d535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Mon, 12 Oct 2026 14:57:12 -0600 Subject: [PATCH 1/3] Add --offline to bundle_report compatibility The compatibility report looks up every incompatible gem's released versions on rubygems.org to find one that allows the target Rails. Without network (CI runners, locked-down machines) the report cannot run at all, even though the list of incompatible gems only needs the gemspecs already installed. --offline skips that lookup and lists the incompatible gems on their own. outdated and ruby_check always call rubygems.org, so the flag is refused there instead of being silently ignored. --- README.md | 3 ++ lib/next_rails/bundle_report.rb | 4 +- lib/next_rails/bundle_report/cli.rb | 13 ++++- .../rails_version_compatibility.rb | 22 +++++++- spec/next_rails/bundle_report/cli_spec.rb | 15 ++++++ .../rails_version_compatibility_spec.rb | 50 +++++++++++++++++++ 6 files changed, 102 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bd7cad6..b31e73f 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,9 @@ bundle_report outdated --json # Show gems incompatible with Rails 7.2 bundle_report compatibility --rails-version=7.2 +# Show gems incompatible with Rails 7.2 without looking up compatible versions on rubygems.org +bundle_report compatibility --rails-version=7.2 --offline + # Show gems incompatible with Ruby 3.3 bundle_report compatibility --ruby-version=3.3 diff --git a/lib/next_rails/bundle_report.rb b/lib/next_rails/bundle_report.rb index 26f09f2..f9e7ba3 100644 --- a/lib/next_rails/bundle_report.rb +++ b/lib/next_rails/bundle_report.rb @@ -15,10 +15,10 @@ def ruby_compatibility(ruby_version: nil) puts RubyVersionCompatibility.new(options: options).generate end - def rails_compatibility(rails_version: nil, include_rails_gems: nil) + def rails_compatibility(rails_version: nil, include_rails_gems: nil, offline: false) return unless rails_version - options = { rails_version: rails_version, include_rails_gems: include_rails_gems } + options = { rails_version: rails_version, include_rails_gems: include_rails_gems, offline: offline } puts RailsVersionCompatibility.new(options: options).generate end diff --git a/lib/next_rails/bundle_report/cli.rb b/lib/next_rails/bundle_report/cli.rb index ff98dc9..b30ca9c 100644 --- a/lib/next_rails/bundle_report/cli.rb +++ b/lib/next_rails/bundle_report/cli.rb @@ -30,6 +30,11 @@ def validate_arguments(argv) raise ArgumentError, "Invalid Ruby version format. Example: --ruby-version=3.3" end end + + # The other reports have no offline mode: outdated and ruby_check always call rubygems.org + if argv.include?("--offline") && (report_type != "compatibility" || argv.any? { |arg| arg.start_with?("--ruby-version") }) + raise ArgumentError, "--offline only applies to the compatibility report with --rails-version." + end end def run @@ -49,6 +54,7 @@ def parse_options Examples: #{$0} compatibility --rails-version 5.0 + #{$0} compatibility --rails-version 5.0 --offline #{$0} compatibility --ruby-version 3.3 #{$0} outdated #{$0} outdated --json @@ -77,6 +83,10 @@ def parse_options options[:include_rails_gems] = true end + opts.on("--offline", "List incompatible gems without looking up compatible versions on rubygems.org (defaults to false)") do + options[:offline] = true + end + opts.on("--json", "Output JSON in outdated report (defaults to false)") do options[:format] = "json" end @@ -110,7 +120,8 @@ def execute_report(report_type, options) else NextRails::BundleReport.rails_compatibility( rails_version: options.fetch(:rails_version, "5.0"), - include_rails_gems: options.fetch(:include_rails_gems, false) + include_rails_gems: options.fetch(:include_rails_gems, false), + offline: options.fetch(:offline, false) ) end end diff --git a/lib/next_rails/bundle_report/rails_version_compatibility.rb b/lib/next_rails/bundle_report/rails_version_compatibility.rb index 31fef56..f2159b0 100644 --- a/lib/next_rails/bundle_report/rails_version_compatibility.rb +++ b/lib/next_rails/bundle_report/rails_version_compatibility.rb @@ -12,8 +12,13 @@ def generate def incompatible_gems_by_state @incompatible_gems_by_state ||= begin - incompatible_gems.each { |gem| gem.find_latest_compatible(rails_version: rails_version) } - incompatible_gems.group_by { |gem| gem.state(rails_version) } + if offline + # No lookup ran, so GemInfo#state would call every gem :incompatible + incompatible_gems.empty? ? {} : { not_checked: incompatible_gems } + else + incompatible_gems.each { |gem| gem.find_latest_compatible(rails_version: rails_version) } + incompatible_gems.group_by { |gem| gem.state(rails_version) } + end end end @@ -21,6 +26,15 @@ def incompatible_gems_by_state def erb_output template = <<-ERB +<% if incompatible_gems_by_state[:not_checked] -%> +<%= NextRails::Tint("=> Incompatible with Rails #{rails_version} (compatible versions not looked up):").white.bold %> +<%= NextRails::Tint("These gems will need to be upgraded or replaced before upgrading to Rails #{rails_version}.").italic %> + +<% incompatible_gems_by_state[:not_checked].each do |gem| -%> +<%= gem_header(gem) %> +<% end -%> + +<% end -%> <% if incompatible_gems_by_state[:found_compatible] -%> <%= NextRails::Tint("=> Incompatible with Rails #{rails_version} (with new versions that are compatible):").white.bold %> <%= NextRails::Tint("These gems will need to be upgraded before upgrading to Rails #{rails_version}.").italic %> @@ -83,4 +97,8 @@ def rails_version def include_rails_gems @options[:include_rails_gems] end + + def offline + @options[:offline] + end end diff --git a/spec/next_rails/bundle_report/cli_spec.rb b/spec/next_rails/bundle_report/cli_spec.rb index 7cb89bf..c07a24a 100644 --- a/spec/next_rails/bundle_report/cli_spec.rb +++ b/spec/next_rails/bundle_report/cli_spec.rb @@ -25,9 +25,24 @@ it 'calls rails_compatibility if called with compatibility with rails-version option' do expect(NextRails::BundleReport).to receive(:rails_compatibility) + .with(rails_version: "8.0.0", include_rails_gems: false, offline: false) described_class.new(["compatibility", "--rails-version=8.0.0"]).run end + it 'passes offline to rails_compatibility if called with the offline option' do + expect(NextRails::BundleReport).to receive(:rails_compatibility) + .with(rails_version: "8.0.0", include_rails_gems: false, offline: true) + described_class.new(["compatibility", "--rails-version=8.0.0", "--offline"]).run + end + + it 'raises if offline is used with a report that has no offline mode' do + [["outdated", "--offline"], ["ruby_check", "--rails-version=8.0.0", "--offline"], + ["compatibility", "--ruby-version=3.4.0", "--offline"]].each do |argv| + expect { described_class.new(argv) } + .to raise_error(ArgumentError, /--offline only applies to the compatibility report with --rails-version/) + end + end + it 'calls ruby_compatibility if called with compatibility with ruby-version option' do expect(NextRails::BundleReport).to receive(:ruby_compatibility) described_class.new(["compatibility", "--ruby-version=3.4.0"]).run diff --git a/spec/next_rails/bundle_report/rails_version_compatibility_spec.rb b/spec/next_rails/bundle_report/rails_version_compatibility_spec.rb index eda4ca4..10ce9bf 100644 --- a/spec/next_rails/bundle_report/rails_version_compatibility_spec.rb +++ b/spec/next_rails/bundle_report/rails_version_compatibility_spec.rb @@ -35,6 +35,56 @@ expect(output).to include("- upgrade to 5.8.0") expect(output).to include("gems incompatible with Rails 7.1") end + + it "lists incompatible gems without looking up newer versions when offline" do + specification = Gem::Specification.new do |s| + s.name = "audited" + s.version = "5.1.0" + s.add_dependency "rails", ">= 5.0", "< 7.1" + end + audited = NextRails::GemInfo.new(specification) + + expect(audited).not_to receive(:find_latest_compatible) + + output = + NextRails::BundleReport::RailsVersionCompatibility.new( + gems: [audited], + options: { rails_version: "7.1", include_rails_gems: false, offline: true } + ).generate + + expect(output).to include("Incompatible with Rails 7.1 (compatible versions not looked up):") + expect(output).to include("audited 5.1.0") + expect(output).to include("gems incompatible with Rails 7.1") + end + + it "prints only the count when offline and nothing is incompatible" do + output = + NextRails::BundleReport::RailsVersionCompatibility.new( + gems: [], + options: { rails_version: "7.1", include_rails_gems: false, offline: true } + ).generate + + expect(output).not_to include("=> Incompatible") + expect(output).to include("gems incompatible with Rails 7.1") + end + end + + describe "#incompatible_gems_by_state" do + it "groups the gems under :not_checked when offline" do + specification = Gem::Specification.new do |s| + s.name = "audited" + s.version = "5.1.0" + s.add_dependency "rails", ">= 5.0", "< 7.1" + end + audited = NextRails::GemInfo.new(specification) + + by_state = NextRails::BundleReport::RailsVersionCompatibility.new( + gems: [audited], + options: { rails_version: "7.1", offline: true } + ).incompatible_gems_by_state + + expect(by_state).to eq(not_checked: [audited]) + end end end From 8b13163e6e7060a2bd425f8cfd5f2ae075f65bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Mon, 12 Oct 2026 14:57:24 -0600 Subject: [PATCH 2/3] Add the --offline flag to the changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7ec924..55617a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * Your changes/patches go here. +- [FEATURE: `bundle_report compatibility --offline` lists the incompatible gems without looking up compatible versions on rubygems.org](https://github.com/fastruby/next_rails/pull/201) + # v1.7.0 / 2026-08-05 [(commits)](https://github.com/fastruby/next_rails/compare/v1.6.0...v1.7.0) - [FEATURE: Add support for SimpleCov 1.0](https://github.com/fastruby/next_rails/pull/196) From 5cc26be2e5523a3a72ba382d005a6a2bea12b885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20V=C3=A1squez?= Date: Mon, 12 Oct 2026 15:11:48 -0600 Subject: [PATCH 3/3] Refuse an abbreviated --offline on other reports OptionParser accepts any unique prefix of a long option, so `outdated --off` ran the outdated report with the flag silently ignored: the check only looked for the exact "--offline". --- lib/next_rails/bundle_report/cli.rb | 11 ++++++++++- spec/next_rails/bundle_report/cli_spec.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/next_rails/bundle_report/cli.rb b/lib/next_rails/bundle_report/cli.rb index b30ca9c..52ed9c0 100644 --- a/lib/next_rails/bundle_report/cli.rb +++ b/lib/next_rails/bundle_report/cli.rb @@ -32,11 +32,20 @@ def validate_arguments(argv) end # The other reports have no offline mode: outdated and ruby_check always call rubygems.org - if argv.include?("--offline") && (report_type != "compatibility" || argv.any? { |arg| arg.start_with?("--ruby-version") }) + if option_given?(argv, "--offline") && (report_type != "compatibility" || option_given?(argv, "--ruby-version")) raise ArgumentError, "--offline only applies to the compatibility report with --rails-version." end end + # OptionParser also accepts a unique prefix of a long option (--off for --offline), + # so an exact match would miss those. + def option_given?(argv, option) + argv.any? do |arg| + name = arg.split("=", 2).first + name.length > 2 && option.start_with?(name) + end + end + def run options = parse_options execute_report(@argv.first, options) diff --git a/spec/next_rails/bundle_report/cli_spec.rb b/spec/next_rails/bundle_report/cli_spec.rb index c07a24a..7eb0b03 100644 --- a/spec/next_rails/bundle_report/cli_spec.rb +++ b/spec/next_rails/bundle_report/cli_spec.rb @@ -37,7 +37,7 @@ it 'raises if offline is used with a report that has no offline mode' do [["outdated", "--offline"], ["ruby_check", "--rails-version=8.0.0", "--offline"], - ["compatibility", "--ruby-version=3.4.0", "--offline"]].each do |argv| + ["compatibility", "--ruby-version=3.4.0", "--offline"], ["outdated", "--off"]].each do |argv| expect { described_class.new(argv) } .to raise_error(ArgumentError, /--offline only applies to the compatibility report with --rails-version/) end