Skip to content

Commit

Permalink
Support zero/multiple sources
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Nov 11, 2011
1 parent f5da0ba commit 2d7616b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion features/appraisals.feature
Expand Up @@ -13,7 +13,6 @@ Feature: run a rake task through several appraisals
When I cd to "projecto"
And I write to "Gemfile" with:
"""
source "http://rubygems.org"
gem "dummy_rake", "0.8.7"
gem "dummy_girl"
group :assets do
Expand Down
2 changes: 0 additions & 2 deletions features/gemspec.feature
Expand Up @@ -49,7 +49,6 @@ Feature: appraisals using an existing gemspec
Scenario: run a gem in the gemspec
And I write to "Gemfile" with:
"""
source "http://rubygems.org"
gemspec
"""
When I add "appraisal" from this project as a dependency
Expand All @@ -62,7 +61,6 @@ Feature: appraisals using an existing gemspec
Scenario: run a gem in the gemspec via path
And I write to "Gemfile" with:
"""
source "http://rubygems.org"
gemspec :path => './specdir'
"""
When I add "appraisal" from this project as a dependency
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/dependency_steps.rb
Expand Up @@ -22,9 +22,9 @@
SPEC
write_file(gem_path, spec)
write_file(version_path, "$#{name}_version = '#{version}'")
run_simple("gem build #{gem_path}")
in_current_dir { `gem build #{gem_path} 2>&1` }
set_env("GEM_HOME", TMP_GEM_ROOT)
run_simple("gem install #{name}-#{version}.gem")
in_current_dir { `gem install #{name}-#{version}.gem 2>&1` }
FileUtils.rm_rf(File.join(current_dir, name))
dirs.pop
end
Expand Down
7 changes: 4 additions & 3 deletions lib/appraisal/gemfile.rb
Expand Up @@ -7,6 +7,7 @@ class Gemfile
attr_reader :dependencies

def initialize
@sources = []
@dependencies = {}
end

Expand All @@ -27,7 +28,7 @@ def group(name)
end

def source(source)
@source = source
@sources << source
end

def to_s
Expand All @@ -36,7 +37,7 @@ def to_s

def dup
gemfile = Gemfile.new
gemfile.source @source
@sources.each { |source| gemfile.source source }
dependencies.values.each do |dependency|
gemfile.gem(dependency.name, *dependency.requirements)
end
Expand All @@ -51,7 +52,7 @@ def gemspec(options = {})
protected

def source_entry
%(source "#{@source}")
@sources.map { |source| %(source "#{source}") }.join("\n")
end

def dependencies_entry
Expand Down
16 changes: 16 additions & 0 deletions spec/appraisal/gemfile_spec.rb
@@ -0,0 +1,16 @@
require 'spec_helper'
require 'appraisal/gemfile'

describe Appraisal::Gemfile do
it "supports gemfiles without sources" do
gemfile = Appraisal::Gemfile.new
gemfile.to_s.strip.should == ""
end

it "supports multiple sources" do
gemfile = Appraisal::Gemfile.new
gemfile.source "one"
gemfile.source "two"
gemfile.to_s.strip.should == %{source "one"\nsource "two"}
end
end

0 comments on commit 2d7616b

Please sign in to comment.