require "celsius/hash" describe Celsius::Hash do describe ".deep_find_key" do let(:hash) do { query: { bool: [ { query_string: { query: "a" } }, { query_string: { query: "b" } }, { match: { some_field: "some_value" } } ] }, facets: { creator: { terms: { field: "facet_creator" } }, lang: { terms: { field: "facet_lang", } } } } end it "returns values matching the given key" do expected_result = [ hash[:query][:bool][0][:query_string], hash[:query][:bool][1][:query_string], ] expect(described_class.deep_find_key(hash, :query_string)).to eq(expected_result) end context "if given an array of keys" do it "tries to find each element based on the former elements result" do expected_result = [ hash[:facets][:creator] ] expect(described_class.deep_find_key(hash, [:facets, :creator])).to eq(expected_result) end end end end