Include predicate arguments in label

This commit is contained in:
Michael Miller 2019-06-01 23:06:39 -06:00
parent 36f53d82db
commit 45f0f7f6d1

View file

@ -573,10 +573,22 @@ module Spectator::DSL
# ``` # ```
macro method_missing(call) macro method_missing(call)
{% if call.name.starts_with?("be_") %} {% if call.name.starts_with?("be_") %}
{% method_name = call.name[3..-1] %} # Remove be_ prefix. {% method_name = call.name[3..-1] %} # Remove be_ prefix.
::Spectator::Matchers::PredicateMatcher.new({ {{method_name}}: Tuple.new({{call.args.splat}}) }, {{method_name.stringify}}) descriptor = { {{method_name}}: Tuple.new({{call.args.splat}}) }
label = String::Builder.new({{method_name.stringify}})
{% unless call.args.empty? %}
label << '('
{% for arg, index in call.args %}
label << {{arg}}
{% if index < call.args.size - 1 %}
label << ", "
{% end %}
{% end %}
label << ')'
{% end %}
::Spectator::Matchers::PredicateMatcher.new(descriptor, label.to_s)
{% else %} {% else %}
{% raise "Undefined local variable or method '#{call}'" %} {% raise "Undefined local variable or method '#{call}'" %}
{% end %} {% end %}
end end
end end