Browse files

Add support for git_source in Gemfile/Appraisal

Note that we're converting entries that use custom git source to `:git`
as there's no reliable way to copy Proc definition.

Close #103
  • Loading branch information...
1 parent 0dda291 commit 5675d17a95cfe904cc4b19dfd3f1f4c6d54d3502 @sikachu sikachu committed Jun 2, 2016
View
4 lib/appraisal/appraisal.rb
@@ -48,6 +48,10 @@ def gemspec(options = {})
gemfile.gemspec(options)
end
+ def git_source(*args, &block)
+ gemfile.git_source(*args, &block)
+ end
+
def write_gemfile
File.open(gemfile_path, "w") do |file|
signature = "# This file was generated by Appraisal"
View
22 lib/appraisal/bundler_dsl.rb
@@ -18,14 +18,15 @@ def initialize
@gits = OrderedHash.new
@paths = OrderedHash.new
@source_blocks = OrderedHash.new
+ @git_sources = {}
end
def run(&block)
instance_exec(&block)
end
def gem(name, *requirements)
- @dependencies.add(name, requirements)
+ @dependencies.add(name, substitute_git_source(requirements))
end
def group(*names, &block)
@@ -75,6 +76,14 @@ def gemspec(options = {})
@gemspec = Gemspec.new(options)
end
+ def git_source(source, &block)
+ @git_sources[source] = block
+ end
+
+ protected
+
+ attr_writer :git_sources
+
private
def source_entry
@@ -127,5 +136,16 @@ def #{method_name}_entry_for_dup
def indent(string)
string.strip.gsub(/^(.+)$/, ' \1')
end
+
+ def substitute_git_source(requirements)
+ requirements.each do |requirement|
+ if requirement.is_a?(Hash)
+ (requirement.keys & @git_sources.keys).each do |matching_source|
+ value = requirement.delete(matching_source)
+ requirement[:git] = @git_sources[matching_source].call(value)
+ end
+ end
+ end
+ end
end
end
View
1 lib/appraisal/gemfile.rb
@@ -22,6 +22,7 @@ def run(definitions)
def dup
Gemfile.new.tap do |gemfile|
+ gemfile.git_sources = @git_sources
gemfile.run(for_dup)
end
end
View
7 spec/acceptance/appraisals_file_bundler_dsl_compatibility_spec.rb
@@ -3,13 +3,15 @@
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_gem 'egg'
+ build_git_gems %w(egg croissant pain_au_chocolat)
build_gemfile <<-Gemfile
source 'https://rubygems.org'
+ git_source(:custom_git_source) { |repo| "../gems/\#{repo}" }
ruby RUBY_VERSION
gem 'bagel'
+ gem "croissant", :custom_git_source => "croissant"
git '../gems/egg' do
gem 'egg'
@@ -44,6 +46,7 @@
ruby "1.8.7"
gem 'bread'
+ gem "pain_au_chocolat", :custom_git_source => "pain_au_chocolat"
git '../gems/egg' do
gem 'porched_egg'
@@ -95,8 +98,10 @@
end
gem "bagel"
+ gem "croissant", :git => "../../gems/croissant"
gem "appraisal", :path => #{PROJECT_ROOT.inspect}
gem "bread"
+ gem "pain_au_chocolat", :git => "../../gems/pain_au_chocolat"
group :breakfast do
gem "orange_juice"
View
12 spec/appraisal/gemfile_spec.rb
@@ -418,4 +418,16 @@
end
end
end
+
+ context "git_source support" do
+ before { stub_const('RUBY_VERSION', '1.8.7') }
+
+ it "stores git_source declaration and apply it as git option" do
+ gemfile = Appraisal::Gemfile.new
+ gemfile.git_source(:custom_source) { |repo| "path/#{repo}" }
+ gemfile.gem "bacon", :custom_source => "bacon_pancake"
+
+ expect(gemfile.to_s).to eq %(gem "bacon", :git => "../path/bacon_pancake")
+ end
+ end
end
View
4 spec/support/dependency_helpers.rb
@@ -53,4 +53,8 @@ def build_git_gem(gem_name, version = '1.0.0')
FileUtils.rm_r(path)
end
end
+
+ def build_git_gems(gems)
+ gems.each { |gem| build_git_gem(gem) }
+ end
end

0 comments on commit 5675d17

Please sign in to comment.