mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add with
stub modifier
This commit is contained in:
parent
cd177dd2ae
commit
4aaed186c3
7 changed files with 85 additions and 0 deletions
|
@ -11,6 +11,12 @@ module Spectator
|
|||
raise @exception
|
||||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.class.new(method, @exception, constraint, location)
|
||||
end
|
||||
|
||||
# Creates the stub.
|
||||
def initialize(method : Symbol, @exception : Exception, constraint : AbstractArguments? = nil, location : Location? = nil)
|
||||
super(method, constraint, location)
|
||||
|
|
|
@ -15,6 +15,12 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.class.new(method, @values, constraint, location)
|
||||
end
|
||||
|
||||
# Creates the stub.
|
||||
def initialize(method : Symbol, @values : Array(T), constraint : AbstractArguments? = nil, location : Location? = nil)
|
||||
super(method, constraint, location)
|
||||
|
|
|
@ -7,5 +7,11 @@ module Spectator
|
|||
# Invokes the stubbed implementation.
|
||||
def call(call : MethodCall) : Nil
|
||||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.class.new(method, constraint, location)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,12 @@ module Spectator
|
|||
@proc.call(call.arguments)
|
||||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.class.new(method, @proc, constraint, location)
|
||||
end
|
||||
|
||||
# Creates the stub.
|
||||
def initialize(method : Symbol, @proc : Proc(AbstractArguments, T), constraint : AbstractArguments? = nil, location : Location? = nil)
|
||||
super(method, constraint, location)
|
||||
|
@ -20,4 +26,12 @@ module Spectator
|
|||
initialize(method, block, constraint, location)
|
||||
end
|
||||
end
|
||||
|
||||
module StubModifiers
|
||||
# Returns a new stub with an argument constraint.
|
||||
def with(*args, **kwargs, &block : AbstractArguments -> T) forall T
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
ProcStub(T).new(method, block, constraint, location)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module Spectator
|
||||
# Mixin intended for `Stub` to return new, modified stubs.
|
||||
module StubModifiers
|
||||
# Returns a new stub of the same type with constrained arguments.
|
||||
abstract def with(*args, **kwargs)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,12 @@ module Spectator
|
|||
@value
|
||||
end
|
||||
|
||||
# Returns a new stub with constrained arguments.
|
||||
def with(*args, **kwargs)
|
||||
constraint = Arguments.new(args, kwargs)
|
||||
self.class.new(method, @value, constraint, location)
|
||||
end
|
||||
|
||||
# Creates the stub.
|
||||
def initialize(method : Symbol, @value : T, constraint : AbstractArguments? = nil, location : Location? = nil)
|
||||
super(method, constraint, location)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue