From 305a612146af2913258248d3b5381c088d7cec92 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Wed, 9 Jul 2025 13:09:03 -0400 Subject: [PATCH 1/2] Reset stubs for class methods and attributes There were a number of stubs for class attributes that were bleeding between different examples and causing flakiness. I added a before each blog in spec_helper.rb that will reset all the different things that caused this flakiness including: - Terrapin::CommandLine.path - Terrapin::CommandLine.runner --- spec/spec_helper.rb | 5 +++++ spec/terrapin/runners_spec.rb | 19 ++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90d6f7c..1f5f357 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,6 +14,11 @@ RSpec.configure do |config| config.include WithExitstatus config.include StubOS + + config.before(:example) do + Terrapin::CommandLine.path = nil + Terrapin::CommandLine.runner = nil + end end def best_logger diff --git a/spec/terrapin/runners_spec.rb b/spec/terrapin/runners_spec.rb index 1174f91..171de25 100644 --- a/spec/terrapin/runners_spec.rb +++ b/spec/terrapin/runners_spec.rb @@ -52,17 +52,6 @@ end describe 'When running an executable in the supplemental path' do - before do - path = Pathname.new(File.dirname(__FILE__)) + '..' + 'support' - File.open(path + 'ls', 'w'){|f| f.puts "#!/bin/sh\necho overridden-ls\n" } - FileUtils.chmod(0755, path + 'ls') - Terrapin::CommandLine.path = path - end - - after do - FileUtils.rm_f("#{Terrapin::CommandLine.path}/ls") - end - [ Terrapin::CommandLine::BackticksRunner, Terrapin::CommandLine::PopenRunner, @@ -72,10 +61,18 @@ describe runner_class do describe '#run' do it 'finds the correct executable' do + path = Pathname.new(File.dirname(__FILE__)) + '..' + 'support' + File.open(path + 'ls', 'w'){|f| f.puts "#!/bin/sh\necho overridden-ls\n" } + FileUtils.chmod(0755, path + 'ls') + Terrapin::CommandLine.path = path Terrapin::CommandLine.runner = runner_class.new command = Terrapin::CommandLine.new('ls') + result = command.run + expect(result.strip).to eq('overridden-ls') + + FileUtils.rm_f("#{Terrapin::CommandLine.path}/ls") end end end From ca56c7791d6c0eebf26ec778699212440f9a5a17 Mon Sep 17 00:00:00 2001 From: Sara Jackson Date: Wed, 9 Jul 2025 15:04:37 -0400 Subject: [PATCH 2/2] Add ensure so we definitely delete the file even the test fails or errors --- spec/terrapin/runners_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/terrapin/runners_spec.rb b/spec/terrapin/runners_spec.rb index 171de25..5c74e65 100644 --- a/spec/terrapin/runners_spec.rb +++ b/spec/terrapin/runners_spec.rb @@ -72,7 +72,8 @@ expect(result.strip).to eq('overridden-ls') - FileUtils.rm_f("#{Terrapin::CommandLine.path}/ls") + ensure + FileUtils.rm("#{Terrapin::CommandLine.path}/ls") end end end