Skip to content

Commit

Permalink
Merge pull request #2138 from Shopify/ko/ruby-3.4
Browse files Browse the repository at this point in the history
Use Ruby 3.4.1 locally and test against it on CI
  • Loading branch information
KaanOzkan authored Jan 7, 2025
2 parents d19a466 + b0ef2b0 commit bce1224
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 25 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.1", "3.2", "3.3", "head"]
ruby: ["3.1", "3.2", "3.3", "3.4", "head"]
rails: ["7.0", "current", "main"]
rubygems: ["3.6.2"]
exclude:
- ruby: "3.1"
rails: "main"
- ruby: "3.4"
rails: "7.0"
include:
- rails: "main"
experimental: true
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4
3.4.1
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PATH
remote: .
specs:
tapioca (0.16.6)
benchmark
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Options:
[--include-dependencies], [--no-include-dependencies], [--skip-include-dependencies] # Generate RBI files for dependencies of the given gem(s)
# Default: false
--typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for generated gem RBIs
# Default: {"activesupport"=>"false"}
# Default: {"activesupport" => "false"}
[--verify], [--no-verify], [--skip-verify] # Verify RBIs are up-to-date
# Default: false
[--doc], [--no-doc], [--skip-doc] # Include YARD documentation from sources when generating RBIs. Warning: this might be slow
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def before_suite(suite)

def record(test)
# Trim leading "test_dddd_" and replace it with "it "
test.name.gsub!(/^test_\d{4}_/, "it ")
test.name = test.name.gsub(/^test_\d{4}_/, "it ")
@test_padding = test.class_name.split("::").size * TEST_PADDING
super
end
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,21 @@ def assert_stdout_includes(result, snippet)
assert_includes(result.out, snippet, result.to_s)
end

sig { params(result: Spoom::ExecResult, pattern: Regexp).void }
def assert_stdout_includes_pattern(result, pattern)
assert_match(pattern, result.out.to_s, result.to_s)
end

sig { params(result: Spoom::ExecResult, snippet: String).void }
def assert_stderr_includes(result, snippet)
assert_includes(result.err, snippet, result.to_s)
end

sig { params(result: Spoom::ExecResult, pattern: Regexp).void }
def assert_stderr_includes_pattern(result, pattern)
assert_match(pattern, result.err.to_s, result.to_s)
end

private

sig { params(name: String).returns(String) }
Expand Down
10 changes: 9 additions & 1 deletion spec/tapioca/cli/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module Tapioca
class ConfigTest < SpecWithProject
include Tapioca::Helpers::Test::Template

describe "cli::configuration" do
before(:all) do
@project.require_default_gems
Expand Down Expand Up @@ -107,14 +109,20 @@ class ConfigTest < SpecWithProject

result = @project.tapioca("gem")

hash_inspect = if ruby_version(">= 3.4")
'"msgpack" => false'
else
'"msgpack"=>false'
end

assert_stderr_equals(<<~ERR, result)
Configuration file sorbet/tapioca/config.yml has the following errors:
- invalid value for option only for key dsl - expected Array[String] but found [1, false]
- invalid value for option exclude for key dsl - expected Array[String] but found [1, false]
- invalid value for option exclude for key gem - expected Array[String] but found [1, false]
- invalid value for option typed_overrides for key gem - expected Hash[String, String] but found {"msgpack"=>false}
- invalid value for option typed_overrides for key gem - expected Hash[String, String] but found {#{hash_inspect}}
ERR

assert_empty_stdout(result)
Expand Down
21 changes: 14 additions & 7 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2638,9 +2638,11 @@ class Post
Loading DSL extension classes... Hi from test extension
OUT

err = "tapioca/tests/dsl_spec/project/sorbet/tapioca/extensions/test.rb:2:in `<top (required)>': " \
"Raising from test extension (RuntimeError)"
assert_stderr_includes(result, err)
err = %r{
tapioca/tests/dsl_spec/project/sorbet/tapioca/extensions/test\.rb:2:in\s['`]<top\s\(required\)>':\s
Raising\sfrom\stest\sextension\s\(RuntimeError\)
}x
assert_stderr_includes_pattern(result, err)

refute_success_status(result)
end
Expand Down Expand Up @@ -3010,9 +3012,11 @@ class Application < Rails::Application
"please pass `--no-halt-upon-load-error` to the tapioca command in sorbet/tapioca/config.yml or in CLI." \
"\nError during application loading"
assert_stdout_includes(res, out)
err = "tapioca/tests/dsl_spec/project/config/application.rb:5:in `<class:Application>': Error during " \
"application loading (RuntimeError)"
assert_stderr_includes(res, err)
err = %r{
tapioca/tests/dsl_spec/project/config/application\.rb:5:in\s['`]<class:Application>':\s
Error\sduring\sapplication\sloading\s\(RuntimeError\)
}x
assert_stderr_includes_pattern(res, err)
refute_success_status(res)
end

Expand All @@ -3025,7 +3029,10 @@ class Application < Rails::Application
"please pass `--no-halt-upon-load-error` to the tapioca command in sorbet/tapioca/config.yml or in CLI." \
"\nError during application loading"
assert_stdout_includes(res, out)
assert_stdout_includes(res, "tapioca/tests/dsl_spec/project/config/application.rb:5:in `<class:Application>'")
assert_stdout_includes_pattern(
res,
%r{tapioca/tests/dsl_spec/project/config/application\.rb:5:in ['`]<class:Application>'},
)
assert_stdout_includes(res, <<~OUT)
Continuing RBI generation without loading the Rails application.
Done
Expand Down
28 changes: 15 additions & 13 deletions spec/tapioca/cli/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def fizz; end
end

it "must generate RBI for a default gem" do
gem_name = "base64"
gem_top_level_constant = "module Base64"
gem_name = "cgi"
gem_top_level_constant = "class CGI"

gem_spec = ::Gem::Specification.default_stubs("*.gemspec").find do |spec|
spec.name == gem_name && spec.default_gem?
Expand Down Expand Up @@ -747,7 +747,7 @@ class Secret; end

it "must generate git gem RBIs with source revision numbers" do
@project.write_gemfile!(<<~GEMFILE, append: true)
gem("faraday", git: "https://github.com/lostisland/faraday", ref: "23e249563613971ced8f851230c46b9eeeefe931")
gem("faraday", git: "https://github.com/lostisland/faraday", ref: "a9cf00425e3abc99b78952af44deb2912a65a882")
GEMFILE

@project.bundle_install!
Expand All @@ -757,7 +757,7 @@ class Secret; end
assert_stdout_includes(result, "Compiled faraday")

assert_project_file_exist(
"sorbet/rbi/gems/faraday@2.0.0.alpha.pre.4-23e249563613971ced8f851230c46b9eeeefe931.rbi",
"sorbet/rbi/gems/faraday@2.12.2-a9cf00425e3abc99b78952af44deb2912a65a882.rbi",
)

assert_empty_stderr(result)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ class User; end
end

it "generates correct RBIs for a Rails engine in Zeitwerk mode" do
@project.require_real_gem("rails", "6.1.7.2")
@project.require_real_gem("rails", "7.1.5")
@project.require_real_gem("turbo-rails", "1.3.2")
@project.bundle_install!

Expand All @@ -1337,7 +1337,7 @@ class User; end
module Foo
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.load_defaults 7.1
config.autoloader = :zeitwerk
end
end
Expand All @@ -1358,7 +1358,7 @@ class Application < Rails::Application
end

it "generates correct RBIs for a Rails engine in Classic mode" do
@project.require_real_gem("rails", "6.1.7.2")
@project.require_real_gem("rails", "7.1.5")
@project.require_real_gem("turbo-rails", "1.3.2")
@project.bundle_install!

Expand All @@ -1368,7 +1368,7 @@ class Application < Rails::Application
module Foo
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.load_defaults 7.1
config.autoloader = :classic
end
end
Expand Down Expand Up @@ -2029,9 +2029,11 @@ class Application < Rails::Application
"please pass `--no-halt-upon-load-error` to the tapioca command in sorbet/tapioca/config.yml or in CLI." \
"\nError during application loading"
assert_stdout_includes(result, out)
err = "/tmp/tapioca/tests/gem_spec/project/config/application.rb:5:in `<class:Application>': Error during " \
"application loading (RuntimeError)"
assert_stderr_includes(result, err)
err = %r{
tapioca/tests/gem_spec/project/config/application\.rb:5:in\s['`]<class:Application>':\s
Error\sduring\sapplication\sloading\s\(RuntimeError\)
}x
assert_stderr_includes_pattern(result, err)
refute_success_status(result)
end

Expand All @@ -2044,9 +2046,9 @@ class Application < Rails::Application
"please pass `--no-halt-upon-load-error` to the tapioca command in sorbet/tapioca/config.yml or in CLI." \
"\nError during application loading"
assert_stdout_includes(result, out)
assert_stdout_includes(
assert_stdout_includes_pattern(
result,
"/tmp/tapioca/tests/gem_spec/project/config/application.rb:5:in `<class:Application>'",
%r{tapioca/tests/gem_spec/project/config/application\.rb:5:in ['`]<class:Application>'},
)
assert_stdout_includes(result, <<~OUT)
Continuing RBI generation without loading the Rails application.
Expand Down
1 change: 1 addition & 0 deletions tapioca.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|

spec.metadata["allowed_push_host"] = "https://rubygems.org"

spec.add_dependency("benchmark")
spec.add_dependency("bundler", ">= 2.2.25")
spec.add_dependency("netrc", ">= 0.11.0")
spec.add_dependency("parallel", ">= 1.21.0")
Expand Down

0 comments on commit bce1224

Please sign in to comment.