Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Store dependencies in the Gemfile.lock as an array, not a hash

This makes Bundler.require require the gems in the order they appear
in the Gemfile for both the locked and unlocked cases.
  • Loading branch information...
commit f17183b53edc96162cd2e20255d6bc315779b5cf 1 parent 8853c6b
Andy Delcambre adelcambre authored
4 lib/bundler/definition.rb
View
@@ -61,8 +61,8 @@ def resolved_dependencies
end
def dependencies
- @dependencies ||= @details["dependencies"].map do |dep, opts|
- Bundler::Dependency.new(dep, opts.delete("version"), opts)
+ @dependencies ||= @details["dependencies"].map do |opts|
+ Bundler::Dependency.new(opts.delete("name"), opts.delete("version"), opts)
end
end
end
6 lib/bundler/runtime.rb
View
@@ -121,10 +121,10 @@ def details
{ s.name => options }
end
- details["dependencies"] = @definition.dependencies.inject({}) do |h,d|
- info = {"version" => d.requirement.to_s, "group" => d.groups}
+ details["dependencies"] = @definition.dependencies.map do |d|
+ info = {"version" => d.requirement.to_s, "group" => d.groups, "name" => d.name}
info.merge!("require" => d.autorequire) if d.autorequire
- h.merge(d.name => info)
+ info
end
details
end
69 spec/runtime/require_spec.rb
View
@@ -149,4 +149,73 @@ def locked_require(*args)
out.should == "two\nbaz\nqux"
end
end
+
+ describe "order" do
+ before(:each) do
+ build_lib "one", "1.0.0" do |s|
+ s.write "lib/one.rb", "Two.two; puts 'one'"
+ end
+
+ build_lib "two", "1.0.0" do |s|
+ s.write "lib/two.rb", <<-TWO
+ module Two
+ def self.two
+ puts 'module_two'
+ end
+ end
+ puts 'two'
+ TWO
+ end
+ end
+
+ it "works when the gems are in the Gemfile in the correct order" do
+ gemfile <<-G
+ path "#{lib_path}"
+ gem "two"
+ gem "one"
+ G
+
+ run "Bundler.require"
+ check out.should == "two\nmodule_two\none"
+ end
+
+ it "fails when the gems are in the Gemfile in the wrong order" do
+ gemfile <<-G
+ path "#{lib_path}"
+ gem "one"
+ gem "two"
+ G
+
+ run "Bundler.require", :expect_err => true
+ check err.should include("uninitialized constant Two")
+ end
+
+ describe "when locked" do
+ it "works when the gems are in the Gemfile in the correct order" do
+ gemfile <<-G
+ path "#{lib_path}"
+ gem "two"
+ gem "one"
+ G
+
+ bundle :lock
+
+ run "Bundler.require"
+ check out.should == "two\nmodule_two\none"
+ end
+
+ it "fails when the gems are in the Gemfile in the wrong order" do
+ gemfile <<-G
+ path "#{lib_path}"
+ gem "one"
+ gem "two"
+ G
+
+ bundle :lock
+
+ run "Bundler.require", :expect_err => true
+ check err.should include("uninitialized constant Two")
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.