From d7cb6e74be95e269f4ca4f99ebfab86391881695 Mon Sep 17 00:00:00 2001 From: Sebastian Welther Date: Thu, 14 Nov 2024 11:46:31 +0100 Subject: [PATCH 1/3] Test for the "ruby file:" syntax --- spec/appraisal/gemfile_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 dbcd772bd6bdadb5a28019e672a802b5cd8efb9d Mon Sep 17 00:00:00 2001 From: Sebastian Welther Date: Thu, 14 Nov 2024 11:26:34 +0100 Subject: [PATCH 2/3] Allow "ruby file:" syntax in Gemfile --- lib/appraisal/bundler_dsl.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/appraisal/bundler_dsl.rb b/lib/appraisal/bundler_dsl.rb index e102f4cd..da02601d 100644 --- a/lib/appraisal/bundler_dsl.rb +++ b/lib/appraisal/bundler_dsl.rb @@ -12,6 +12,7 @@ class BundlerDSL def initialize @sources = [] @ruby_version = nil + @ruby_kwargs = nil @dependencies = DependencyList.new @gemspecs = [] @groups = {} @@ -65,8 +66,9 @@ def source(source, &block) end end - def ruby(ruby_version) + def ruby(ruby_version = nil, **kwargs) @ruby_version = ruby_version + @ruby_kwargs = kwargs end def git(source, options = {}, &block) @@ -110,11 +112,15 @@ def source_entry alias_method :source_entry_for_dup, :source_entry def ruby_version_entry - return unless @ruby_version + if @ruby_version + case @ruby_version + when String then return "ruby #{@ruby_version.inspect}" + else return "ruby(#{@ruby_version.inspect})" + end + end - case @ruby_version - when String then "ruby #{@ruby_version.inspect}" - else "ruby(#{@ruby_version.inspect})" + if @ruby_kwargs && @ruby_kwargs.keys.size.positive? + "ruby #{@ruby_kwargs}" end end From 1e2555e30273d32b64b52efc32c1aaa6196cb40d Mon Sep 17 00:00:00 2001 From: Sebastian Welther Date: Thu, 14 Nov 2024 14:15:31 +0100 Subject: [PATCH 3/3] Repair the existing feature --- lib/appraisal/bundler_dsl.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/appraisal/bundler_dsl.rb b/lib/appraisal/bundler_dsl.rb index da02601d..dbb82d4b 100644 --- a/lib/appraisal/bundler_dsl.rb +++ b/lib/appraisal/bundler_dsl.rb @@ -12,7 +12,6 @@ class BundlerDSL def initialize @sources = [] @ruby_version = nil - @ruby_kwargs = nil @dependencies = DependencyList.new @gemspecs = [] @groups = {} @@ -68,7 +67,7 @@ def source(source, &block) def ruby(ruby_version = nil, **kwargs) @ruby_version = ruby_version - @ruby_kwargs = kwargs + @ruby_version = kwargs unless ruby_version end def git(source, options = {}, &block) @@ -112,15 +111,11 @@ def source_entry alias_method :source_entry_for_dup, :source_entry def ruby_version_entry - if @ruby_version - case @ruby_version - when String then return "ruby #{@ruby_version.inspect}" - else return "ruby(#{@ruby_version.inspect})" - end - end + return unless @ruby_version - if @ruby_kwargs && @ruby_kwargs.keys.size.positive? - "ruby #{@ruby_kwargs}" + case @ruby_version + when String then "ruby #{@ruby_version.inspect}" + else "ruby(#{@ruby_version.inspect})" end end