Skip to content

Commit 4224c4e

Browse files
authored
Merge pull request #225 from prefab-cloud/handle-stderr-issue-in-ide
Update stderr manipulation code in test helper
2 parents be54c2b + 8bb6291 commit 4224c4e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

test/support/common_helpers.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@ def teardown
2626
end
2727
end
2828

29-
if $stderr != $oldstderr && !$stderr.string.empty?
29+
#note this skips the output check in environments like rubymine that hijack the output. Alternative is a method missing error on string
30+
31+
if $stderr != $oldstderr && $stderr.respond_to?(:string) && !$stderr.string.empty?
3032
# we ignore 2.X because of the number of `instance variable @xyz not initialized` warnings
3133
if !RUBY_VERSION.start_with?('2.')
3234
raise "Unexpected stderr. Handle stderr with assert_stderr\n\n#{$stderr.string}"
3335
end
3436
end
3537

36-
$stderr = $oldstderr
38+
# Only restore stderr if we have a valid oldstderr
39+
if $oldstderr
40+
$stderr = $oldstderr
41+
end
3742

3843
Timecop.return
3944
end
@@ -174,6 +179,7 @@ def assert_logged(expected)
174179
end
175180

176181
def assert_stderr(expected)
182+
skip "Cannot verify stderr in current environment" unless $stderr.respond_to?(:string)
177183
$stderr.string.split("\n").uniq.each do |line|
178184
matched = false
179185

0 commit comments

Comments
 (0)