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..5c74e65 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,19 @@ 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') + + ensure + FileUtils.rm("#{Terrapin::CommandLine.path}/ls") end end end