summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2009-09-03 14:19:51 -0700
committerCarl Lerche <carllerche@mac.com>2009-09-03 14:19:51 -0700
commit8ba5e7135ea1a28b93c500d06ee4b4e84ef240df (patch)
tree68788da429e48e2a37201506dbecdd6c3297fd30
parentdfd2dfdb31798d8f8dd0320a43f64c3c4dde3f88 (diff)
downloadbundler-8ba5e7135ea1a28b93c500d06ee4b4e84ef240df.tar.gz
Add a #require_env method to environment
-rw-r--r--lib/bundler/dependency.rb4
-rw-r--r--lib/bundler/environment.rb4
-rw-r--r--spec/bundler/environment_spec.rb40
-rw-r--r--spec/support/helpers.rb13
4 files changed, 55 insertions, 6 deletions
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index b627b58662..828fcbbad9 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -33,11 +33,11 @@ module Bundler
to_gem_dependency.to_s
end
- def require(environment)
+ def require_env(environment)
return unless in?(environment)
@require_as.each do |file|
- super(file)
+ require file
end
@block.call if @block
diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb
index f07a9e2c6f..c45b01a51f 100644
--- a/lib/bundler/environment.rb
+++ b/lib/bundler/environment.rb
@@ -69,6 +69,10 @@ module Bundler
ENV["RUBYOPT"] = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}"
end
+ def require_env(env = nil)
+ dependencies.each { |d| d.require_env(env) }
+ end
+
def root
filename.parent
end
diff --git a/spec/bundler/environment_spec.rb b/spec/bundler/environment_spec.rb
new file mode 100644
index 0000000000..eccfbe8351
--- /dev/null
+++ b/spec/bundler/environment_spec.rb
@@ -0,0 +1,40 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+# More should probably loaded in here
+describe "Bundler::Environment" do
+ it "can require the environment without being in context of it" do
+ build_manifest <<-Gemfile
+ clear_sources
+ gem "rake"
+ Gemfile
+ Dir.chdir(bundled_app) do
+ out = ruby <<-RUBY
+ require 'bundler'
+ Bundler::Environment.load.require_env
+ puts defined?(Rake)
+ RUBY
+ out.should == "constant"
+ end
+ end
+
+ it "only requires gems specific to the requested environment" do
+ build_manifest <<-Gemfile
+ clear_sources
+ gem "rake", :only => "awesome"
+ Gemfile
+ Dir.chdir(bundled_app) do
+ out = ruby <<-RUBY
+ require 'bundler'
+ Bundler::Environment.load.require_env
+ puts defined?(Rake)
+ RUBY
+ out.should == "nil"
+ out = ruby <<-RUBY
+ require 'bundler'
+ Bundler::Environment.load.require_env(:awesome)
+ puts defined?(Rake)
+ RUBY
+ out.should == "constant"
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 757764733b..cdfdd3618c 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -1,10 +1,15 @@
module Spec
module Helpers
- def run_in_context(*args)
- cmd = args.pop.gsub(/(?=")/, "\\")
- env = args.pop || bundled_app("vendor", "gems", "environment")
+ def run_in_context(cmd)
+ env = bundled_app("vendor", "gems", "environment")
+ ruby "-r #{env}", cmd
+ end
+
+ def ruby(opts, ruby = nil)
+ ruby, opts = opts, nil unless ruby
+ ruby.gsub!(/(?=")/, "\\")
lib = File.join(File.dirname(__FILE__), '..', '..', 'lib')
- %x{#{Gem.ruby} -I#{lib} -r #{env} -e "#{cmd}"}.strip
+ %x{#{Gem.ruby} -I#{lib} #{opts} -e "#{ruby}"}.strip
end
def gem_command(command, args = "")