Skip to content

Commit

Permalink
Preserve order in dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Nov 11, 2011
1 parent 2d7616b commit e7cacd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions features/appraisals.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Feature: run a rake task through several appraisals
When I successfully run `bundle install --local`
And I successfully run `bundle exec rake appraisal:install --trace`

@puts @announce
Scenario: run a specific task with one appraisal
When I successfully run `bundle exec rake appraisal:1.3.0 version --trace`
Then the output should contain "Loaded 1.3.0"
Expand Down
9 changes: 5 additions & 4 deletions lib/appraisal/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Gemfile

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

def load(path)
Expand All @@ -20,7 +20,8 @@ def run(definitions)
end

def gem(name, *requirements)
@dependencies[name] = Dependency.new(name, requirements)
@dependencies.reject! { |dependency| dependency.name == name }
@dependencies << Dependency.new(name, requirements)
end

def group(name)
Expand All @@ -38,7 +39,7 @@ def to_s
def dup
gemfile = Gemfile.new
@sources.each { |source| gemfile.source source }
dependencies.values.each do |dependency|
dependencies.each do |dependency|
gemfile.gem(dependency.name, *dependency.requirements)
end
gemfile.gemspec(@gemspec.options) if @gemspec
Expand All @@ -56,7 +57,7 @@ def source_entry
end

def dependencies_entry
dependencies.values.map { |dependency| dependency.to_s }.join("\n")
dependencies.map { |dependency| dependency.to_s }.join("\n")
end

def gemspec_entry
Expand Down
8 changes: 8 additions & 0 deletions spec/appraisal/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
gemfile.source "two"
gemfile.to_s.strip.should == %{source "one"\nsource "two"}
end

it "preserves dependency order" do
gemfile = Appraisal::Gemfile.new
gemfile.gem "one"
gemfile.gem "two"
gemfile.gem "three"
gemfile.to_s.should =~ /one.*two.*three/m
end
end

0 comments on commit e7cacd4

Please sign in to comment.