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

Commit

Permalink
Fix bundle exec rake install not working
Browse files Browse the repository at this point in the history
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
...
```
  • Loading branch information
deivid-rodriguez committed Dec 9, 2019
1 parent cddda67 commit a1277aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bundler/gem_helper.rb
Expand Up @@ -86,7 +86,7 @@ def install_gem(built_gem_path = nil, local = false)
built_gem_path ||= build_gem
cmd = "#{gem_command} install #{built_gem_path}"
cmd += " --local" if local
out, status = sh_with_status(cmd.shellsplit)
out, status = Bundler.with_original_env { sh_with_status(cmd.shellsplit) }
unless status.success? && out[/Successfully installed/]
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output"
end
Expand Down
22 changes: 22 additions & 0 deletions spec/runtime/gem_tasks_spec.rb
Expand Up @@ -6,15 +6,25 @@
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
Expand All @@ -35,6 +45,18 @@
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')
Expand Down

0 comments on commit a1277aa

Please sign in to comment.