[rubygems/rubygems] Extract stdboth spec helper

bb13f4e702
This commit is contained in:
David Rodríguez 2025-06-05 10:52:37 +02:00 committed by Hiroshi SHIBATA
parent ee55b82b34
commit d95f7a3c43
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
15 changed files with 36 additions and 32 deletions

View file

@ -179,7 +179,7 @@ RSpec.describe "bundle executable" do
shared_examples_for "no warning" do
it "prints no warning" do
bundle "fail", env: { "BUNDLER_VERSION" => bundler_version }, raise_on_error: false
expect(last_command.stdboth).to eq("Could not find command \"fail\".")
expect(stdboth).to eq("Could not find command \"fail\".")
end
end
@ -228,10 +228,10 @@ To update to the most recent version, run `bundle update --bundler`
context "running a parseable command" do
it "prints no warning" do
bundle "config get --parseable foo", env: { "BUNDLER_VERSION" => bundler_version }
expect(last_command.stdboth).to eq ""
expect(stdboth).to eq ""
bundle "platform --ruby", env: { "BUNDLER_VERSION" => bundler_version }, raise_on_error: false
expect(last_command.stdboth).to eq "Could not locate Gemfile"
expect(stdboth).to eq "Could not locate Gemfile"
end
end

View file

@ -260,7 +260,7 @@ RSpec.describe "bundle install with gem sources" do
gem "myrack"
G
expect(last_command.stdboth).to include(plugin_msg)
expect(stdboth).to include(plugin_msg)
end
describe "with a gem that installs multiple platforms" do
@ -722,7 +722,7 @@ RSpec.describe "bundle install with gem sources" do
gem "ajp-rails", "0.0.0"
G
expect(last_command.stdboth).not_to match(/Error Report/i)
expect(stdboth).not_to match(/Error Report/i)
expect(err).to include("An error occurred while installing ajp-rails (0.0.0), and Bundler cannot continue.").
and include("Bundler::APIResponseInvalidDependenciesError")
end

View file

@ -529,7 +529,7 @@ RSpec.describe "bundle gem" do
system_gems gems, path: path, gem_repo: gem_repo2
bundle "exec rake build", dir: bundled_app("newgem")
expect(last_command.stdboth).not_to include("ERROR")
expect(stdboth).not_to include("ERROR")
end
context "gem naming with relative paths" do

View file

@ -1140,7 +1140,7 @@ RSpec.describe "bundle update in more complicated situations" do
end
bundle "update thin myrack-obama"
expect(last_command.stdboth).to include "Bundler attempted to update myrack-obama but its version stayed the same"
expect(stdboth).to include "Bundler attempted to update myrack-obama but its version stayed the same"
expect(the_bundle).to include_gems "thin 2.0", "myrack 10.0", "myrack-obama 1.0"
end
@ -1158,7 +1158,7 @@ RSpec.describe "bundle update in more complicated situations" do
bundle "update foo"
expect(last_command.stdboth).not_to include "attempted to update"
expect(stdboth).not_to include "attempted to update"
end
it "will not warn when changing gem sources but not versions" do
@ -1176,7 +1176,7 @@ RSpec.describe "bundle update in more complicated situations" do
bundle "update myrack"
expect(last_command.stdboth).not_to include "attempted to update"
expect(stdboth).not_to include "attempted to update"
end
it "will update only from pinned source" do
@ -1266,7 +1266,7 @@ RSpec.describe "bundle update in more complicated situations" do
it "is not updated because it is not actually included in the bundle" do
simulate_platform "x86_64-linux" do
bundle "update a"
expect(last_command.stdboth).to include "Bundler attempted to update a but it was not considered because it is for a different platform from the current one"
expect(stdboth).to include "Bundler attempted to update a but it was not considered because it is for a different platform from the current one"
expect(the_bundle).to_not include_gem "a"
end
end
@ -1307,7 +1307,7 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler"
it "should explain that bundler conflicted and how to resolve the conflict" do
bundle "update", all: true, raise_on_error: false
expect(last_command.stdboth).not_to match(/in snapshot/i)
expect(stdboth).not_to match(/in snapshot/i)
expect(err).to match(/current Bundler version/i).
and match(/Install the necessary version with `gem install bundler:9\.9\.9`/i)
end

View file

@ -43,7 +43,7 @@ RSpec.describe "bundle install with :allow_offline_install" do
G
bundle :update, artifice: "fail", all: true
expect(last_command.stdboth).to include "Using the cached data for the new index because of a network error"
expect(stdboth).to include "Using the cached data for the new index because of a network error"
expect(the_bundle).to include_gems("myrack-obama 1.0", "myrack 1.0.0")
end

View file

@ -192,7 +192,7 @@ RSpec.describe "bundle install from an existing gemspec" do
install_gemfile <<-G, raise_on_error: false
gemspec :path => '#{tmp("foo")}'
G
expect(last_command.stdboth).not_to include("ahh")
expect(stdboth).not_to include("ahh")
end
it "allows the gemspec to activate other gems" do

View file

@ -1673,7 +1673,7 @@ In Gemfile:
end
G
expect(last_command.stdboth).to_not include("password1")
expect(stdboth).to_not include("password1")
expect(out).to include("Fetching https://user1@github.com/company/private-repo")
end
end
@ -1689,7 +1689,7 @@ In Gemfile:
end
G
expect(last_command.stdboth).to_not include("oauth_token")
expect(stdboth).to_not include("oauth_token")
expect(out).to include("Fetching https://x-oauth-basic@github.com/company/private-repo")
end
end

View file

@ -397,7 +397,7 @@ RSpec.describe "bundle install with groups" do
FileUtils.rm_r gem_repo2
bundle "config set --local without myrack"
bundle :install, verbose: true
expect(last_command.stdboth).not_to match(/fetching/i)
expect(stdboth).not_to match(/fetching/i)
end
end
end

View file

@ -313,7 +313,7 @@ RSpec.describe "compact index api" do
gem "myrack"
G
expect(last_command.stdboth).not_to include "Double checking"
expect(stdboth).not_to include "Double checking"
end
it "fetches again when more dependencies are found in subsequent sources", bundler: "< 3" do

View file

@ -4,13 +4,13 @@ RSpec.describe "bundle command names" do
it "work when given fully" do
bundle "install", raise_on_error: false
expect(err).to eq("Could not locate Gemfile")
expect(last_command.stdboth).not_to include("Ambiguous command")
expect(stdboth).not_to include("Ambiguous command")
end
it "work when not ambiguous" do
bundle "ins", raise_on_error: false
expect(err).to eq("Could not locate Gemfile")
expect(last_command.stdboth).not_to include("Ambiguous command")
expect(stdboth).not_to include("Ambiguous command")
end
it "print a friendly error when ambiguous" do

View file

@ -217,7 +217,7 @@ RSpec.describe "The library itself" do
end
end
warnings = last_command.stdboth.split("\n")
warnings = stdboth.split("\n")
# ignore warnings around deprecated Object#=~ method in RubyGems
warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} }

View file

@ -24,7 +24,7 @@ RSpec.describe "env helpers" do
path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
with_path_as(path) do
bundle_exec_ruby(bundled_app("source.rb").to_s)
expect(last_command.stdboth).to eq(path)
expect(stdboth).to eq(path)
end
end
@ -35,7 +35,7 @@ RSpec.describe "env helpers" do
gem_path = ENV["GEM_PATH"] + "#{File::PATH_SEPARATOR}/foo"
with_gem_path_as(gem_path) do
bundle_exec_ruby(bundled_app("source.rb").to_s)
expect(last_command.stdboth).to eq(gem_path)
expect(stdboth).to eq(gem_path)
end
end
@ -81,7 +81,7 @@ RSpec.describe "env helpers" do
RUBY
ENV["BUNDLE_PATH"] = "./foo"
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).to include "false"
expect(stdboth).to include "false"
end
it "should remove absolute path to 'bundler/setup' from RUBYOPT even if it was present in original env" do
@ -91,7 +91,7 @@ RSpec.describe "env helpers" do
setup_require = "-r#{lib_dir}/bundler/setup"
ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 #{setup_require} #{ENV["RUBYOPT"]}"
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).not_to include(setup_require)
expect(stdboth).not_to include(setup_require)
end
it "should remove relative path to 'bundler/setup' from RUBYOPT even if it was present in original env" do
@ -100,7 +100,7 @@ RSpec.describe "env helpers" do
RUBY
ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).not_to include("-rbundler/setup")
expect(stdboth).not_to include("-rbundler/setup")
end
it "should delete BUNDLER_SETUP even if it was present in original env" do
@ -109,7 +109,7 @@ RSpec.describe "env helpers" do
RUBY
ENV["BUNDLER_ORIG_BUNDLER_SETUP"] = system_gem_path("gems/bundler-#{Bundler::VERSION}/lib/bundler/setup").to_s
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).to include "false"
expect(stdboth).to include "false"
end
it "should restore RUBYLIB", :ruby_repo do
@ -119,7 +119,7 @@ RSpec.describe "env helpers" do
ENV["RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo"
ENV["BUNDLER_ORIG_RUBYLIB"] = lib_dir.to_s + File::PATH_SEPARATOR + "/foo-original"
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).to include("/foo-original")
expect(stdboth).to include("/foo-original")
end
it "should restore the original MANPATH" do
@ -129,7 +129,7 @@ RSpec.describe "env helpers" do
ENV["MANPATH"] = "/foo"
ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original"
bundle_exec_ruby bundled_app("source.rb")
expect(last_command.stdboth).to include("/foo-original")
expect(stdboth).to include("/foo-original")
end
end

View file

@ -4,12 +4,12 @@ RSpec.describe "Requiring bundler" do
it "takes care of requiring rubygems when entrypoint is bundler/setup" do
sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler/setup -e'puts true'", env: { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) })
expect(last_command.stdboth).to eq("true")
expect(stdboth).to eq("true")
end
it "takes care of requiring rubygems when requiring just bundler" do
sys_exec("#{Gem.ruby} -I#{lib_dir} -rbundler -e'puts true'", env: { "RUBYOPT" => opt_add("--disable=gems", ENV["RUBYOPT"]) })
expect(last_command.stdboth).to eq("true")
expect(stdboth).to eq("true")
end
end

View file

@ -1552,7 +1552,7 @@ end
puts "FAIL"
RUBY
expect(last_command.stdboth).not_to include "FAIL"
expect(stdboth).not_to include "FAIL"
expect(err).to match(/private method [`']gem'/)
end
@ -1568,7 +1568,7 @@ end
puts "FAIL"
RUBY
expect(last_command.stdboth).not_to include "FAIL"
expect(stdboth).not_to include "FAIL"
expect(err).to match(/private method [`']require'/)
end

View file

@ -22,6 +22,10 @@ module Spec
last_command.stderr
end
def stdboth
last_command.stdboth
end
def exitstatus
last_command.exitstatus
end