diff options
| author | Ian Ker-Seymer <ian.kerseymer@shopify.com> | 2024-05-30 23:03:08 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-02-13 06:28:13 +0000 |
| commit | e785e466daab8c85d8e6cdfb05fa43c488e74db2 (patch) | |
| tree | 634953ceb41ffd5fbf83fc617badd4bdd6044f25 | |
| parent | c0d4f3e92dbfd7744b12c1f0fbb11fcee3ef1313 (diff) | |
[ruby/rubygems] Improve testing config
https://github.com/ruby/rubygems/commit/92e28403c3
4 files changed, 21 insertions, 7 deletions
diff --git a/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt index 8f32a93ab8..09ce97682d 100644 --- a/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +++ b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt @@ -1,7 +1,7 @@ use magnus::{function, prelude::*, Error, Ruby}; -fn hello(subject: String) -> String { - format!("Hello from Rust, {subject}!") +pub fn hello(subject: String) -> String { + format!("Hello {subject}, from Rust!") } #[magnus::init] @@ -14,10 +14,10 @@ fn init(ruby: &Ruby) -> Result<(), Error> { #[cfg(test)] mod tests { use rb_sys_test_helpers::ruby_test; + use super::hello; #[ruby_test] fn test_hello() { - use magnus::RString; - assert_eq!(12, RString::new("rust ❤️ ruby").length()) + assert_eq!("Hello world, from Rust!", hello("world".to_string())); } } diff --git a/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt b/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt index 82cada988c..6552c4addd 100644 --- a/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +++ b/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt @@ -5,7 +5,15 @@ RSpec.describe <%= config[:constant_name] %> do expect(<%= config[:constant_name] %>::VERSION).not_to be nil end +<%- if config[:ext] == 'rust' -%> + it "can call into Rust" do + result = Testing.hello("world") + + expect(result).to be("Hello earth, from Rust!") + end +<%- else -%> it "does something useful" do expect(false).to eq(true) end +<%- end -%> end diff --git a/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt b/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt index 4b35a63071..3c7d8b096e 100644 --- a/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt +++ b/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt @@ -7,7 +7,13 @@ class <%= config[:minitest_constant_name] %> < Minitest::Test refute_nil ::<%= config[:constant_name] %>::VERSION end +<%- if config[:ext] == 'rust' -%> + def test_hello_world + assert_equal "Hello earth, from Rust!", Testing.hello("world") + end +<%- else -%> def test_it_does_something_useful assert false end +<%- end -%> end diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index c078ed84aa..754dd3f31f 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -1736,10 +1736,8 @@ RSpec.describe "bundle gem" do expect(bundled_app("#{gem_name}/ext/#{gem_name}/build.rs")).to exist end - it "includes rake-compiler, rb_sys gems and required_rubygems_version constraint" do + it "includes rake-compiler constraint" do expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"') - expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include('spec.add_dependency "rb_sys"') - expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include('spec.required_rubygems_version = ">= ') end it "depends on compile task for build" do @@ -1782,6 +1780,8 @@ RSpec.describe "bundle gem" do system(env, "cargo", "-V", out: IO::NULL, err: [:child, :out]) skip "cargo not present" unless $?.success? + # Hermetic Cargo setup + RbConfig::CONFIG.each {|k, v| env["RBCONFIG_#{k}"] = v } env end end |
