summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-02-05 16:33:53 -0800
committerCarl Lerche <carllerche@mac.com>2010-02-05 16:33:53 -0800
commite400f1d6116e43c47c89490a9a23296c54f18f84 (patch)
treeddb5b4e94cc426f09429adcb81cc077e84311ccd
parent54026a158ea851f688ac4d87a8c739fb30753bfb (diff)
downloadbundler-e400f1d6116e43c47c89490a9a23296c54f18f84.tar.gz
Improve bundle exec
-rw-r--r--lib/bundler.rb4
-rw-r--r--lib/bundler/cli.rb21
-rw-r--r--spec/other/exec_spec.rb24
3 files changed, 39 insertions, 10 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 94cf48ec7e..0f1e883878 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -106,8 +106,6 @@ module Bundler
@settings ||= Settings.new(root)
end
- private
-
def default_gemfile
if ENV['BUNDLE_GEMFILE']
return Pathname.new(ENV['BUNDLE_GEMFILE'])
@@ -124,6 +122,8 @@ module Bundler
raise GemfileNotFound, "The default Gemfile was not found"
end
+ private
+
def configure_gem_home_and_path
if path = settings[:path]
ENV['GEM_HOME'] = File.expand_path(path, root)
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index b381242ad0..ac313d6355 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -93,11 +93,22 @@ module Bundler
desc "exec", "Run the command in context of the bundle"
def exec(*)
ARGV.delete('exec')
- ENV["RUBYOPT"] = %W(
- -I#{File.expand_path('../..', __FILE__)}
- -rbundler/setup
- #{ENV["RUBYOPT"]}
- ).compact.join(' ')
+
+ # Set PATH
+ paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
+ paths.unshift "#{Bundler.bundle_path}/bin"
+ ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
+
+ # Set BUNDLE_GEMFILE
+ ENV['BUNDLE_GEMFILE'] = Bundler.default_gemfile
+
+ # Set RUBYOPT
+ rubyopt = [ENV["RUBYOPT"]].compact
+ rubyopt.unshift "-rbundler/setup"
+ rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}"
+ ENV["RUBYOPT"] = rubyopt.join(' ')
+
+ # Run
Kernel.exec *ARGV
end
diff --git a/spec/other/exec_spec.rb b/spec/other/exec_spec.rb
index 83458056de..43e3b6f0d3 100644
--- a/spec/other/exec_spec.rb
+++ b/spec/other/exec_spec.rb
@@ -5,13 +5,31 @@ describe "bundle exec" do
system_gems "rack-1.0.0", "rack-0.9.1"
end
- it "should have specs" do
- pending "The paths isn't working right for some reason"
+ it "activates the correct gem" do
gemfile <<-G
gem "rack", "0.9.1"
G
- bundle :exec, "rackup"
+ bundle "exec rackup"
out.should == "0.9.1"
end
+
+ it "works when the bins are in ~/.bundle" do
+ install_gemfile <<-G
+ gem "rack"
+ G
+
+ bundle "exec rackup"
+ out.should == "1.0.0"
+ end
+
+ it "works when running from a random directory" do
+ install_gemfile <<-G
+ gem "rack"
+ G
+
+ bundle "exec cd #{tmp('gems')} && rackup"
+
+ out.should == "1.0.0"
+ end
end \ No newline at end of file