diff --git a/spec/integration/can_i_merge_spec.rb b/spec/integration/can_i_merge_spec.rb index 3623f79..13226bf 100644 --- a/spec/integration/can_i_merge_spec.rb +++ b/spec/integration/can_i_merge_spec.rb @@ -39,6 +39,17 @@ module CLI invoke_can_i_merge end + it "exits with failure if one pacticipant has a failing result" do + stub_request(:get, "http://pact-broker/matrix?latest=true&latestby=cvp&mainBranch=true&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=5"). + with( + headers: { + 'Accept'=>'application/hal+json', + }). + to_return(status: 200, body: File.read("spec/support/matrix_with_failure.json"), headers: { "Content-Type" => "application/hal+json" }) + stub_const("ARGV", %w[--pacticipant Bar --version 5]) + expect($stdout).to receive(:puts).with(/Computer says no.*(success).*(failure)/m) + expect { invoke_can_i_merge }.to raise_error(SystemExit) + end it "ignores pacticipant if --ignore flag is provided" do stub_request(:get, "http://pact-broker/matrix?latest=true&latestby=cvp&mainBranch=true&q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=5&ignore%5B%5D%5Bpacticipant%5D=Foo"). diff --git a/spec/support/matrix_with_failure.json b/spec/support/matrix_with_failure.json new file mode 100644 index 0000000..f73c9a5 --- /dev/null +++ b/spec/support/matrix_with_failure.json @@ -0,0 +1,61 @@ +{ + "summary": { + "deployable": false, + "ignored": 0, + "unknown": 0 + }, + "matrix": [ + { + "consumer": { + "name": "Baz", + "version": { + "number": "4" + } + }, + "provider": { + "name": "Bar", + "version": { + "number": "5" + } + }, + "verificationResult": { + "verifiedAt": "2017-10-10T12:49:04+11:00", + "success": true, + "_links": { + "self": { + "href": "http://result" + } + } + }, + "pact": { + "createdAt": "2017-10-10T12:49:04+11:00" + } + }, + { + "consumer": { + "name": "Foo", + "version": { + "number": "4" + } + }, + "provider": { + "name": "Bar", + "version": { + "number": "5" + } + }, + "verificationResult": { + "verifiedAt": "2017-10-10T12:49:04+11:00", + "success": false, + "_links": { + "self": { + "href": "http://result" + } + } + }, + "pact": { + "createdAt": "2017-10-10T12:49:04+11:00" + } + } + ] +}