From 286c1d1906e89e8add77ddc3de2b4b7d0bed5ddf Mon Sep 17 00:00:00 2001 From: Torrey Payne <11740989+torreypayne@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:05:37 +0000 Subject: [PATCH] chore(firestore): support Ruby 3.2 Hash#inspect output in samples tests --- .../samples/acceptance/get_data_test.rb | 30 +++++++++---------- .../samples/acceptance/helper.rb | 13 ++++++++ .../samples/acceptance/quickstart_test.rb | 14 ++++----- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/google-cloud-firestore/samples/acceptance/get_data_test.rb b/google-cloud-firestore/samples/acceptance/get_data_test.rb index ffde0c84934a..7cdf9e5fcc73 100644 --- a/google-cloud-firestore/samples/acceptance/get_data_test.rb +++ b/google-cloud-firestore/samples/acceptance/get_data_test.rb @@ -41,11 +41,11 @@ get_document project_id: @firestore_project, collection_path: @collection_path end assert_includes out, "SF data:" - assert_includes out, 'name: "San Francisco"' - assert_includes out, 'state: "CA"' - assert_includes out, 'country: "USA"' - assert_includes out, "capital: false" - assert_includes out, "population: 860000" + assert_hash_entry out, :name, '"San Francisco"' + assert_hash_entry out, :state, '"CA"' + assert_hash_entry out, :country, '"USA"' + assert_hash_entry out, :capital, "false" + assert_hash_entry out, :population, "860000" end it "get_multiple_docs" do @@ -57,11 +57,11 @@ assert_includes out, "BJ data:" refute_includes out, "SF data:" refute_includes out, "LA data:" - assert_includes out, 'name: "Tokyo"' - assert_includes out, "state: nil" - assert_includes out, 'country: "Japan"' - assert_includes out, "capital: true" - assert_includes out, "population: 9000000" + assert_hash_entry out, :name, '"Tokyo"' + assert_hash_entry out, :state, "nil" + assert_hash_entry out, :country, '"Japan"' + assert_hash_entry out, :capital, "true" + assert_hash_entry out, :population, "9000000" end it "get_all_docs" do @@ -73,11 +73,11 @@ assert_includes out, "BJ data:" assert_includes out, "SF data:" assert_includes out, "LA data:" - assert_includes out, 'name: "Los Angeles"' - assert_includes out, 'state: "CA"' - assert_includes out, 'country: "USA"' - assert_includes out, "capital: false" - assert_includes out, "population: 3900000" + assert_hash_entry out, :name, '"Los Angeles"' + assert_hash_entry out, :state, '"CA"' + assert_hash_entry out, :country, '"USA"' + assert_hash_entry out, :capital, "false" + assert_hash_entry out, :population, "3900000" end it "add_subcollection" do diff --git a/google-cloud-firestore/samples/acceptance/helper.rb b/google-cloud-firestore/samples/acceptance/helper.rb index fdffa102534b..d430c495514b 100644 --- a/google-cloud-firestore/samples/acceptance/helper.rb +++ b/google-cloud-firestore/samples/acceptance/helper.rb @@ -84,3 +84,16 @@ def delete_composite_index name: request = Google::Cloud::Firestore::Admin::V1::DeleteIndexRequest.new name: name $firestore_admin.delete_index request end + +## +# Asserts that inspected Ruby hash output contains a key/value entry under both +# Ruby <3.4 (`:key=>value`) and Ruby >=3.4 (`key: value`) formatting. +# +# @param output [String] Captured stdout output. +# @param key [String, Symbol] Hash key name. +# @param value [String] Inspected value fragment. +def assert_hash_entry output, key, value + escaped_key = Regexp.escape key.to_s + escaped_value = Regexp.escape value.to_s + assert_match(/(?:#{escaped_key}: |:#{escaped_key}=>)#{escaped_value}/, output) +end diff --git a/google-cloud-firestore/samples/acceptance/quickstart_test.rb b/google-cloud-firestore/samples/acceptance/quickstart_test.rb index c56fbeace7c8..2a2945ac2a92 100644 --- a/google-cloud-firestore/samples/acceptance/quickstart_test.rb +++ b/google-cloud-firestore/samples/acceptance/quickstart_test.rb @@ -47,13 +47,13 @@ get_all project_id: @firestore_project, collection_path: @collection_path end assert_includes out, "alovelace data:" - assert_includes out, 'first: "Ada"' - assert_includes out, 'last: "Lovelace"' - assert_includes out, "born: 1815" + assert_hash_entry out, :first, '"Ada"' + assert_hash_entry out, :last, '"Lovelace"' + assert_hash_entry out, :born, "1815" assert_includes out, "aturing data:" - assert_includes out, 'first: "Alan"' - assert_includes out, 'middle: "Mathison"' - assert_includes out, 'last: "Turing"' - assert_includes out, "born: 1912" + assert_hash_entry out, :first, '"Alan"' + assert_hash_entry out, :middle, '"Mathison"' + assert_hash_entry out, :last, '"Turing"' + assert_hash_entry out, :born, "1912" end end