From d4f96af0ce911768058567310fcf14ede99e0221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 9 Dec 2019 17:51:13 +0100 Subject: [PATCH 1/5] Prefer `be_empty` to `eq("")` --- spec/commands/clean_spec.rb | 2 +- spec/commands/exec_spec.rb | 2 +- spec/commands/outdated_spec.rb | 2 +- spec/runtime/gem_tasks_spec.rb | 2 +- spec/runtime/setup_spec.rb | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 7f9f84c104e..5cc97de9122 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -782,7 +782,7 @@ def should_not_have_gems(*gems) expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist bundle! :clean - expect(out).to eq("") + expect(out).to be_empty expect(vendored_gems("bundler/gems/extensions")).to exist expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index d2e85a289bf..a5d67c6d682 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -104,7 +104,7 @@ install_gemfile "" sys_exec "#{Gem.ruby} #{command.path}" - expect(out).to eq("") + expect(out).to be_empty expect(err).to be_empty end diff --git a/spec/commands/outdated_spec.rb b/spec/commands/outdated_spec.rb index 7631bcb4574..5096688d003 100644 --- a/spec/commands/outdated_spec.rb +++ b/spec/commands/outdated_spec.rb @@ -324,7 +324,7 @@ def test_group_option(group) context "and no gems are outdated" do it "has empty output" do subject - expect(out).to eq("") + expect(out).to be_empty end end end diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index 4760b6a7490..17b1efdfb3b 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -22,7 +22,7 @@ sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}" end - expect(err).to eq("") + expect(err).to be_empty expected_tasks = [ "rake build", "rake clean", diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 80c38e9f4a6..8769b00426c 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -130,7 +130,7 @@ def clean_load_path(lp) load_path = out.split("\n") rack_load_order = load_path.index {|path| path.include?("rack") } - expect(err).to eq("") + expect(err).to be_empty expect(load_path).to include(a_string_ending_with("dash_i_dir"), "rubylib_dir") expect(rack_load_order).to be > 0 end @@ -1042,7 +1042,7 @@ def Bundler.require(path) RUBY expect(err).to be_empty - expect(out).to eq("") + expect(out).to be_empty end end @@ -1098,8 +1098,8 @@ def lock_with(bundler_version = nil) it "does not change the lock or warn" do lockfile lock_with(Bundler::VERSION.succ) ruby "require '#{lib_dir}/bundler/setup'" - expect(out).to eq("") - expect(err).to eq("") + expect(out).to be_empty + expect(err).to be_empty lockfile_should_be lock_with(Bundler::VERSION.succ) end end @@ -1162,8 +1162,8 @@ def lock_with(ruby_version = nil) let(:ruby_version) { "5.5.5" } it "does not change the lock or warn" do expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile } - expect(out).to eq("") - expect(err).to eq("") + expect(out).to be_empty + expect(err).to be_empty end end From f5a225499d16c8185105251ea4f8e924dd5d55e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 9 Dec 2019 18:03:55 +0100 Subject: [PATCH 2/5] Name variable consistenly Like it is named in the other analogous methods. --- lib/bundler/gem_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 46a66432337..e1eb044553a 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -98,13 +98,13 @@ def install_gem(built_gem_path = nil, local = false) protected def rubygem_push(path) - gem_command = %W[gem push #{path}] - gem_command << "--key" << gem_key if gem_key - gem_command << "--host" << allowed_push_host if allowed_push_host + cmd = %W[gem push #{path}] + cmd << "--key" << gem_key if gem_key + cmd << "--host" << allowed_push_host if allowed_push_host unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file? raise "Your rubygems.org credentials aren't set. Run `gem push` to set them." end - sh_with_input(gem_command) + sh_with_input(cmd) Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}" end From cddda67520e3618cd5a5577a62a5dab4bfa5f9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 9 Dec 2019 18:04:32 +0100 Subject: [PATCH 3/5] Extract a `gem_command` method And use it consistently. --- lib/bundler/gem_helper.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index e1eb044553a..b510572cb86 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -73,8 +73,7 @@ def install def build_gem file_name = nil - gem = ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem" - sh("#{gem} build -V #{spec_path}".shellsplit) do + sh("#{gem_command} build -V #{spec_path}".shellsplit) do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") @@ -85,8 +84,7 @@ def build_gem def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem - gem = ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem" - cmd = "#{gem} install #{built_gem_path}" + cmd = "#{gem_command} install #{built_gem_path}" cmd += " --local" if local out, status = sh_with_status(cmd.shellsplit) unless status.success? && out[/Successfully installed/] @@ -98,7 +96,7 @@ def install_gem(built_gem_path = nil, local = false) protected def rubygem_push(path) - cmd = %W[gem push #{path}] + cmd = %W[#{gem_command} push #{path}] cmd << "--key" << gem_key if gem_key cmd << "--host" << allowed_push_host if allowed_push_host unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file? @@ -211,5 +209,9 @@ def gem_key def gem_push? !%w[n no nil false off 0].include?(ENV["gem_push"].to_s.downcase) end + + def gem_command + ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem" + end end end From 7497037a21168b0fdcbb556770f02668933a0702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 9 Dec 2019 19:13:32 +0100 Subject: [PATCH 4/5] 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. --- lib/bundler/gem_helper.rb | 4 ++-- spec/runtime/gem_tasks_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index b510572cb86..7d4e382be8c 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -86,8 +86,8 @@ 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) - 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 17b1efdfb3b..4b92de76bba 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -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 @@ -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') From aa4488abc7fad3006e0adad410dcf8c7ba080dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 10 Dec 2019 10:08:21 +0100 Subject: [PATCH 5/5] Remove unnecessary -I option This is leftover code that should've been removed on a previous PR. --- spec/support/path.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/path.rb b/spec/support/path.rb index 3e42589f4d3..1c142e2643e 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -22,7 +22,7 @@ def bindir end def gem_bin - @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace" + @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -S gem --backtrace" end def spec_dir