From 2666f806531ac3407b72c1dfd5068a82d77a3c05 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 11 Aug 2019 13:16:18 -0600 Subject: [PATCH] Hackish fix for block short-hand syntax Dunno when this broke or how it ever worked. :neutral_face: --- src/spectator/dsl/example_dsl.cr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spectator/dsl/example_dsl.cr b/src/spectator/dsl/example_dsl.cr index da90e2e..5fea5a7 100644 --- a/src/spectator/dsl/example_dsl.cr +++ b/src/spectator/dsl/example_dsl.cr @@ -55,9 +55,6 @@ module Spectator::DSL {% raise "Argument or block must be provided to expect" %} {% end %} - # Create a proc to capture the block. - %proc = ->({{block.args.splat}}) {{block}} - # Check if the short-hand method syntax is used. # This is a hack, since macros don't get this as a "literal" or something similar. # The Crystal compiler will translate: @@ -73,12 +70,15 @@ module Spectator::DSL # 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. {% method_name = block.body.id.split('.')[1..-1].join('.') %} - %partial = %proc.partial(subject) - %test_block = ::Spectator::TestBlock.create(%partial, {{"#" + method_name}}) - {% else %} + %proc = ->{ subject.{{method_name.id}} } + %test_block = ::Spectator::TestBlock.create(%proc, {{"#" + method_name}}) + {% elsif block.args.empty? %} # In this case, it looks like the short-hand method syntax wasn't used. - # Just drop in the proc as-is. + # Capture the block as a proc and pass along. + %proc = ->{{block}} %test_block = ::Spectator::TestBlock.create(%proc, {{"`" + block.body.stringify + "`"}}) + {% else %} + {% raise "Unexpected block arguments in expect call" %} {% end %} %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})