diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index e9ee03b8a2b..c923a0ad379 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -106,7 +106,7 @@ def rubygem_push(path) 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(gem_command) + sh_with_input(gem_command) Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}" end @@ -180,6 +180,13 @@ def name gemspec.name end + def sh_with_input(cmd) + Bundler.ui.debug(cmd) + SharedHelpers.chdir(base) do + abort unless Kernel.system(*cmd) + end + end + def sh(cmd, &block) out, status = sh_with_status(cmd, &block) unless status.success? diff --git a/spec/bundler/gem_helper_spec.rb b/spec/bundler/gem_helper_spec.rb index dc982c6ee78..4fa4831c59e 100644 --- a/spec/bundler/gem_helper_spec.rb +++ b/spec/bundler/gem_helper_spec.rb @@ -11,6 +11,7 @@ before(:each) do global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false" bundle "gem #{app_name}" + prepare_gemspec(app_gemspec_path) end context "determining gemspec" do @@ -218,15 +219,26 @@ def mock_build_message(name, version) end end - it "on releasing" do - mock_build_message app_name, app_version - mock_confirm_message "Tagged v#{app_version}." - mock_confirm_message "Pushed git commits and tags." - expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) + context "on releasing" do + before do + mock_build_message app_name, app_version + mock_confirm_message "Tagged v#{app_version}." + mock_confirm_message "Pushed git commits and tags." - Dir.chdir(app_path) { sys_exec("git push -u origin master") } + Dir.chdir(app_path) { sys_exec("git push -u origin master") } + end - Rake.application["release"].invoke + it "calls rubygem_push with proper arguments" do + expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) + + Rake.application["release"].invoke + end + + it "uses Kernel.system" do + expect(Kernel).to receive(:system).with("gem", "push", app_gem_path.to_s, "--host", "http://example.org").and_return(true) + + Rake.application["release"].invoke + end end it "even if tag already exists" do @@ -249,7 +261,7 @@ def mock_build_message(name, version) before(:each) do Rake.application = Rake::Application.new subject.install - allow(subject).to receive(:sh) + allow(subject).to receive(:sh_with_input) end after(:each) do diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 2914ba66c52..fada9c8bfce 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -182,19 +182,7 @@ def gem_skeleton_assertions(gem_name) in_app_root bundle! "gem newgem --bin" - process_file(bundled_app("newgem", "newgem.gemspec")) do |line| - # Simulate replacing TODOs with real values - case line - when /spec\.metadata\["(?:allowed_push_host|homepage_uri|source_code_uri|changelog_uri)"\]/, /spec\.homepage/ - line.gsub(/\=.*$/, "= 'http://example.org'") - when /spec\.summary/ - line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}") - when /spec\.description/ - line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}") - else - line - end - end + prepare_gemspec(bundled_app("newgem", "newgem.gemspec")) Dir.chdir(bundled_app("newgem")) do gems = ["rake-10.0.2", :bundler] diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 8af2b1ff2db..1e6b70b4714 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -543,6 +543,22 @@ def with_read_only(pattern) Dir[pattern].each(&chmod[0o755, 0o644]) end + # Simulate replacing TODOs with real values + def prepare_gemspec(pathname) + process_file(pathname) do |line| + case line + when /spec\.metadata\["(?:allowed_push_host|homepage_uri|source_code_uri|changelog_uri)"\]/, /spec\.homepage/ + line.gsub(/\=.*$/, "= 'http://example.org'") + when /spec\.summary/ + line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}") + when /spec\.description/ + line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}") + else + line + end + end + end + def process_file(pathname) changed_lines = pathname.readlines.map do |line| yield line