From 477271d297f782ef0e9f138145dc866d7ebb1726 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 3 Nov 2019 11:23:04 -0700 Subject: [PATCH] Use NilMethodStub by default Provides one place that #with can be defined and enforces ordering. --- src/spectator/dsl/mocks.cr | 2 +- src/spectator/mocks/nil_method_stub.cr | 19 +++++++++++++++++++ src/spectator/mocks/value_method_stub.cr | 6 +----- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/spectator/mocks/nil_method_stub.cr diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 5d1e927..6e29045 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -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 diff --git a/src/spectator/mocks/nil_method_stub.cr b/src/spectator/mocks/nil_method_stub.cr new file mode 100644 index 0000000..68274d2 --- /dev/null +++ b/src/spectator/mocks/nil_method_stub.cr @@ -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 diff --git a/src/spectator/mocks/value_method_stub.cr b/src/spectator/mocks/value_method_stub.cr index 0fa5b77..fbf7421 100644 --- a/src/spectator/mocks/value_method_stub.cr +++ b/src/spectator/mocks/value_method_stub.cr @@ -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