From 9f79ad05a4a81c983f23cb12327853d9114d9264 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 28 Feb 2023 22:59:51 +0200 Subject: [PATCH] Capture output from PostgreSQL notice receiver in a test --- .../adapters/postgresql/postgresql_adapter_test.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index c4f34b4b475..cd5cce1b43c 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -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