summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-05-24 12:04:29 +0200
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-05-27 13:03:21 +0200
commitb88d13242009ad2ac80aa7c4ffd702eba9271a6b (patch)
treef3719ffd2d25602499802d3f4acae5323fd203ca
parenta0584faa5df94527f48adbd252bcf40080a90223 (diff)
downloadbundler-b88d13242009ad2ac80aa7c4ffd702eba9271a6b.tar.gz
Fix some flakies on the first spec
Sometimes, the initial environment before the first spec would not be properly reset, causing some specs to fail if they run first. Reproducible with ``` bin/rspec \ --seed 52285 \ -e "Bundler.unbundled_env behaves like an unbundling helper should clean up RUBYLIB" ``` This change causes a separate spec failure, namely: ``` $ bin/rspec spec/bundler/gem_helper_spec.rb:294 1) Bundler::GemHelper gem management release:rubygem_push success messaging No allowed_push_host set RUBYGEMS_HOST env var is set should report successful push to the host from the environment Failure/Error: expect(Bundler.ui).to receive(:confirm).with(message) #<Bundler::UI::Shell:0x0000556bc98a8f60 @shell=#<Bundler::Thor::Shell::Color:0x0000556bc98e80e8 @base=nil, @mute=false, @padding=0, @always_force=false>, @level="info", @warning_history=[]> received :confirm with unexpected arguments expected: ("Pushed lorem__ipsum 0.1.0 to https://custom.env.gemhost.com") got: ("Pushed lorem__ipsum 0.1.0 to rubygems.org") # ./spec/bundler/gem_helper_spec.rb:54:in `mock_confirm_message' # ./spec/bundler/gem_helper_spec.rb:286:in `block (6 levels) in <top (required)>' # ./spec/spec_helper.rb:100:in `block (2 levels) in <top (required)>' ``` This is due to some RSpec weirdness. In particular, https://github.com/rspec/rspec-core/issues/2544. If you have an outer `before(:each)` block, and an inner `around(:each)` block, it turns out that the inner `around(:each)` runs before the outer `before(:each)`. This is very unintuitive and might change in future RSpec's. In our case, it causes a particular failure where the `around` hook would set a value for an environment variable, and then it would be unintentionally reset by our global `before` hook. We workaround the issue by changing the global `before` hook to an `around` hook, so that the ordering respects nesting.
-rw-r--r--spec/spec_helper.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 067c8dc070..3031d3019d 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -111,14 +111,15 @@ RSpec.configure do |config|
build_repo1
end
- config.before :each do
+ config.around :each do |example|
+ ENV.replace(original_env)
reset!
system_gems []
in_app_root
@command_executions = []
- end
- config.after :each do |example|
+ example.run
+
all_output = @command_executions.map(&:to_s_verbose).join("\n\n")
if example.exception && !all_output.empty?
warn all_output unless config.formatters.grep(RSpec::Core::Formatters::DocumentationFormatter).empty?
@@ -129,7 +130,6 @@ RSpec.configure do |config|
end
Dir.chdir(original_wd)
- ENV.replace(original_env)
end
config.after :suite do