From d2f797aa4d259e3f005d96a8b8771b2b87fd3775 Mon Sep 17 00:00:00 2001 From: Sebastian Welther Date: Thu, 14 Nov 2024 11:46:31 +0100 Subject: [PATCH 1/2] Allow "ruby file:" syntax in Gemfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the use of the `ruby file:` syntax in Gemfiles, e.g.: ```ruby ruby file: "../.ruby-version" … ``` Previously, Appraisal would fail with `wrong number of arguments (given 0, expected 1) (ArgumentError)` ``` …/appraisal-2.5.0/lib/appraisal/bundler_dsl.rb:66:in `ruby': wrong number of arguments (given 0, expected 1) (ArgumentError) from …/appraisal-2.5.0/lib/appraisal/gemfile.rb:27:in `run' from …/appraisal-2.5.0/lib/appraisal/gemfile.rb:19:in `instance_eval' from …/appraisal-2.5.0/lib/appraisal/gemfile.rb:19:in `run' from …/appraisal-2.5.0/lib/appraisal/gemfile.rb:25:in `block in dup' … ``` --- lib/appraisal/bundler_dsl.rb | 3 ++- spec/appraisal/gemfile_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/appraisal/bundler_dsl.rb b/lib/appraisal/bundler_dsl.rb index e102f4cd..dbb82d4b 100644 --- a/lib/appraisal/bundler_dsl.rb +++ b/lib/appraisal/bundler_dsl.rb @@ -65,8 +65,9 @@ def source(source, &block) end end - def ruby(ruby_version) + def ruby(ruby_version = nil, **kwargs) @ruby_version = ruby_version + @ruby_version = kwargs unless ruby_version end def git(source, options = {}, &block) diff --git a/spec/appraisal/gemfile_spec.rb b/spec/appraisal/gemfile_spec.rb index 666c07ba..d5a869d5 100644 --- a/spec/appraisal/gemfile_spec.rb +++ b/spec/appraisal/gemfile_spec.rb @@ -440,4 +440,17 @@ expect(gemfile.load(tmpfile.path)).to include(File.dirname(tmpfile.path)) end end + + it "supports the ruby file: syntax" do + gemfile = Appraisal::Gemfile.new + + gemfile.ruby file: ".ruby-version" + gemfile.source "one" + + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip + source "one" + + ruby {:file=>".ruby-version"} + GEMFILE + end end From 9a0fd4ddeed43bbae5fc9b79804db5291c40d36d Mon Sep 17 00:00:00 2001 From: Sebastian Welther Date: Wed, 2 Apr 2025 11:27:10 +0200 Subject: [PATCH 2/2] make test pass with all supported ruby versions --- spec/appraisal/gemfile_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/appraisal/gemfile_spec.rb b/spec/appraisal/gemfile_spec.rb index d5a869d5..0f4588b8 100644 --- a/spec/appraisal/gemfile_spec.rb +++ b/spec/appraisal/gemfile_spec.rb @@ -447,10 +447,13 @@ gemfile.ruby file: ".ruby-version" gemfile.source "one" + ruby_version = gemfile.instance_variable_get("@ruby_version") + expected = ruby_version.is_a?(String) ? "ruby #{ruby_version.inspect}" : "ruby(#{ruby_version.inspect})" + expect(gemfile.to_s).to eq <<-GEMFILE.strip_heredoc.strip source "one" - ruby {:file=>".ruby-version"} + #{expected} GEMFILE end end