Support shorthand &.foo(ARGS) syntax

This commit is contained in:
Michael Miller 2019-02-28 15:40:04 -07:00
parent 619927b3e6
commit 1219b19d89

View file

@ -63,9 +63,9 @@ module Spectator::DSL
{% if block.args == ["__arg0".id] && block.body.is_a?(Call) && block.body.id =~ /^__arg0\./ %} {% if block.args == ["__arg0".id] && block.body.is_a?(Call) && block.body.id =~ /^__arg0\./ %}
# Extract the method name to make it clear to the user what is tested. # Extract the method name to make it clear to the user what is tested.
# The raw block can't be used because it's not clear to the user. # The raw block can't be used because it's not clear to the user.
{% method_name = block.body.id.split('.').last %} {% method_name = block.body.id.split('.')[1..-1].join('.') %}
# TODO: Maybe pass the subject in as __arg0 instead of prefixing the method name. # TODO: Maybe pass the subject in as __arg0 instead of prefixing the method name.
::Spectator::Expectations::ValueExpectationPartial.new(subject.{{method_name}}, {{"#" + method_name}}, {{_source_file}}, {{_source_line}}) ::Spectator::Expectations::ValueExpectationPartial.new(subject.{{method_name.id}}, {{"#" + method_name}}, {{_source_file}}, {{_source_line}})
{% else %} {% else %}
# In this case, it looks like the short-hand method syntax wasn't used. # In this case, it looks like the short-hand method syntax wasn't used.
# Just drop in the block as-is. # Just drop in the block as-is.