Skip to content

Commit

Permalink
fix dependency (and tag) descriptions stomping over other descriptions.
Browse files Browse the repository at this point in the history
collect descriptions in a new array before joining them together.  put English
logic in separate function english_list.
  • Loading branch information
kjetilho committed Jul 6, 2017
1 parent 88004c7 commit fee068a
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions lib/rspec-puppet/matchers/create_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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?
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit fee068a

Please sign in to comment.