Skip to content

Commit

Permalink
Make git_source work in nested groups
Browse files Browse the repository at this point in the history
If you declare a `git_source` at the top level of your Gemfile or a spec in
Appraisals, it will substitute the gem source in `gem` declarations. If you
want to use those gem sources in nested groups declared with `group`,
`platforms`, `platform`, `source`, `git`, or `path`, the `git_source`
declarations from the top level aren't inherited, so they don't work like they
do with bundler.

Fortunately, in `BundlerDSL` there's a protected `git_sources` writer, and all
the groups are also declared in that file. It should be easy enough to assign
all of the group objects to a copy of the `git_sources`. That would make the
substitutions work.

Fixes #159.
  • Loading branch information
BrianHawley authored and nickcharlton committed Feb 10, 2020
1 parent 92d5134 commit a88ea24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/appraisal/bundler_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ def gem(name, *requirements)
end

def group(*names, &block)
@groups[names] ||= Group.new(names)
@groups[names] ||=
Group.new(names).tap { |g| g.git_sources = @git_sources.dup }
@groups[names].run(&block)
end

def platforms(*names, &block)
@platforms[names] ||= Platform.new(names)
@platforms[names] ||=
Platform.new(names).tap { |g| g.git_sources = @git_sources.dup }
@platforms[names].run(&block)
end

alias_method :platform, :platforms

def source(source, &block)
if block_given?
@source_blocks[source] ||= Source.new(source)
@source_blocks[source] ||=
Source.new(source).tap { |g| g.git_sources = @git_sources.dup }
@source_blocks[source].run(&block)
else
@sources << source
Expand All @@ -54,12 +57,14 @@ def ruby(ruby_version)
end

def git(source, options = {}, &block)
@gits[source] ||= Git.new(source, options)
@gits[source] ||=
Git.new(source, options).tap { |g| g.git_sources = @git_sources.dup }
@gits[source].run(&block)
end

def path(source, options = {}, &block)
@paths[source] ||= Path.new(source, options)
@paths[source] ||=
Path.new(source, options).tap { |g| g.git_sources = @git_sources.dup }
@paths[source].run(&block)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'Appraisals file Bundler DSL compatibility' do
it 'supports all Bundler DSL in Appraisals file' do
build_gems %w(bagel orange_juice milk waffle coffee ham sausage pancake)
build_git_gems %w(egg croissant pain_au_chocolat)
build_git_gems %w(egg croissant pain_au_chocolat omelette)

build_gemfile <<-Gemfile
source 'https://rubygems.org'
Expand All @@ -23,6 +23,7 @@
group :breakfast do
gem 'orange_juice'
gem "omelette", :custom_git_source => "omelette"
end
platforms :ruby, :jruby do
Expand Down Expand Up @@ -106,6 +107,7 @@
group :breakfast do
gem "orange_juice"
gem "omelette", :git => "../../gems/omelette"
gem "bacon"
platforms :rbx do
Expand Down

0 comments on commit a88ea24

Please sign in to comment.