From 473abbe52e043e346b8cb1f26996ca962ca6337c Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 6 Nov 2017 17:00:14 +1100 Subject: [PATCH] feat(matrix): improve reason when no results are found --- lib/pact_broker/api/decorators/matrix_decorator.rb | 2 ++ .../api/decorators/matrix_decorator_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/pact_broker/api/decorators/matrix_decorator.rb b/lib/pact_broker/api/decorators/matrix_decorator.rb index 25771f0f7..bec361c9a 100644 --- a/lib/pact_broker/api/decorators/matrix_decorator.rb +++ b/lib/pact_broker/api/decorators/matrix_decorator.rb @@ -26,11 +26,13 @@ def to_hash(options) end def deployable + return nil if lines.empty? return nil if lines.any?{ |line| line[:success].nil? } lines.any? && lines.all?{ |line| line[:success] } end def reason + return "No results matched the given query" if lines.empty? case deployable when true then "All verification results are published and successful" when false then "One or more verifications have failed" diff --git a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb index ba2a2db6c..9ff3a7435 100644 --- a/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb @@ -160,6 +160,18 @@ module Decorators expect(parsed_json[:summary][:reason]).to match /have failed/ end end + + context "when there are no results" do + let(:lines) { [] } + + it "has a deployable flag of false" do + expect(parsed_json[:summary][:deployable]).to be nil + end + + it "has an explanation" do + expect(parsed_json[:summary][:reason]).to match /No results/ + end + end end end end