summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-12-09 19:13:32 +0100
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-12-10 10:15:50 +0100
commit7497037a21168b0fdcbb556770f02668933a0702 (patch)
tree0aec83393facc5bd26bb18f730e115d304c85fc6
parentcddda67520e3618cd5a5577a62a5dab4bfa5f9c5 (diff)
downloadbundler-7497037a21168b0fdcbb556770f02668933a0702.tar.gz
Fix `bundle exec rake install` not working
These gem task checks for a specific string in the gem subcommand output. However, if we are inside a bundled environment (`bundle exec rake install` instead of `rake install`), the ruby process will require `bundler/setup` first thing, and initialize a silent UI for rubygems. As a result, the output string will be always empty and the condition for success will always fail. So, even if installation succeeded, user will always be notified of a failure like: ``` foo 1.0 built to pkg/foo-1.0.gem. rake aborted! Couldn't install gem, run `gem install /home/deivid/Code/bundler/tmp/1/bundled_app/pkg/foo-1.0.gem' for more detailed output ... ``` So, don't check for a specific string in the output and only rely on the exit status.
-rw-r--r--lib/bundler/gem_helper.rb4
-rw-r--r--spec/runtime/gem_tasks_spec.rb22
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb
index b510572cb8..7d4e382be8 100644
--- a/lib/bundler/gem_helper.rb
+++ b/lib/bundler/gem_helper.rb
@@ -86,8 +86,8 @@ module Bundler
built_gem_path ||= build_gem
cmd = "#{gem_command} install #{built_gem_path}"
cmd += " --local" if local
- out, status = sh_with_status(cmd.shellsplit)
- unless status.success? && out[/Successfully installed/]
+ _, status = sh_with_status(cmd.shellsplit)
+ unless status.success?
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output"
end
Bundler.ui.confirm "#{name} (#{version}) installed."
diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb
index 17b1efdfb3..4b92de76bb 100644
--- a/spec/runtime/gem_tasks_spec.rb
+++ b/spec/runtime/gem_tasks_spec.rb
@@ -6,15 +6,25 @@ RSpec.describe "require 'bundler/gem_tasks'" do
f.write <<-GEMSPEC
Gem::Specification.new do |s|
s.name = "foo"
+ s.version = "1.0"
+ s.summary = "dummy"
+ s.author = "Perry Mason"
end
GEMSPEC
end
+
bundled_app("Rakefile").open("w") do |f|
f.write <<-RAKEFILE
$:.unshift("#{lib_dir}")
require "bundler/gem_tasks"
RAKEFILE
end
+
+ install_gemfile! <<-G
+ source "#{file_uri_for(gem_repo1)}"
+
+ gem "rake"
+ G
end
it "includes the relevant tasks" do
@@ -35,6 +45,18 @@ RSpec.describe "require 'bundler/gem_tasks'" do
expect(exitstatus).to eq(0) if exitstatus
end
+ it "defines a working `rake install` task" do
+ with_gem_path_as(Spec::Path.base_system_gems.to_s) do
+ sys_exec "#{rake} install", "RUBYOPT" => "-I#{lib_dir}"
+ end
+
+ expect(err).to be_empty
+
+ bundle! "exec rake install"
+
+ expect(err).to be_empty
+ end
+
it "adds 'pkg' to rake/clean's CLOBBER" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do
sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect')