Raise UnexpectedMessageError

This commit is contained in:
Michael Miller 2019-11-11 22:08:36 -07:00
parent 18b3879dce
commit 925af7908b
2 changed files with 6 additions and 1 deletions

View file

@ -1,5 +1,6 @@
require "./generic_method_call"
require "./generic_method_stub"
require "./unexpected_message_error"
module Spectator::Mocks
abstract class Double
@ -61,7 +62,7 @@ module Spectator::Mocks
{% if body && !body.is_a?(Nop) %}
{{body.body}}
{% else %}
raise "Stubbed method called without being allowed"
raise ::Spectator::Mocks::UnexpectedMessageError.new("#{self} received unexpected message {{name}}")
# This code shouldn't be reached, but makes the compiler happy to have a matching return type.
{% if definition.is_a?(TypeDeclaration) %}
%x = uninitialized {{definition.type}}

View file

@ -0,0 +1,4 @@
module Spectator::Mocks
class UnexpectedMessageError < Exception
end
end