Skip to content

Commit

Permalink
Allow suspenders to be used with a range of Ruby versions
Browse files Browse the repository at this point in the history
Suspenders locks the user in a particular Ruby version (3.0.5 at the
time of writing), a restriction that can sometimes be annoying. This
PR enables Suspenders to be used with a range of safe Ruby versions,
initially from 3.0.5 to 3.2 (which includes any future 3.2.x minor
versions).

Contrary to the Rails version, the Ruby version can be more flexible
if our gems are compatible. Major Rails versions, on the other hand,
tend to be a bit more disruptive and may require deeper changes to
Suspenders. [The last main breaking
change](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/)
was on Ruby 3.0, but we're already past that point.

`.ruby-versions` was the source of truth for the canonical Ruby
version, but in this PR it represents the maximum version.
Unfortunately, it is still needed by CI so we can't delete it. Note
that even without such a file, rubybems validates the runtime Ruby
version through the gemspec.

Closes #1073
  • Loading branch information
Suspenders Boy committed Jun 30, 2023
1 parent cc924a1 commit 3fe8dd6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.5
3.2.2
2 changes: 1 addition & 1 deletion lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def replace_gemfile
end

def ruby_version
create_file ".ruby-version", "#{Suspenders::RUBY_VERSION}\n"
create_file ".ruby-version", "#{::RUBY_VERSION}\n"
end

def configure_i18n_for_missing_translations
Expand Down
9 changes: 5 additions & 4 deletions lib/suspenders/version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Suspenders
RAILS_VERSION = "~> 7.0.0".freeze
RUBY_VERSION = IO
.read("#{File.dirname(__FILE__)}/../../.ruby-version")
.strip
.freeze

minimum_ruby_version = "3.0.5"
maximum_ruby_version = Pathname(__dir__).join("../../.ruby-version").read.strip

RUBY_VERSION_RANGE = [minimum_ruby_version, maximum_ruby_version].freeze
VERSION = "20230113.0".freeze
end
6 changes: 3 additions & 3 deletions spec/features/new_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it "uses custom Gemfile" do
gemfile_file = IO.read("#{project_path}/Gemfile")
expect(gemfile_file).to match(
/^ruby "#{Suspenders::RUBY_VERSION}"$/o
/^ruby "#{RUBY_VERSION}"$/o
)
expect(gemfile_file).to match(
/^gem "rails", "#{Suspenders::RAILS_VERSION}"$/o
Expand All @@ -34,8 +34,8 @@
end
end

it "creates .ruby-version from Suspenders .ruby-version" do
ruby_version_file = IO.read("#{project_path}/.ruby-version")
it "creates .ruby-version with the running ruby version" do
ruby_version_file = project_path.join(".ruby-version").read

expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
end
Expand Down
4 changes: 3 additions & 1 deletion suspenders.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ require "suspenders/version"
require "date"

Gem::Specification.new do |s|
s.required_ruby_version = ">= #{Suspenders::RUBY_VERSION}"
minimum, maximum = Suspenders::RUBY_VERSION_RANGE

s.required_ruby_version = [">= #{minimum}", "<= #{maximum}"]
s.required_rubygems_version = ">= 3.0.0"
s.authors = ["thoughtbot"]

Expand Down
2 changes: 1 addition & 1 deletion templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

ruby "<%= Suspenders::RUBY_VERSION %>"
ruby <%= RUBY_VERSION.inspect %>
<% if options[:api] %>
gem "sprockets", "< 4"
Expand Down

0 comments on commit 3fe8dd6

Please sign in to comment.