From 42cb5e08c7176e3f27c6862525343846fb594a09 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 2 Nov 2021 17:12:38 -0500 Subject: [PATCH] Fix double output When we proxy `Object.load` to `Kernel.load` we were firing `DeadEnd.handle_error` twice. Switching the test over to a `load` instead of a `require_relative` makes the error show up, which can then be asserted via adding the `once` call in rspec. I still don't know why this code was needed in the first place. close #97 --- CHANGELOG.md | 1 + lib/dead_end/auto.rb | 20 -------------------- spec/integration/ruby_command_line_spec.rb | 4 ++-- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ac0b2..5d71d16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## HEAD (unreleased) +- Fix double output bug (https://github.com/zombocom/dead_end/pull/99) - Fix bug causing poor results (fix #95, fix #88) () - [Breaking] Remove previously deprecated `require "dead_end/fyi"` interface (https://github.com/zombocom/dead_end/pull/94) - DeadEnd is now fired on EVERY syntax error (https://github.com/zombocom/dead_end/pull/94) diff --git a/lib/dead_end/auto.rb b/lib/dead_end/auto.rb index c99059b..fe0336e 100644 --- a/lib/dead_end/auto.rb +++ b/lib/dead_end/auto.rb @@ -33,23 +33,3 @@ def require_relative(file) DeadEnd.handle_error(e) end end - -# I honestly have no idea why this Object delegation is needed -# I keep staring at bootsnap and it doesn't have to do this -# is there a bug in their implementation they haven't caught or -# am I doing something different? -class Object - private - - def load(path, wrap = false) - Kernel.load(path, wrap) - rescue SyntaxError => e - DeadEnd.handle_error(e) - end - - def require(path) - Kernel.require(path) - rescue SyntaxError => e - DeadEnd.handle_error(e) - end -end diff --git a/spec/integration/ruby_command_line_spec.rb b/spec/integration/ruby_command_line_spec.rb index eed66ef..9cd7e15 100644 --- a/spec/integration/ruby_command_line_spec.rb +++ b/spec/integration/ruby_command_line_spec.rb @@ -46,13 +46,13 @@ module DeadEnd require_rb = tmpdir.join("require.rb") require_rb.write <<~EOM - require_relative "./script.rb" + load "#{script.expand_path}" EOM out = `ruby -I#{lib_dir} -rdead_end #{require_rb} 2>&1` expect($?.success?).to be_falsey - expect(out).to include('❯ 5 it "flerg"') + expect(out).to include('❯ 5 it "flerg"').once end end end