@@ -141,8 +141,8 @@ def failure_message_when_negated
141
141
end
142
142
143
143
def description
144
+ tests = [ ]
144
145
values = [ ]
145
- value_str_prefix = "with"
146
146
147
147
if @expected_params_count
148
148
values << "exactly #{ @expected_params_count } parameters"
@@ -157,44 +157,39 @@ def description
157
157
end
158
158
159
159
if @notifies . any?
160
- value_str_prefix = "that notifies"
161
- values = @notifies
160
+ tests << english_list ( "that notifies" , @notifies )
162
161
end
163
162
164
163
if @subscribes . any?
165
- value_str_prefix = "that subscribes to"
166
- values = @subscribes
164
+ tests << english_list ( "that subscribes to" , @subscribes )
167
165
end
168
166
169
167
if @requires . any?
170
- value_str_prefix = "that requires"
171
- values = @requires
168
+ tests << english_list ( "that requires" , @requires )
172
169
end
173
170
174
171
if @befores . any?
175
- value_str_prefix = "that comes before"
176
- values = @befores
172
+ tests << english_list ( "that comes before" , @befores )
177
173
end
178
174
179
175
if @tagged . any?
180
- value_str_prefix = "that is tagged"
181
- values = @tagged
176
+ tests << english_list ( "that is tagged" , @tagged )
182
177
end
183
178
184
179
if @not_tagged . any?
185
- value_str_prefix = "that is not tagged"
186
- values = @not_tagged
180
+ tests << english_list ( "that is not tagged" , @not_tagged , "nor" )
187
181
end
188
182
189
183
unless values . empty?
190
- if values . length == 1
191
- value_str = " #{ value_str_prefix } #{ values . first } "
192
- else
193
- value_str = " #{ value_str_prefix } #{ values [ 0 ..-2 ] . join ( ", " ) } and #{ values [ -1 ] } "
194
- end
184
+ tests << english_list ( "with" , values )
185
+ end
186
+
187
+ tests_str = ""
188
+ unless tests . empty?
189
+ tests_str = english_list ( "" , tests , "and" , true )
195
190
end
196
191
197
- "contain #{ @referenced_type } [#{ @title } ]#{ value_str } "
192
+ "contain #{ @referenced_type } [#{ @title } ]#{ tests_str } "
198
193
end
199
194
200
195
def diffable?
@@ -236,6 +231,16 @@ def generate_param_list(list, type)
236
231
output
237
232
end
238
233
234
+ def english_list ( value_str_prefix , values , joiner = 'and' , oxford_comma = false )
235
+ if values . length == 1
236
+ "#{ value_str_prefix } #{ values . first } "
237
+ elsif oxford_comma
238
+ "#{ value_str_prefix } #{ values [ 0 ..-2 ] . join ( ", " ) } , #{ joiner } #{ values [ -1 ] } "
239
+ else
240
+ "#{ value_str_prefix } #{ values [ 0 ..-2 ] . join ( ", " ) } #{ joiner } #{ values [ -1 ] } "
241
+ end
242
+ end
243
+
239
244
def check_befores ( catalogue , resource )
240
245
@befores . each do |ref |
241
246
unless precedes? ( resource , canonicalize_resource ( ref ) )
0 commit comments