Add method to define stubs

This commit is contained in:
Michael Miller 2022-03-12 14:31:19 -07:00
parent 123dd0efca
commit ea46af00a6
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 42 additions and 1 deletions

View file

@ -9,6 +9,6 @@ module Spectator
module DSL
# Keywords that cannot be used in specs using the DSL.
# These are either problematic or reserved for internal use.
RESERVED_KEYWORDS = %i[initialize _spectator_stubbed_name _spectator_find_stub]
RESERVED_KEYWORDS = %i[initialize _spectator_stubbed_name _spectator_find_stub _spectator_define_stub]
end
end

View file

@ -37,6 +37,10 @@ module Spectator
def initialize(@stubs : Array(Stub) = [] of Stub)
end
protected def _spectator_define_stub(stub : Stub) : Nil
@stubs.unshift(stub)
end
private def _spectator_find_stub(call) : Stub?
Log.debug { "Finding stub for #{call}" }
stub = @stubs.find &.===(call)