Skip to content

Commit fee068a

Browse files
committed
fix dependency (and tag) descriptions stomping over other descriptions.
collect descriptions in a new array before joining them together. put English logic in separate function english_list.
1 parent 88004c7 commit fee068a

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

lib/rspec-puppet/matchers/create_generic.rb

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def failure_message_when_negated
141141
end
142142

143143
def description
144+
tests = []
144145
values = []
145-
value_str_prefix = "with"
146146

147147
if @expected_params_count
148148
values << "exactly #{@expected_params_count} parameters"
@@ -157,44 +157,39 @@ def description
157157
end
158158

159159
if @notifies.any?
160-
value_str_prefix = "that notifies"
161-
values = @notifies
160+
tests << english_list("that notifies", @notifies)
162161
end
163162

164163
if @subscribes.any?
165-
value_str_prefix = "that subscribes to"
166-
values = @subscribes
164+
tests << english_list("that subscribes to", @subscribes)
167165
end
168166

169167
if @requires.any?
170-
value_str_prefix = "that requires"
171-
values = @requires
168+
tests << english_list("that requires", @requires)
172169
end
173170

174171
if @befores.any?
175-
value_str_prefix = "that comes before"
176-
values = @befores
172+
tests << english_list("that comes before", @befores)
177173
end
178174

179175
if @tagged.any?
180-
value_str_prefix = "that is tagged"
181-
values = @tagged
176+
tests << english_list("that is tagged", @tagged)
182177
end
183178

184179
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")
187181
end
188182

189183
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)
195190
end
196191

197-
"contain #{@referenced_type}[#{@title}]#{value_str}"
192+
"contain #{@referenced_type}[#{@title}]#{tests_str}"
198193
end
199194

200195
def diffable?
@@ -236,6 +231,16 @@ def generate_param_list(list, type)
236231
output
237232
end
238233

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+
239244
def check_befores(catalogue, resource)
240245
@befores.each do |ref|
241246
unless precedes?(resource, canonicalize_resource(ref))

0 commit comments

Comments
 (0)