mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement stub that raises
This commit is contained in:
parent
6e287f864b
commit
b896a7f1d5
2 changed files with 30 additions and 0 deletions
14
src/spectator/mocks/exception_method_stub.cr
Normal file
14
src/spectator/mocks/exception_method_stub.cr
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
require "./generic_arguments"
|
||||||
|
require "./generic_method_stub"
|
||||||
|
|
||||||
|
module Spectator::Mocks
|
||||||
|
class ExceptionMethodStub(ExceptionType) < GenericMethodStub(Nil)
|
||||||
|
def initialize(name, source, @exception : ExceptionType, args = nil)
|
||||||
|
super(name, source, args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(_args : GenericArguments(T2, NT2), rt : RT.class) forall T2, NT2, RT
|
||||||
|
raise @exception
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -20,6 +20,22 @@ module Spectator::Mocks
|
||||||
MultiValueMethodStub.new(@name, @source, values.to_a, @args)
|
MultiValueMethodStub.new(@name, @source, values.to_a, @args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def and_raise(exception_type : Exception.class)
|
||||||
|
ExceptionMethodStub.new(@name, @source, exception_type.new, @args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def and_raise(exception : Exception)
|
||||||
|
ExceptionMethodStub.new(@name, @source, exception, @args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def and_raise(message : String)
|
||||||
|
ExceptionMethodStub.new(@name, @source, Exception.new(message), @args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def and_raise(exception_type : Exception.class, *args) forall T
|
||||||
|
ExceptionMethodStub.new(@name, @source, exception_type.new(*args), @args)
|
||||||
|
end
|
||||||
|
|
||||||
def with(*args : *T, **opts : **NT) forall T, NT
|
def with(*args : *T, **opts : **NT) forall T, NT
|
||||||
args = GenericArguments.new(args, opts)
|
args = GenericArguments.new(args, opts)
|
||||||
NilMethodStub.new(@name, @source, args)
|
NilMethodStub.new(@name, @source, args)
|
||||||
|
|
Loading…
Reference in a new issue