pact_broker-client 1.75.3 → 1.75.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/pact_broker/client/version.rb +1 -1
  4. metadata +5 -216
  5. data/.github/workflows/test.yml +0 -59
  6. data/.rspec +0 -3
  7. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  8. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  9. data/pact-broker-client.gemspec +0 -31
  10. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  11. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  12. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  13. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  14. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  15. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  17. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  18. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  19. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  20. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  21. data/spec/fixtures/certificates/ca_key.pem +0 -28
  22. data/spec/fixtures/certificates/client_cert.pem +0 -17
  23. data/spec/fixtures/certificates/key.pem +0 -28
  24. data/spec/fixtures/certificates/server.csr +0 -15
  25. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  26. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  27. data/spec/fixtures/foo-bar.json +0 -31
  28. data/spec/integration/can_i_deploy_spec.rb +0 -24
  29. data/spec/integration/can_i_merge_spec.rb +0 -44
  30. data/spec/integration/create_version_tag_spec.rb +0 -20
  31. data/spec/integration/describe_environment_spec.rb +0 -31
  32. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  33. data/spec/integration/unknown_options_spec.rb +0 -39
  34. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  35. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  36. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  37. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  38. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  39. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  41. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  42. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  43. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  44. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  45. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  46. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  47. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  48. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  49. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  50. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  51. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  52. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  53. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  54. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  55. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  56. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  57. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  58. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  59. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  60. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  61. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  62. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  63. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  64. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  65. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  66. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  67. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  68. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  69. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  70. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  71. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  72. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  73. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  74. data/spec/readme_spec.rb +0 -16
  75. data/spec/service_providers/create_environment_spec.rb +0 -78
  76. data/spec/service_providers/delete_branch_spec.rb +0 -68
  77. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  78. data/spec/service_providers/list_environments_spec.rb +0 -77
  79. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  80. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  81. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  82. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  83. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  84. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  85. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  86. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  87. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  88. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  89. data/spec/service_providers/pact_helper.rb +0 -136
  90. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  91. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  92. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  93. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  94. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  95. data/spec/service_providers/record_deployment_spec.rb +0 -199
  96. data/spec/service_providers/record_release_spec.rb +0 -130
  97. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  98. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  99. data/spec/spec_helper.rb +0 -68
  100. data/spec/support/approvals.rb +0 -26
  101. data/spec/support/cli_test_pacts/bar.json +0 -0
  102. data/spec/support/cli_test_pacts/foo.json +0 -0
  103. data/spec/support/latest_pacts_for_provider.json +0 -15
  104. data/spec/support/matrix.json +0 -35
  105. data/spec/support/matrix.txt +0 -3
  106. data/spec/support/matrix_error.txt +0 -3
  107. data/spec/support/matrix_with_results.txt +0 -10
  108. data/spec/support/pacticipant_get.json +0 -18
  109. data/spec/support/pacticipants_list.json +0 -26
  110. data/spec/support/pacts_latest_list.json +0 -41
  111. data/spec/support/shared_context.rb +0 -25
  112. data/spec/support/ssl_server.rb +0 -42
@@ -1,167 +0,0 @@
1
- require 'pact_broker/client/environments/update_environment'
2
-
3
- module PactBroker
4
- module Client
5
- module Environments
6
- describe UpdateEnvironment do
7
- before do
8
- allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:sleep)
9
- allow_any_instance_of(PactBroker::Client::Hal::HttpClient).to receive(:default_max_tries).and_return(1)
10
- end
11
-
12
- let(:params) do
13
- {
14
- uuid: uuid,
15
- name: "new name",
16
- display_name: "new display name",
17
- production: false
18
- }
19
- end
20
- let(:options) do
21
- {
22
- output: output,
23
- verbose: verbose
24
- }
25
- end
26
- let(:uuid) { "a9aa4c22-66bb-45d3-ba4c-4916ac8b48c5" }
27
- let(:pact_broker_base_url) { "http://example.org" }
28
- let(:pact_broker_client_options) { { pact_broker_base_url: pact_broker_base_url } }
29
- let(:response_headers) { { "Content-Type" => "application/hal+json"} }
30
- let(:output) { "text" }
31
- let(:verbose) { false }
32
-
33
- before do
34
- stub_request(:get, "http://example.org/").to_return(status: 200, body: index_response_body, headers: response_headers)
35
- stub_request(:get, "http://example.org/environments/#{uuid}").to_return(status: get_environment_response_status, body: get_environment_response_body, headers: response_headers)
36
- stub_request(:put, "http://example.org/environments/#{uuid}").to_return(status: put_response_status, body: put_environment_response_body, headers: response_headers)
37
- end
38
- let(:put_response_status) { 200 }
39
- let(:get_environment_response_status) { 200 }
40
- let(:put_request_body) do
41
- {
42
- name: "new name",
43
- displayName: "new display name",
44
- production: false
45
- }.to_json
46
- end
47
-
48
- let(:index_response_body) do
49
- {
50
- "_links" => {
51
- "pb:environments" => {},
52
- "pb:environment" => {
53
- "href" => "http://example.org/environments/{uuid}"
54
- }
55
- }
56
- }.to_json
57
- end
58
-
59
- let(:get_environment_response_body) do
60
- {
61
- name: "existing name",
62
- displayName: "existing display name",
63
- production: true
64
- }.to_json
65
- end
66
-
67
- let(:put_environment_response_body) do
68
- JSON.parse(get_environment_response_body).merge("updatedAt" => "2021-05-28T13:34:54+10:00").to_json
69
- end
70
-
71
- subject { UpdateEnvironment.call(params, options, pact_broker_client_options) }
72
-
73
- it "updates the environment" do
74
- request = stub_request(:put, "http://example.org/environments/#{uuid}").with(body: put_request_body)
75
- subject
76
- expect(request).to have_been_made
77
- end
78
-
79
- context "when update is successful" do
80
- its(:success) { is_expected.to be true }
81
- its(:message) { is_expected.to include "Updated new name environment in the Pact Broker" }
82
-
83
- context "when output is json" do
84
- let(:output) { "json" }
85
-
86
- its(:message) { is_expected.to eq put_environment_response_body }
87
- end
88
- end
89
-
90
- context "when environments are not supported" do
91
- let(:index_response_body) { "{}" }
92
-
93
- its(:success) { is_expected.to be false }
94
- its(:message) { is_expected.to include "does not support environments" }
95
- end
96
-
97
- context "when a StandardError occurs" do
98
- before do
99
- allow_any_instance_of(described_class).to receive(:do_call).and_raise(StandardError.new("Foo"))
100
- end
101
-
102
- its(:success) { is_expected.to be false }
103
- its(:message) { is_expected.to include "StandardError - Foo" }
104
-
105
- context "when verbose is on" do
106
- let(:verbose) { true }
107
-
108
- it "includes the message and class and backtrace in the error" do
109
- expect(subject.message.split("\n").size).to be > 2
110
- end
111
- end
112
-
113
- context "when output is json" do
114
- let(:output) { "json" }
115
-
116
- it "includes the message and class in the error" do
117
- message_hash = JSON.parse(subject.message)
118
- expect(message_hash).to eq "error" => { "message" => "Foo", "class" => "StandardError" }
119
- end
120
-
121
- context "when verbose is on" do
122
- let(:verbose) { true }
123
-
124
- it "includes the message and class and backtrace in the error" do
125
- message_hash = JSON.parse(subject.message)
126
- expect(message_hash["error"]["backtrace"]).to be_a(Array)
127
- end
128
- end
129
- end
130
- end
131
-
132
- context "when the environment does not exist" do
133
- let(:get_environment_response_status) { 404 }
134
- let(:get_environment_response_body) { "" }
135
- let(:put_environment_response_body) { "" }
136
-
137
- its(:success) { is_expected.to be false }
138
- its(:message) { is_expected.to include get_environment_response_body }
139
-
140
- context "when output is json" do
141
- let(:output) { "json" }
142
-
143
- its(:message) { is_expected.to eq "{}" }
144
- end
145
- end
146
-
147
- context "when update is unsuccessful" do
148
- let(:put_response_status) { 400 }
149
- let(:put_environment_response_body) do
150
- {
151
- "some" => "error"
152
- }.to_json
153
- end
154
-
155
- its(:success) { is_expected.to be false }
156
- its(:message) { is_expected.to include put_environment_response_body }
157
-
158
- context "when output is json" do
159
- let(:output) { "json" }
160
-
161
- its(:message) { is_expected.to eq put_environment_response_body }
162
- end
163
- end
164
- end
165
- end
166
- end
167
- end
@@ -1,39 +0,0 @@
1
- require 'pact_broker/client/generate_display_name'
2
-
3
- module PactBroker
4
- module Client
5
- describe GenerateDisplayName do
6
- describe ".call" do
7
- TEST_CASES = {
8
- "foo" => "Foo",
9
- "MyService" => "My Service",
10
- "my-service" => "My Service",
11
- "my_service" => "My Service",
12
- "my service" => "My Service",
13
- "ABCService" => "ABC Service",
14
- "A4Service" => "A4 Service",
15
- "SNSPactEventConsumer" => "SNS Pact Event Consumer",
16
- "AWSSummiteerWeb" => "AWS Summiteer Web",
17
- "Beer-Consumer" => "Beer Consumer",
18
- "foo.pretend-consumer" => "Foo Pretend Consumer",
19
- "Client-XX" => "Client XX",
20
- "providerJSWorkshop" => "Provider JS Workshop",
21
- "e2e Provider Example" => "E2e Provider Example",
22
- "MP - Our Provider" => "MP - Our Provider",
23
- "PoC - Pact-broker-consumer" => "PoC - Pact Broker Consumer",
24
- "QB-DATABASE Service" => "QB DATABASE Service",
25
- "Support Species App (Provider)" => "Support Species App (Provider)",
26
- 9 => "9",
27
- "" => "",
28
- nil => nil
29
- }
30
-
31
- TEST_CASES.each do | name, expected_display_name |
32
- it "converts #{name.inspect} to #{expected_display_name.inspect}" do
33
- expect(GenerateDisplayName.call(name)).to eq expected_display_name
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,159 +0,0 @@
1
- require 'pact_broker/client/git'
2
-
3
- module PactBroker
4
- module Client
5
- module Git
6
- describe ".branch" do
7
- before do
8
- allow(ENV).to receive(:[]).and_call_original
9
- Git::BRANCH_ENV_VAR_NAMES.each do | env_var_name|
10
- allow(ENV).to receive(:[]).with(env_var_name).and_return(nil)
11
- end
12
- allow(Git).to receive(:execute_git_command).and_return(" origin/HEAD \n origin/foo")
13
- end
14
-
15
- let(:raise_exception) { true }
16
-
17
- subject { Git.branch(raise_error: raise_exception) }
18
-
19
- shared_examples_for "when raise_error is false" do
20
- context "when raise_error is false" do
21
- let(:raise_exception) { false }
22
-
23
- it { is_expected.to be nil }
24
- end
25
- end
26
-
27
- context "when there is a known environment variable for the branch" do
28
- before do
29
- allow(ENV).to receive(:[]).with("BUILDKITE_BRANCH").and_return("")
30
- allow(ENV).to receive(:[]).with("TRAVIS_BRANCH").and_return("foo")
31
- end
32
-
33
- it "returns the value of the environment variable" do
34
- expect(subject).to eq "foo"
35
- end
36
- end
37
-
38
- context "when the branch starts with refs/heads/" do
39
- before do
40
- allow(ENV).to receive(:[]).with("GITHUB_REF").and_return("refs/heads/feature-x")
41
- end
42
-
43
- it "trims off the refs/heads/" do
44
- expect(subject).to eq "feature-x"
45
- end
46
- end
47
-
48
- context "when there is one environment variable ending with _BRANCH" do
49
- before do
50
- allow(ENV).to receive(:keys).and_return(%w{FOO_BRANCH BAR_BRANCH BLAH})
51
- allow(ENV).to receive(:[]).with("FOO_BRANCH").and_return("")
52
- allow(ENV).to receive(:[]).with("BAR_BRANCH").and_return("meep")
53
- end
54
-
55
- it "returns the value of that environment variable" do
56
- expect(subject).to eq "meep"
57
- end
58
- end
59
-
60
- context "when there is more than one environment variable ending with _BRANCH" do
61
- it "attempts to execute a git command to determine the value" do
62
- expect(Git).to receive(:execute_git_command)
63
- expect(subject).to_not be_empty
64
- end
65
- end
66
-
67
- context "when there is no known environment variable for the branch", skip_ci: true do
68
- it "attempts to execute a git command to determine the value" do
69
- expect(Git).to receive(:execute_git_command)
70
- expect(subject).to_not be_empty
71
- end
72
- end
73
-
74
- context "when one git branch name is returned (apart from HEAD)" do
75
- before do
76
- allow(Git).to receive(:execute_git_command).and_return(" origin/HEAD \n origin/foo")
77
- end
78
-
79
- it "returns the branch" do
80
- expect(subject).to eq "foo"
81
- end
82
- end
83
-
84
- context "when two git branch names are returned (apart from HEAD)" do
85
- before do
86
- allow(Git).to receive(:execute_git_command).and_return(" origin/HEAD \n origin/foo \n origin/bar")
87
- end
88
-
89
- it "raises an error" do
90
- expect { subject }.to raise_error PactBroker::Client::Error, /returned multiple branches: foo, bar/
91
- end
92
-
93
- include_examples "when raise_error is false"
94
- end
95
-
96
-
97
- context "when the git branch name comes back as an empty string" do
98
- before do
99
- allow(Git).to receive(:execute_git_command).and_return(" origin/HEAD")
100
- end
101
-
102
- it "raises an error" do
103
- expect { subject }.to raise_error PactBroker::Client::Error, /didn't return anything/
104
- end
105
-
106
- include_examples "when raise_error is false"
107
- end
108
-
109
- context "when there is an error executing the git command" do
110
- before do
111
- allow(Git).to receive(:execute_git_command).and_raise("some error")
112
- end
113
-
114
- it "raises an error" do
115
- expect { subject }.to raise_error PactBroker::Client::Error, /some error/
116
- end
117
-
118
- include_examples "when raise_error is false"
119
- end
120
- end
121
-
122
- describe ".build_url" do
123
- before do
124
- allow(ENV).to receive(:[]).and_call_original
125
- end
126
-
127
- subject { Git.build_url }
128
-
129
- context "when nothing is set" do
130
- before do
131
- allow(ENV).to receive(:[]).and_return(nil)
132
- end
133
-
134
- it { is_expected.to eq nil }
135
- end
136
-
137
- context "when BUILDKITE_BUILD_URL is set" do
138
- before do
139
- allow(ENV).to receive(:[]).and_return(nil)
140
- allow(ENV).to receive(:[]).with("BUILDKITE_BUILD_URL").and_return("http://build")
141
- end
142
-
143
- it { is_expected.to eq "http://build" }
144
- end
145
-
146
- context "when the Github Actions env vars are set" do
147
- before do
148
- allow(ENV).to receive(:[]).and_return(nil)
149
- allow(ENV).to receive(:[]).with("GITHUB_SERVER_URL").and_return("https://github.com")
150
- allow(ENV).to receive(:[]).with("GITHUB_REPOSITORY").and_return("org/repo")
151
- allow(ENV).to receive(:[]).with("GITHUB_RUN_ID").and_return("1")
152
- end
153
-
154
- it { is_expected.to eq "https://github.com/org/repo/actions/runs/1" }
155
- end
156
- end
157
- end
158
- end
159
- end
@@ -1,17 +0,0 @@
1
- require 'pact_broker/client/hal/authorization_header_redactor'
2
-
3
- module PactBroker
4
- module Client
5
- module Hal
6
- describe AuthorizationHeaderRedactor do
7
- let(:stream) { StringIO.new }
8
- let(:stream_redactor) { AuthorizationHeaderRedactor.new(stream) }
9
-
10
- it "redacts the authorizaton header" do
11
- stream_redactor << "\\r\\nAuthorization: Bearer TOKEN\\r\\n"
12
- expect(stream.string).to eq "\\r\\nAuthorization: [redacted]\\r\\n"
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,149 +0,0 @@
1
- require 'pact_broker/client/hal/entity'
2
- require 'pact_broker/client/hal/http_client'
3
-
4
- module PactBroker::Client
5
- module Hal
6
- describe Entity do
7
- let(:http_client) do
8
- instance_double('Pact::Hal::HttpClient', post: provider_response)
9
- end
10
-
11
- let(:provider_response) do
12
- double('response', body: provider_hash, success?: true, status: status)
13
- end
14
- let(:status) { 200 }
15
-
16
- let(:provider_hash) do
17
- {
18
- "name" => "Provider"
19
- }
20
- end
21
-
22
- let(:pact_hash) do
23
- {
24
- "name" => "a name",
25
-
26
- "_links" => {
27
- "pb:provider" => {
28
- "href" => "http://provider"
29
- },
30
- "pb:version-tag" => {
31
- "href" => "http://provider/version/{version}/tag/{tag}"
32
- }
33
- }
34
- }
35
- end
36
-
37
- subject(:entity) { Entity.new("http://pact", pact_hash, http_client) }
38
-
39
- it "delegates to the properties in the data" do
40
- expect(subject.name).to eq "a name"
41
- end
42
-
43
- describe "post" do
44
- let(:post_provider) { entity.post("pb:provider", {'some' => 'data'} ) }
45
-
46
- it "executes an http request" do
47
- expect(http_client).to receive(:post).with("http://provider", '{"some":"data"}', {})
48
- post_provider
49
- end
50
-
51
- it "returns the entity for the relation" do
52
- expect(post_provider).to be_a(Entity)
53
- end
54
-
55
- context "with template params" do
56
- let(:post_provider) { entity._link("pb:version-tag").expand(version: "1", tag: "prod").post({'some' => 'data'} ) }
57
-
58
- it "posts to the expanded URL" do
59
- expect(http_client).to receive(:post).with("http://provider/version/1/tag/prod", '{"some":"data"}', {})
60
- post_provider
61
- end
62
- end
63
- end
64
-
65
- describe "assert_success!" do
66
- context "when the response is successful" do
67
- it "returns the entity" do
68
- expect(entity.assert_success!).to be entity
69
- end
70
- end
71
-
72
- context "when the response is not successful and there is no response" do
73
- subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client) }
74
-
75
- it "raises an error" do
76
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status="
77
- end
78
- end
79
-
80
- context "when the response is not successful and there is a response" do
81
- let(:response) { double('response', status: 200, raw_body: "body") }
82
-
83
- subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client, response) }
84
-
85
- it "raises an error" do
86
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error making request to http://pact status=200 body"
87
- end
88
- end
89
- end
90
-
91
- describe "can?" do
92
- context "when the relation exists" do
93
- it "returns true" do
94
- expect(subject.can?('pb:provider')).to be true
95
- end
96
- end
97
-
98
- context "when the relation does not exist" do
99
- it "returns false" do
100
- expect(subject.can?('pb:consumer')).to be false
101
- end
102
- end
103
- end
104
-
105
- describe "_link!" do
106
- context 'when the key exists' do
107
- it 'returns a Link' do
108
- expect(subject._link!('pb:provider')).to be_a(Link)
109
- expect(subject._link!('pb:provider').href).to eq 'http://provider'
110
- end
111
- end
112
-
113
- context 'when the key does not exist' do
114
- it 'raises an error' do
115
- expect { subject._link!('foo') }.to raise_error RelationNotFoundError, /Could not find relation 'foo' in resource at http:\/\/pact/
116
- end
117
- end
118
- end
119
-
120
- describe 'fetch' do
121
- context 'when the key exists' do
122
- it 'returns fetched value' do
123
- expect(subject.fetch('pb:provider')).to eq("href" => 'http://provider')
124
- end
125
- end
126
-
127
- context "when the key doesn't not exist" do
128
- it 'returns nil' do
129
- expect(subject.fetch('i-dont-exist')).to be nil
130
- end
131
- end
132
-
133
- context "when a fallback key is provided" do
134
- context "when the fallback value exists" do
135
- it "returns the fallback value" do
136
- expect(subject.fetch('i-dont-exist', 'pb:provider')).to eq("href" => 'http://provider')
137
- end
138
- end
139
-
140
- context "when the fallback value does not exist" do
141
- it "returns nil" do
142
- expect(subject.fetch('i-dont-exist', 'i-also-dont-exist')).to be nil
143
- end
144
- end
145
- end
146
- end
147
- end
148
- end
149
- end