From a9a5df3d31d98338c7389bb4a793cb5a3a6d7a82 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 6 May 2021 11:09:41 +1000 Subject: [PATCH] fix: gracefully handle an interactions value that is not an array --- lib/pact_broker/pacts/sort_content.rb | 11 ++++++++--- spec/lib/pact_broker/pacts/sort_content_spec.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/pact_broker/pacts/sort_content.rb b/lib/pact_broker/pacts/sort_content.rb index 1b161fcec..a412b5657 100644 --- a/lib/pact_broker/pacts/sort_content.rb +++ b/lib/pact_broker/pacts/sort_content.rb @@ -29,9 +29,14 @@ def self.verifiable_content_key_for pact_hash end end - def self.order_verifiable_content array - array_with_ordered_hashes = order_hash_keys(array) - array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json } + def self.order_verifiable_content probably_array + # You never can tell what people will do... + if probably_array.is_a?(Array) + array_with_ordered_hashes = order_hash_keys(probably_array) + array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json } + else + probably_array + end end end end diff --git a/spec/lib/pact_broker/pacts/sort_content_spec.rb b/spec/lib/pact_broker/pacts/sort_content_spec.rb index ca4304b51..f06758b05 100644 --- a/spec/lib/pact_broker/pacts/sort_content_spec.rb +++ b/spec/lib/pact_broker/pacts/sort_content_spec.rb @@ -39,6 +39,19 @@ module Pacts expect(SortContent.call(other_content)).to eq other_content end end + + context "when interactions is a string" do + let(:other_content) do + { + 'a' => 1, + 'interactions' => 'interactions' + } + end + + it "does not blow up" do + expect(SortContent.call(other_content)).to eq other_content + end + end end end end