Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Test :default group and multiple groups
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Lerche <carllerche@mac.com>
  • Loading branch information
jeremy authored and Carl Lerche committed Feb 4, 2010
1 parent 78c5313 commit f50ccd9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
15 changes: 10 additions & 5 deletions lib/bundler/environment.rb
Expand Up @@ -22,8 +22,9 @@ def setup(*groups)
end

def require(*groups)
dependencies_for(*groups).each do |dep|
dep.autorequire.each do |path|
autorequires = autorequires_for_groups(*groups)
groups.each do |group|
(autorequires[group] || []).each do |path|
Kernel.require(path)
end
end
Expand Down Expand Up @@ -57,7 +58,11 @@ def locked?
end

def dependencies_for(*groups)
@definition.actual_dependencies.select { |d| groups.include?(d.group) }
if groups.empty?
dependencies
else
dependencies.select { |d| groups.include?(d.group) }
end
end

def specs_for(*groups)
Expand Down Expand Up @@ -166,8 +171,8 @@ def details
details
end

def autorequires_for_groups
groups = dependencies.map { |dep| dep.group }.uniq
def autorequires_for_groups(*groups)
groups = dependencies.map { |dep| dep.group }.uniq if groups.empty?
groups.inject({}) do |hash, group|
hash[group] = dependencies_for(group).map { |dep| dep.autorequire }.flatten
hash
Expand Down
25 changes: 14 additions & 11 deletions spec/runtime/require_spec.rb
Expand Up @@ -3,38 +3,41 @@
describe "Bundler.require" do
before :each do
build_lib "one", "1.0.0" do |s|
s.write "lib/baz.rb", "puts 'WIN'"
s.write "lib/qux.rb", "puts 'WIN'"
s.write "lib/baz.rb", "puts 'baz'"
s.write "lib/qux.rb", "puts 'qux'"
end

build_lib "two", "1.0.0" do |s|
s.write "lib/two.rb", "puts 'WIN'"
s.write "lib/two.rb", "puts 'two'"
end

build_lib "three", "1.0.0" do |s|
s.write "lib/three.rb", "puts 'LOSE'"
s.write "lib/three.rb", "puts 'three'"
end

gemfile <<-G
path "#{lib_path('one-1.0.0')}"
path "#{lib_path('two-1.0.0')}"
path "#{lib_path('three-1.0.0')}"
gem "one", :group => "bar", :require => %w(baz qux)
gem "two", :group => "bar"
gem "three", :group => "not"
gem "one", :group => :bar, :require => %w(baz qux)
gem "two"
gem "three", :group => :not
G
end

it "requires the gems" do
run "Bundler.require('bar')"
out.should == "WIN\nWIN\nWIN"
run "Bundler.require(:bar)"
out.should == "baz\nqux"

run "Bundler.require(:default, :bar)"
out.should == "two\nbaz\nqux"
end

it "requires the locked gems" do
bundle :lock

env = bundled_app(".bundle/environment.rb")
out = ruby("require '#{env}'; Bundler.setup('bar'); Bundler.require('bar')")
out.should == "WIN\nWIN\nWIN"
out = ruby("require '#{env}'; Bundler.setup(:default, :bar); Bundler.require(:default, :bar)")
out.should == "two\nbaz\nqux"
end
end

0 comments on commit f50ccd9

Please sign in to comment.