mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use NilMethodStub by default
Provides one place that #with can be defined and enforces ordering.
This commit is contained in:
parent
af9104dfe4
commit
477271d297
3 changed files with 21 additions and 6 deletions
|
@ -46,6 +46,6 @@ module Spectator::DSL
|
|||
|
||||
macro receive(method_name, _source_file = __FILE__, _source_line = __LINE__)
|
||||
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
|
||||
::Spectator::Mocks::ValueMethodStub.new({{method_name.symbolize}}, %source, nil)
|
||||
::Spectator::Mocks::NilMethodStub.new({{method_name.symbolize}}, %source)
|
||||
end
|
||||
end
|
||||
|
|
19
src/spectator/mocks/nil_method_stub.cr
Normal file
19
src/spectator/mocks/nil_method_stub.cr
Normal file
|
@ -0,0 +1,19 @@
|
|||
require "./generic_arguments"
|
||||
require "./generic_method_stub"
|
||||
require "./value_method_stub"
|
||||
|
||||
module Spectator::Mocks
|
||||
class NilMethodStub < GenericMethodStub(Nil)
|
||||
def initialize(name, source, args = nil)
|
||||
super(name, source, args)
|
||||
end
|
||||
|
||||
def call(_args : GenericArguments(T, NT)) : ReturnType forall T, NT
|
||||
nil
|
||||
end
|
||||
|
||||
def and_return(value : T) forall T
|
||||
ValueMethodStub.new(@name, @source, value)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
require "./arguments"
|
||||
require "./generic_arguments"
|
||||
require "./generic_method_stub"
|
||||
|
||||
module Spectator::Mocks
|
||||
|
@ -10,9 +10,5 @@ module Spectator::Mocks
|
|||
def call(_args : GenericArguments(T, NT)) : ReturnType forall T, NT
|
||||
@value
|
||||
end
|
||||
|
||||
def and_return(value : T) forall T
|
||||
ValueMethodStub.new(@name, @source, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue