Permalink
Browse files

Preserve order in dependencies

  • Loading branch information...
jferris committed Nov 11, 2011
1 parent 2d7616b commit e7cacd421d377105b7000e15f4c50732facde35a
Showing with 14 additions and 4 deletions.
  1. +1 −0 features/appraisals.feature
  2. +5 −4 lib/appraisal/gemfile.rb
  3. +8 −0 spec/appraisal/gemfile_spec.rb
@@ -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"
View
@@ -8,7 +8,7 @@ class Gemfile
def initialize
@sources = []
- @dependencies = {}
+ @dependencies = []
end
def load(path)
@@ -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)
@@ -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
@@ -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
@@ -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.