From 04c71d4d03d12dc6895e4f2cbdb70aead54611c7 Mon Sep 17 00:00:00 2001 From: Adrian Goh Jun Wei Date: Sat, 6 Jul 2024 10:18:58 +0800 Subject: [PATCH] Fix tests uninitialized constant rack (#501) * fix: manually insert shakapacker using "echo" instead * manually overwrite "rack" to be v2 --- CHANGELOG.md | 2 ++ spec/generator_specs/generator_spec.rb | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e18046..2af053ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Changes since the last non-beta release. ### Fixed +- Fixes failing tests for Ruby 2.7 due to `Rack::Handler::Puma.respond_to?(:config)` [PR 501](https://github.com/shakacode/shakapacker/pull/501) by [adriangohjw](https://github.com/adriangohjw) + - Improve documentation for using Yarn PnP [PR 484](https://github.com/shakacode/shakapacker/pull/484) by [G-Rath](https://github.com/g-rath). - Remove old `yarn` bin script [PR 483](https://github.com/shakacode/shakapacker/pull/483) by [G-Rath](https://github.com/g-rath). diff --git a/spec/generator_specs/generator_spec.rb b/spec/generator_specs/generator_spec.rb index ed4ed0fb..df56b2a8 100644 --- a/spec/generator_specs/generator_spec.rb +++ b/spec/generator_specs/generator_spec.rb @@ -19,10 +19,23 @@ )) Bundler.with_unbundled_env do - sh_in_dir({}, BASE_RAILS_APP_PATH, %( - gem update bundler - bundle add shakapacker --path "#{GEM_ROOT}" - )) + if RUBY_VERSION.start_with?("2.") + # Bundler's version compatible with Ruby 2 does not support "--path" switch + # Overwriting "rack" version due to unless Rack::Handler::Puma.respond_to?(:config) in Capybara gem v3.39.2 or earlier. + # Issue resolved in Capybara v3.40.0, but Ruby 2.7 support dropped; last compatible version is v3.39.2. + # Ref: https://github.com/shakacode/shakapacker/issues/498 + sh_in_dir({}, BASE_RAILS_APP_PATH, %( + gem update bundler + echo 'gem "shakapacker", :path => "#{GEM_ROOT}"' >> Gemfile + echo 'gem "rack", "< 3.0.0"' >> Gemfile + bundle install + )) + else + sh_in_dir({}, BASE_RAILS_APP_PATH, %( + gem update bundler + bundle add shakapacker --path "#{GEM_ROOT}" + )) + end end end