@@ -4,38 +4,54 @@ module Provider
44 module VerificationResults
55 class Create
66
7- def self . call pact_json , failed_examples
8- new ( pact_json , failed_examples ) . call
7+ def self . call pact_source , test_results_hash
8+ new ( pact_source , test_results_hash ) . call
99 end
1010
11- def initialize pact_json , failed_examples
12- @pact_json = pact_json
13- @failed_examples = failed_examples
11+ def initialize pact_source , test_results_hash
12+ @pact_source = pact_source
13+ @test_results_hash = test_results_hash
1414 end
1515
1616 def call
17- VerificationResult . new ( !any_failures? , Pact . configuration . provider . application_version )
17+ VerificationResult . new ( !any_failures? , Pact . configuration . provider . application_version , test_results_hash_for_pact_uri )
1818 end
1919
2020 private
2121
22- def pact_hash
23- @pact_hash ||= json_load ( pact_json )
22+ def pact_uri
23+ @pact_uri ||= pact_source . uri
2424 end
2525
26- def json_load json
27- JSON . load ( json , nil , { max_nesting : 50 } )
26+ def any_failures?
27+ count_failures_for_pact_uri > 0
2828 end
2929
30- def count_failures_for_pact_json
31- failed_examples . collect { |e | e . metadata [ :pact_json ] == pact_json } . uniq . size
30+ def examples_for_pact_uri
31+ @examples_for_pact_uri ||= test_results_hash [ :examples ]
32+ . select { |e | e [ :pact_uri ] == pact_uri }
33+ . collect { |e | clean_example ( e ) }
3234 end
3335
34- def any_failures?
35- count_failures_for_pact_json > 0
36+ def count_failures_for_pact_uri
37+ examples_for_pact_uri . count { |e | e [ :status ] != 'passed' }
38+ end
39+
40+ def test_results_hash_for_pact_uri
41+ {
42+ examples : examples_for_pact_uri ,
43+ summary : {
44+ exampleCount : examples_for_pact_uri . size ,
45+ failureCount : count_failures_for_pact_uri
46+ }
47+ }
48+ end
49+
50+ def clean_example ( example )
51+ example . reject { |k , v | k == :pact_uri }
3652 end
3753
38- attr_reader :pact_json , :failed_examples
54+ attr_reader :pact_source , :test_results_hash
3955 end
4056 end
4157 end
0 commit comments