Skip to content

Commit cd2b79e

Browse files
committed
feat(publish test results): rename example to test in JSON
1 parent bf5e753 commit cd2b79e

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

lib/pact/provider/rspec/pact_broker_formatter.rb

+13-14
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,9 @@ def dump_summary(summary)
2727
end
2828

2929
def stop(notification)
30-
@output_hash[:examples] = notification.examples.map do |example|
31-
format_example(example).tap do |hash|
32-
e = example.exception
33-
if e
34-
hash[:exception] = {
35-
class: e.class.name,
36-
message: ::Term::ANSIColor.uncolor(e.message)
37-
}
38-
end
39-
end
40-
end
30+
@output_hash[:tests] = notification
31+
.examples
32+
.map { |example| format_example(example) }
4133
end
4234

4335
def seed(notification)
@@ -53,14 +45,21 @@ def close(_notification)
5345

5446
def format_example(example)
5547
{
56-
exampleDescription: example.description,
57-
exampleFullDescription: example.full_description,
48+
testDescription: example.description,
49+
testFullDescription: example.full_description,
5850
status: example.execution_result.status.to_s,
5951
interactionProviderState: example.metadata[:pact_interaction].provider_state,
6052
interactionDescription: example.metadata[:pact_interaction].description,
6153
pact_uri: example.metadata[:pact_uri],
6254
pact_interaction: example.metadata[:pact_interaction]
63-
}
55+
}.tap do |hash|
56+
if example.exception
57+
hash[:exception] = {
58+
class: example.exception.class.name,
59+
message: ::Term::ANSIColor.uncolor(example.exception.message)
60+
}
61+
end
62+
end
6463
end
6564
end
6665
end

lib/pact/provider/verification_results/create.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def publishable?
3232
end
3333

3434
def examples_for_pact_uri
35-
@examples_for_pact_uri ||= test_results_hash[:examples].select{ |e| e[:pact_uri] == pact_uri }
35+
@examples_for_pact_uri ||= test_results_hash[:tests].select{ |e| e[:pact_uri] == pact_uri }
3636
end
3737

3838
def count_failures_for_pact_uri
@@ -52,9 +52,9 @@ def all_interactions_count
5252

5353
def test_results_hash_for_pact_uri
5454
{
55-
examples: examples_for_pact_uri.collect{ |e| clean_example(e) },
55+
tests: examples_for_pact_uri.collect{ |e| clean_example(e) },
5656
summary: {
57-
exampleCount: examples_for_pact_uri.size,
57+
testCount: examples_for_pact_uri.size,
5858
failureCount: count_failures_for_pact_uri
5959
}
6060
}

spec/integration/publish_verification_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646

4747
let(:test_results_hash) do
4848
{
49-
examples: [
49+
tests: [
5050
{
51-
exampleDescription: '1',
51+
testDescription: '1',
5252
status: 'passed',
5353
pact_uri: pact_uri
5454
}

spec/lib/pact/provider/verification_results/create_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module VerificationResults
3434
end
3535
let(:test_results_hash) do
3636
{
37-
examples: [example_1, example_2]
37+
tests: [example_1, example_2]
3838
}
3939
end
4040
let(:pact_hash_1) do
@@ -51,8 +51,8 @@ module VerificationResults
5151

5252
it "creates a VerificationResult with the relevant test results" do
5353
expected_test_results_hash = {
54-
examples: [{ status: "passed" }],
55-
summary: { exampleCount: 1, failureCount: 0}
54+
tests: [{ status: "passed" }],
55+
summary: { testCount: 1, failureCount: 0}
5656
}
5757
expect(VerificationResult).to receive(:new).with(anything, anything, anything, expected_test_results_hash)
5858
subject

0 commit comments

Comments
 (0)