Merge pull request #47539 from fatkodima/pg-notice-receiver-capture-output

Capture output from PostgreSQL notice receiver in a test
This commit is contained in:
Yasuo Honda 2023-03-01 08:22:12 +09:00 committed by GitHub
commit 05dc09385f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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