Use NilMethodStub by default

Provides one place that #with can be defined and enforces ordering.
This commit is contained in:
Michael Miller 2019-11-03 11:23:04 -07:00
parent af9104dfe4
commit 477271d297
3 changed files with 21 additions and 6 deletions

View file

@ -46,6 +46,6 @@ module Spectator::DSL
macro receive(method_name, _source_file = __FILE__, _source_line = __LINE__) macro receive(method_name, _source_file = __FILE__, _source_line = __LINE__)
%source = ::Spectator::Source.new({{_source_file}}, {{_source_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
end end

View 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

View file

@ -1,4 +1,4 @@
require "./arguments" require "./generic_arguments"
require "./generic_method_stub" require "./generic_method_stub"
module Spectator::Mocks module Spectator::Mocks
@ -10,9 +10,5 @@ module Spectator::Mocks
def call(_args : GenericArguments(T, NT)) : ReturnType forall T, NT def call(_args : GenericArguments(T, NT)) : ReturnType forall T, NT
@value @value
end end
def and_return(value : T) forall T
ValueMethodStub.new(@name, @source, value)
end
end end
end end