From 223fcc3c3fd0727f8bf5db3150485ccb8e9b15f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 21 Jan 2020 12:23:37 +0100 Subject: Fix flaky spec failure If our test code happens to run `Gem.configuration` before `ENV["HOME"]` is changed for our tests, this test starts failing because the test first writes to the global `~/.gemrc` file (not in `tmp/`), because `Gem.config_file` has that value memoized. Then, however, the `bundle install` subprocess infers `Gem.config_file` from the modified `ENV["HOME"]` and tries to read `tmp/home/.gemrc`. However, that file doesn't exist, so rubygems configuration is ignored and doesn't print an error like the test expects. The error looks like this: ``` Failures: 1) Bundler friendly errors with invalid YAML in .gemrc reports a relevant friendly error message Failure/Error: expect(err).to include("Failed to load #{home(".gemrc")}") expected "" to include "Failed to load /home/travis/build/rubygems/bundler/tmp/1/home/.gemrc" Commands: $ /home/travis/.rvm/rubies/ruby-2.6.5/bin/ruby -I/home/travis/build/rubygems/bundler/lib:/home/travis/build/rubygems/bundler/spec -rsupport/hax -rsupport/artifice/fail /home/travis/build/rubygems/bundler/exe/bundle install Running `bundle install` with bundler 3.0.0 Found changes from the lockfile, re-resolving dependencies because the list of sources changed, the dependencies in your gemfile changed, you added a new platform to your gemfile Fetching source index from file:///home/travis/build/rubygems/bundler/tmp/1/gems/remote1/ Resolving dependencies... Using bundler 3.0.0 0: bundler (3.0.0) from /home/travis/build/rubygems/bundler/lib/bundler/source Fetching rack 1.0.0 Installing rack 1.0.0 Rack's post install message 0: rack (1.0.0) from /home/travis/build/rubygems/bundler/tmp/1/bundled_app/.bundle/ruby/2.6.0/specifications/rack-1.0.0.gemspec Bundle complete! 1 Gemfile dependency, 2 gems now installed. Bundled gems are installed into `./.bundle` Post-install message from rack: Rack's post install message # $? => 0 # ./spec/bundler/friendly_errors_spec.rb:27:in `block (3 levels) in ' # ./spec/spec_helper.rb:109:in `block (3 levels) in ' # ./spec/spec_helper.rb:109:in `block (2 levels) in ' # ./spec/spec_helper.rb:76:in `block (2 levels) in ' # ./spec/support/rubygems_ext.rb:98:in `load' # ./spec/support/rubygems_ext.rb:98:in `gem_load_and_activate' # ./spec/support/rubygems_ext.rb:45:in `gem_load' ``` My fix is to make this test independent from the specific rubygems configuration in the main test process. --- spec/bundler/friendly_errors_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/bundler/friendly_errors_spec.rb b/spec/bundler/friendly_errors_spec.rb index e9189b0514..82553a3ca7 100644 --- a/spec/bundler/friendly_errors_spec.rb +++ b/spec/bundler/friendly_errors_spec.rb @@ -7,13 +7,13 @@ require "cgi" RSpec.describe Bundler, "friendly errors" do context "with invalid YAML in .gemrc" do before do - File.open(Gem.configuration.config_file_name, "w") do |f| + File.open(home(".gemrc"), "w") do |f| f.write "invalid: yaml: hah" end end after do - FileUtils.rm(Gem.configuration.config_file_name) + FileUtils.rm(home(".gemrc")) end it "reports a relevant friendly error message" do -- cgit v1.2.1