From 291b4c75a857556991f8f16d8d586e1964bb3da9 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 12 Mar 2022 23:02:33 -0700 Subject: [PATCH] Compiler error if stub defined in a method --- src/spectator/mocks/stubbable.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spectator/mocks/stubbable.cr b/src/spectator/mocks/stubbable.cr index b6aa708..dead512 100644 --- a/src/spectator/mocks/stubbable.cr +++ b/src/spectator/mocks/stubbable.cr @@ -45,6 +45,7 @@ module Spectator # # Stubbed methods will call `#_spectator_find_stub` with the method call information. private macro stub(method) + {% raise "Cannot define a stub inside a method" if @def %} {% raise "stub requires a method definition" if !method.is_a?(Def) %} {% raise "Cannot stub method with reserved keyword as name - #{method.name}" if method.name.starts_with?("_spectator") || ::Spectator::DSL::RESERVED_KEYWORDS.includes?(method.name.symbolize) %} @@ -108,6 +109,7 @@ module Spectator # # Stubbed methods will call `#_spectator_find_stub` with the method call information. private macro abstract_stub(method) + {% raise "Cannot define a stub inside a method" if @def %} {% raise "abstract_stub requires a method definition" if !method.is_a?(Def) %} {% raise "Cannot stub method with reserved keyword as name - #{method.name}" if method.name.starts_with?("_spectator") || ::Spectator::DSL::RESERVED_KEYWORDS.includes?(method.name.symbolize) %}