Skip to content

Commit 9f79ad0

Browse files
committed
Capture output from PostgreSQL notice receiver in a test
1 parent 6c51cd3 commit 9f79ad0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,13 @@ def test_only_check_for_insensitive_comparison_capability_once
521521

522522
def test_ignores_warnings_when_behaviour_ignore
523523
with_db_warnings_action(:ignore) do
524-
result = @connection.execute("do $$ BEGIN RAISE WARNING 'foo'; END; $$")
525-
526-
assert_equal [], result.to_a
524+
# libpq prints a warning to stderr from C, so we need to stub
525+
# the whole file descriptors, not just Ruby's $stdout/$stderr.
526+
_out, err = capture_subprocess_io do
527+
result = @connection.execute("do $$ BEGIN RAISE WARNING 'foo'; END; $$")
528+
assert_equal [], result.to_a
529+
end
530+
assert_match(/WARNING: foo/, err)
527531
end
528532
end
529533

0 commit comments

Comments
 (0)