Skip to content

Commit 9208c17

Browse files
tisbanickcharlton
authored andcommitted
Add support for ruby file: Gemfile syntax
Previously, this would yield an error: appraise "foo" do ruby file: '../.ruby-version' gem "faraday-follow_redirects", "0.3.0" end `Appraisal::BundlerDSL#ruby_version` is emitting a block when the Gemfile DSL ruby method is used. Currently, this is emitted, which is not a method argument but rather a block: ruby {:file=>"../.ruby-version"} To fix this, we need to add `()` to ensure the arguments stay arguments: ruby({:file=>"../.ruby-version"}) This has been tested on Bundler 2.3.27 only — at this point in time we have compatibility issues with others. thoughtbot#218
1 parent 7d26791 commit 9208c17

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/appraisal/bundler_dsl.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ def source_entry
108108
alias_method :source_entry_for_dup, :source_entry
109109

110110
def ruby_version_entry
111-
if @ruby_version
112-
"ruby #{@ruby_version.inspect}"
111+
return unless @ruby_version
112+
113+
case @ruby_version
114+
when String then "ruby #{@ruby_version.inspect}"
115+
else "ruby(#{@ruby_version.inspect})"
113116
end
114117
end
115118

spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,33 @@
149149
gemspec :path => "../sitepress"
150150
Gemfile
151151
end
152+
153+
it 'supports ruby file: ".ruby-version" DSL' do
154+
build_gemfile <<-Gemfile
155+
source 'https://rubygems.org'
156+
157+
ruby RUBY_VERSION
158+
159+
gem 'appraisal', :path => #{PROJECT_ROOT.inspect}
160+
Gemfile
161+
162+
build_appraisal_file <<-Appraisals
163+
appraise 'ruby-version' do
164+
ruby file: ".ruby-version"
165+
end
166+
Appraisals
167+
168+
run 'bundle install --local'
169+
run 'appraisal generate'
170+
171+
expect(content_of 'gemfiles/ruby_version.gemfile').to eq <<-Gemfile.strip_heredoc
172+
# This file was generated by Appraisal
173+
174+
source "https://rubygems.org"
175+
176+
ruby({:file=>".ruby-version"})
177+
178+
gem "appraisal", :path => #{PROJECT_ROOT.inspect}
179+
Gemfile
180+
end
152181
end

0 commit comments

Comments
 (0)