Capture output from PostgreSQL notice receiver in a test

This commit is contained in:
fatkodima 2023-02-28 22:59:51 +02:00
parent 6c51cd399e
commit 9f79ad05a4
1 changed files with 7 additions and 3 deletions

View File

@ -521,9 +521,13 @@ module ActiveRecord
def test_ignores_warnings_when_behaviour_ignore
with_db_warnings_action(:ignore) do
result = @connection.execute("do $$ BEGIN RAISE WARNING 'foo'; END; $$")
assert_equal [], result.to_a
# libpq prints a warning to stderr from C, so we need to stub
# the whole file descriptors, not just Ruby's $stdout/$stderr.
_out, err = capture_subprocess_io do
result = @connection.execute("do $$ BEGIN RAISE WARNING 'foo'; END; $$")
assert_equal [], result.to_a
end
assert_match(/WARNING: foo/, err)
end
end