Skip to content

Commit

Permalink
feat(publish test results): rename example to test in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Nov 13, 2017
1 parent bf5e753 commit cd2b79e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
27 changes: 13 additions & 14 deletions lib/pact/provider/rspec/pact_broker_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@ def dump_summary(summary)
end

def stop(notification)
@output_hash[:examples] = notification.examples.map do |example|
format_example(example).tap do |hash|
e = example.exception
if e
hash[:exception] = {
class: e.class.name,
message: ::Term::ANSIColor.uncolor(e.message)
}
end
end
end
@output_hash[:tests] = notification
.examples
.map { |example| format_example(example) }
end

def seed(notification)
Expand All @@ -53,14 +45,21 @@ def close(_notification)

def format_example(example)
{
exampleDescription: example.description,
exampleFullDescription: example.full_description,
testDescription: example.description,
testFullDescription: example.full_description,
status: example.execution_result.status.to_s,
interactionProviderState: example.metadata[:pact_interaction].provider_state,
interactionDescription: example.metadata[:pact_interaction].description,
pact_uri: example.metadata[:pact_uri],
pact_interaction: example.metadata[:pact_interaction]
}
}.tap do |hash|
if example.exception
hash[:exception] = {
class: example.exception.class.name,
message: ::Term::ANSIColor.uncolor(example.exception.message)
}
end
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pact/provider/verification_results/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def publishable?
end

def examples_for_pact_uri
@examples_for_pact_uri ||= test_results_hash[:examples].select{ |e| e[:pact_uri] == pact_uri }
@examples_for_pact_uri ||= test_results_hash[:tests].select{ |e| e[:pact_uri] == pact_uri }
end

def count_failures_for_pact_uri
Expand All @@ -52,9 +52,9 @@ def all_interactions_count

def test_results_hash_for_pact_uri
{
examples: examples_for_pact_uri.collect{ |e| clean_example(e) },
tests: examples_for_pact_uri.collect{ |e| clean_example(e) },
summary: {
exampleCount: examples_for_pact_uri.size,
testCount: examples_for_pact_uri.size,
failureCount: count_failures_for_pact_uri
}
}
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/publish_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@

let(:test_results_hash) do
{
examples: [
tests: [
{
exampleDescription: '1',
testDescription: '1',
status: 'passed',
pact_uri: pact_uri
}
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact/provider/verification_results/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module VerificationResults
end
let(:test_results_hash) do
{
examples: [example_1, example_2]
tests: [example_1, example_2]
}
end
let(:pact_hash_1) do
Expand All @@ -51,8 +51,8 @@ module VerificationResults

it "creates a VerificationResult with the relevant test results" do
expected_test_results_hash = {
examples: [{ status: "passed" }],
summary: { exampleCount: 1, failureCount: 0}
tests: [{ status: "passed" }],
summary: { testCount: 1, failureCount: 0}
}
expect(VerificationResult).to receive(:new).with(anything, anything, anything, expected_test_results_hash)
subject
Expand Down

0 comments on commit cd2b79e

Please sign in to comment.