From 6c223e6971b9002b6e7f8893a35bd15e7a9e62be Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 6 Aug 2020 17:01:58 +1000 Subject: [PATCH] fix: gracefully handle contracts without interactions or messages in deployment status warnings --- lib/pact_broker/pacts/content.rb | 3 ++- spec/lib/pact_broker/pacts/content_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/pacts/content.rb b/lib/pact_broker/pacts/content.rb index cfa5ec0e8..a82dc272e 100644 --- a/lib/pact_broker/pacts/content.rb +++ b/lib/pact_broker/pacts/content.rb @@ -32,7 +32,8 @@ def sort end def interactions_missing_test_results - interactions.reject do | interaction | + return [] unless messages_or_interactions + messages_or_interactions.reject do | interaction | interaction['tests']&.any? end end diff --git a/spec/lib/pact_broker/pacts/content_spec.rb b/spec/lib/pact_broker/pacts/content_spec.rb index 624b0451b..051f2a6ab 100644 --- a/spec/lib/pact_broker/pacts/content_spec.rb +++ b/spec/lib/pact_broker/pacts/content_spec.rb @@ -308,6 +308,14 @@ module Pacts expect(subject.interactions_missing_test_results.count).to eq 1 end + context "with no interactions" do + let(:pact_content) { {} } + + it "does not blow up" do + expect(subject.interactions_missing_test_results.count).to eq 0 + end + end + context "with nil test results" do let(:test_results) { nil }