Skip to content

Commit

Permalink
fix(test): Ensure $stdout is always restored
Browse files Browse the repository at this point in the history
This fixes the `IOError` we could encounter in tests.

Found using:

```ruby
def bugmsg(header, stdout)
  bugged = begin; print; rescue IOError; "💥 "; end
  STDOUT.puts "🤞#{header.rjust(17)}: stdout=#{stdout.inspect} " \
    "#{bugged}(at #{caller_locations(2, 1).first})"
end

trace_var :$stdout, (proc { bugmsg("$stdout=", _1) })

TracePoint.trace(:a_return) do |tp|
  next unless tp.method_id == :reopen && tp.self == $stdout
  bugmsg("$stdout#reopen", $stdout)
end
```
  • Loading branch information
BuonOmo authored and rafiss committed Sep 24, 2023
1 parent 4bf5499 commit 27cf9aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/cases/schema_dumper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def down
end
ensure
migration.migrate(:down)
# $stdout = original
$stdout = original
end

def test_timestamps_schema_dump_before_rails_7_with_timestamptz_setting
Expand Down Expand Up @@ -119,7 +119,7 @@ def down
end
ensure
migration.migrate(:down)
# $stdout = original
$stdout = original
end

def test_schema_dump_with_correct_timestamp_types_via_add_column_before_rails_7_with_timestamptz_setting
Expand Down Expand Up @@ -153,7 +153,7 @@ def down
end
ensure
migration.migrate(:down)
# $stdout = original
$stdout = original
end

def test_schema_dump_when_changing_datetime_type_for_an_existing_app
Expand Down

0 comments on commit 27cf9aa

Please sign in to comment.