mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow StubbedType alongside Stubbable for allow()
This commit is contained in:
parent
55b2ac9f05
commit
77096b76e9
2 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue