Skip to content

Commit

Permalink
test: add test for describe-pacticipant
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 5, 2021
1 parent cd11ebb commit abfbee9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/client/pacticipants/describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def result_message
pacticipant_entity.response.raw_body
else
properties = pacticipant_entity.response.body.except("_links", "_embedded")
if pacticipant_entity._embedded["labels"] && pacticipant_entity._embedded["labels"].any?
if pacticipant_entity._embedded && pacticipant_entity._embedded["labels"] && pacticipant_entity._embedded["labels"].any?
properties["labels"] = pacticipant_entity._embedded["labels"]
end
PactBroker::Client::DescribeTextFormatter.call(properties)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/approvals/describe_pacticipant.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: Pricing Service
Repository Url: [email protected]:business-systems/pricing-service
31 changes: 31 additions & 0 deletions spec/integration/describe_environment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'pact_broker/client/cli/broker'

RSpec.describe "describe-environment" do
let(:index_body_hash) do
{
_links: {
"pb:pacticipant" => {
href: "http://broker/pacticipants/{pacticipant}"
}
}
}
end

let(:pacticipant_body_hash) { JSON.parse(File.read("./spec/support/pacticipant_get.json")) }

let!(:index_request) do
stub_request(:get, "http://broker").to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
end

let!(:pacticipant_request) do
stub_request(:get, "http://broker/pacticipants/Foo").to_return(status: 200, body: pacticipant_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
end

let(:parameters) { %w{describe-pacticipant --name Foo --broker-base-url http://broker} }

subject { capture(:stdout) { PactBroker::Client::CLI::Broker.start(parameters) } }

it "prints the pacticipant properties" do
Approvals.verify(subject, :name => "describe_pacticipant", format: :txt)
end
end
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@

config.filter_run_excluding skip_windows: is_windows, skip_ci: is_ci
config.example_status_persistence_file_path = "./spec/examples.txt"

def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end

result
end
end

module Pact
Expand Down

0 comments on commit abfbee9

Please sign in to comment.