From fee068a4c4407c0a308990d3e8ef090dae9eb2e9 Mon Sep 17 00:00:00 2001 From: Kjetil Torgrim Homme Date: Thu, 6 Jul 2017 12:28:18 +0200 Subject: [PATCH] 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. --- lib/rspec-puppet/matchers/create_generic.rb | 43 ++++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/rspec-puppet/matchers/create_generic.rb b/lib/rspec-puppet/matchers/create_generic.rb index e34fdd6f7..ce291da9c 100644 --- a/lib/rspec-puppet/matchers/create_generic.rb +++ b/lib/rspec-puppet/matchers/create_generic.rb @@ -141,8 +141,8 @@ def failure_message_when_negated end def description + tests = [] values = [] - value_str_prefix = "with" if @expected_params_count values << "exactly #{@expected_params_count} parameters" @@ -157,44 +157,39 @@ def description end if @notifies.any? - value_str_prefix = "that notifies" - values = @notifies + tests << english_list("that notifies", @notifies) end if @subscribes.any? - value_str_prefix = "that subscribes to" - values = @subscribes + tests << english_list("that subscribes to", @subscribes) end if @requires.any? - value_str_prefix = "that requires" - values = @requires + tests << english_list("that requires", @requires) end if @befores.any? - value_str_prefix = "that comes before" - values = @befores + tests << english_list("that comes before", @befores) end if @tagged.any? - value_str_prefix = "that is tagged" - values = @tagged + tests << english_list("that is tagged", @tagged) end if @not_tagged.any? - value_str_prefix = "that is not tagged" - values = @not_tagged + tests << english_list("that is not tagged", @not_tagged, "nor") end unless values.empty? - if values.length == 1 - value_str = " #{value_str_prefix} #{values.first}" - else - value_str = " #{value_str_prefix} #{values[0..-2].join(", ")} and #{values[-1]}" - end + tests << english_list("with", values) + end + + tests_str = "" + unless tests.empty? + tests_str = english_list("", tests, "and", true) end - "contain #{@referenced_type}[#{@title}]#{value_str}" + "contain #{@referenced_type}[#{@title}]#{tests_str}" end def diffable? @@ -236,6 +231,16 @@ def generate_param_list(list, type) output end + def english_list(value_str_prefix, values, joiner='and', oxford_comma=false) + if values.length == 1 + "#{value_str_prefix} #{values.first}" + elsif oxford_comma + "#{value_str_prefix} #{values[0..-2].join(", ")}, #{joiner} #{values[-1]}" + else + "#{value_str_prefix} #{values[0..-2].join(", ")} #{joiner} #{values[-1]}" + end + end + def check_befores(catalogue, resource) @befores.each do |ref| unless precedes?(resource, canonicalize_resource(ref))