@@ -54,28 +54,30 @@ def dump_summary(summary)
5454 private
5555
5656 def interactions_count ( summary )
57- summary . examples . collect { |e | e . metadata [ :pact_interaction_example_description ] } . uniq . size
57+ summary . examples . collect { |e | interaction_unique_key ( e ) } . uniq . size
5858 end
5959
6060 def failed_interactions_count ( summary )
61- summary . failed_examples . collect { |e | e . metadata [ :pact_interaction_example_description ] } . uniq . size
61+ failed_interaction_examples ( summary ) . size
62+ end
63+
64+ def pending_interactions_count ( summary )
65+ pending_interaction_examples ( summary ) . size
6266 end
6367
6468 def ignore_failures? ( summary )
6569 summary . failed_examples . any? { |e | e . metadata [ :pact_ignore_failures ] }
6670 end
6771
6872 def failure_title summary
69- if ignore_failures? ( summary )
70- "#{ failed_interactions_count ( summary ) } pending"
71- else
72- ::RSpec ::Core ::Formatters ::Helpers . pluralize ( failed_interactions_count ( summary ) , "failure" )
73- end
73+ ::RSpec ::Core ::Formatters ::Helpers . pluralize ( failed_interactions_count ( summary ) , "failure" )
7474 end
7575
7676 def totals_line summary
7777 line = ::RSpec ::Core ::Formatters ::Helpers . pluralize ( interactions_count ( summary ) , "interaction" )
7878 line << ", " << failure_title ( summary )
79+ pending_count = pending_interactions_count ( summary )
80+ line << ", " << "#{ pending_count } pending" if pending_count > 0
7981 line
8082 end
8183
@@ -88,12 +90,17 @@ def color_for_summary summary
8890 end
8991
9092 def print_rerun_commands summary
91- if ignore_failures? ( summary )
93+ if pending_interactions_count ( summary ) > 0
94+ set_rspec_failure_color ( :yellow )
9295 output . puts ( "\n Pending interactions: (Failures listed here are expected and do not affect your suite's status)\n \n " )
93- else
94- output . puts ( "\n Failed interactions:\n \n " )
96+ interaction_rerun_commands ( pending_interaction_examples ( summary ) ) . each do | message |
97+ output . puts ( message )
98+ end
9599 end
96- interaction_rerun_commands ( summary ) . each do | message |
100+
101+ set_rspec_failure_color ( :red )
102+ output . puts ( "\n Failed interactions:\n \n " )
103+ interaction_rerun_commands ( failed_interaction_examples ( summary ) ) . each do | message |
97104 output . puts ( message )
98105 end
99106 end
@@ -104,10 +111,34 @@ def print_missing_provider_states
104111 end
105112 end
106113
107- def interaction_rerun_commands summary
108- summary . failed_examples . collect do |example |
114+ def pending_interaction_examples ( summary )
115+ one_failed_example_per_interaction ( summary ) . select do | example |
116+ example . metadata [ :pactfile_uri ] . metadata [ :pending ]
117+ end
118+ end
119+
120+ def failed_interaction_examples ( summary )
121+ one_failed_example_per_interaction ( summary ) . select do | example |
122+ !example . metadata [ :pactfile_uri ] . metadata [ :pending ]
123+ end
124+ end
125+
126+ def one_failed_example_per_interaction ( summary )
127+ summary . failed_examples . group_by { | e | interaction_unique_key ( e ) } . values . collect ( &:first )
128+ end
129+
130+ def interaction_rerun_commands examples
131+ examples . collect do |example |
109132 interaction_rerun_command_for example
110- end . uniq . compact
133+ end . compact
134+ end
135+
136+ def interaction_unique_key ( example )
137+ # pending is just to make the counting easier, it isn't required for the unique key
138+ {
139+ pactfile_uri : example . metadata [ :pactfile_uri ] ,
140+ index : example . metadata [ :pact_interaction ] . index ,
141+ }
111142 end
112143
113144 def interaction_rerun_command_for example
@@ -156,6 +187,10 @@ def colorizer
156187 def executing_with_ruby?
157188 ENV [ 'PACT_EXECUTING_LANGUAGE' ] == 'ruby'
158189 end
190+
191+ def set_rspec_failure_color color
192+ ::RSpec . configuration . failure_color = color
193+ end
159194 end
160195 end
161196 end
0 commit comments