diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 07d3c00..681ace1 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -111,12 +111,29 @@ module Spectator::DSL else :module end %} - {% begin %} - {{type.id}} ::{{resolved.id}} - include ::Spectator::Mocks::Stubs + {% if block %} + {% begin %} + {{type.id}} ::{{resolved.id}} + include ::Spectator::Mocks::Stubs - {{block.body}} - end + {{block.body}} + end + + {% if type == :class %} + {{type.id}} Mock{{resolved.id}} < ::{{resolved.id}} + end + {% elsif type == :module %} + class Mock{{resolved.id}} + include ::{{resolved.id}} + end + {% end %} + {% end %} + {% else %} + {% if type == :struct %} + {% raise "Cannot use mock(#{resolved.id}) to create a struct" %} + {% else %} + Mock{{resolved.id}}.new + {% end %} {% end %} end