From 3fa00a8a5c23a0f0e03976c37fac5b08e0f0406e Mon Sep 17 00:00:00 2001 From: James Kebinger Date: Fri, 14 Feb 2025 13:05:35 -0600 Subject: [PATCH 1/2] Update stderr manipulation code in test helper running in an IDE causes this code to fail, so instead its safely neutered with this approach. --- test/support/common_helpers.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/support/common_helpers.rb b/test/support/common_helpers.rb index f2607e6..5f75ab0 100644 --- a/test/support/common_helpers.rb +++ b/test/support/common_helpers.rb @@ -26,14 +26,19 @@ def teardown end end - if $stderr != $oldstderr && !$stderr.string.empty? + #note this skips the output check in environments like rubymine that hijack the output. Alternative is a method missing error on string + + if $stderr != $oldstderr && $stderr.respond_to?(:string) && !$stderr.string.empty? # we ignore 2.X because of the number of `instance variable @xyz not initialized` warnings if !RUBY_VERSION.start_with?('2.') raise "Unexpected stderr. Handle stderr with assert_stderr\n\n#{$stderr.string}" end end - $stderr = $oldstderr + # Only restore stderr if we have a valid oldstderr + if $oldstderr + $stderr = $oldstderr + end Timecop.return end @@ -174,6 +179,7 @@ def assert_logged(expected) end def assert_stderr(expected) + skip "Cannot verify stderr in current environment" unless $stderr.respond_to?(:string) $stderr.string.split("\n").uniq.each do |line| matched = false @@ -185,8 +191,5 @@ def assert_stderr(expected) end assert expected.empty?, "Expected stderr to include: #{expected}, but it did not" - - # restore since we've handled it - $stderr = $oldstderr end end From 8bb6291f5440a35ae86d1e94993b780911fed603 Mon Sep 17 00:00:00 2001 From: James Kebinger Date: Fri, 14 Feb 2025 13:13:43 -0600 Subject: [PATCH 2/2] put the restoration of std error back in assert_stderr --- test/support/common_helpers.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/support/common_helpers.rb b/test/support/common_helpers.rb index 5f75ab0..261ed58 100644 --- a/test/support/common_helpers.rb +++ b/test/support/common_helpers.rb @@ -191,5 +191,8 @@ def assert_stderr(expected) end assert expected.empty?, "Expected stderr to include: #{expected}, but it did not" + + # restore since we've handled it + $stderr = $oldstderr end end