Allow StubbedType alongside Stubbable for allow()

This commit is contained in:
Michael Miller 2022-07-07 19:01:02 -06:00
parent 55b2ac9f05
commit 77096b76e9
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
2 changed files with 5 additions and 4 deletions

View file

@ -200,14 +200,14 @@ module Spectator::DSL
# Targets a stubbable object (such as a mock or double) for operations.
#
# The *stubbable* must be a `Stubbable`.
# The *stubbable* must be a `Stubbable` or `StubbedType`.
# This method is expected to be followed up with `.to receive()`.
#
# ```
# dbl = dbl(:foobar)
# allow(dbl).to receive(:foo).and_return(42)
# ```
def allow(stubbable : Stubbable)
def allow(stubbable : Stubbable | StubbedType)
::Spectator::Allow.new(stubbable)
end

View file

@ -1,5 +1,6 @@
require "./stub"
require "./stubbable"
require "./stubbed_type"
module Spectator
# Targets a stubbable object.
@ -12,9 +13,9 @@ module Spectator
struct Allow(T)
# Creates the stub target.
#
# The *target* must be a kind of `Stubbable`.
# The *target* must be a kind of `Stubbable` or `StubbedType`.
def initialize(@target : T)
{% raise "Target of `allow` must be stubbable (a mock or double)." unless T < Stubbable %}
{% raise "Target of `allow` must be stubbable (a mock or double)." unless T < Stubbable || T < StubbedType %}
end
# Applies a stub to the targeted stubbable object.