Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions google-cloud-firestore/samples/acceptance/get_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions google-cloud-firestore/samples/acceptance/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions google-cloud-firestore/samples/acceptance/quickstart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading