diff --git a/src/spectator/expectations/expectation_partial.cr b/src/spectator/expectations/expectation_partial.cr index e848eaf..31606b2 100644 --- a/src/spectator/expectations/expectation_partial.cr +++ b/src/spectator/expectations/expectation_partial.cr @@ -24,10 +24,10 @@ module Spectator::Expectations report(match_data) end - def to(stub : Mocks::GenericMethodStub(RT, T, NT)) : Nil forall RT, T, NT + def to(stub : Mocks::MethodStub) : Nil value = TestValue.new(stub.name, stub.to_s) - matcher = if stub.arguments? - Matchers::ReceiveArgumentsMatcher.new(value, stub.arguments) + matcher = if (arguments = stub.arguments?) + Matchers::ReceiveArgumentsMatcher.new(value, arguments) else Matchers::ReceiveMatcher.new(value) end @@ -42,7 +42,13 @@ module Spectator::Expectations end def to_not(stub : Mocks::MethodStub) : Nil - raise NotImplementedError.new("`expect(double).to_not receive(message)` syntax not implemented yet") + value = TestValue.new(stub.name, stub.to_s) + matcher = if (arguments = stub.arguments?) + Matchers::ReceiveArgumentsMatcher.new(value, arguments) + else + Matchers::ReceiveMatcher.new(value) + end + to_never(matcher) end # ditto diff --git a/src/spectator/matchers/receive_arguments_matcher.cr b/src/spectator/matchers/receive_arguments_matcher.cr index bc729db..e4053cc 100644 --- a/src/spectator/matchers/receive_arguments_matcher.cr +++ b/src/spectator/matchers/receive_arguments_matcher.cr @@ -2,10 +2,10 @@ require "../mocks" require "./standard_matcher" module Spectator::Matchers - struct ReceiveArgumentsMatcher(T, NT) < StandardMatcher + struct ReceiveArgumentsMatcher < StandardMatcher alias Range = ::Range(Int32, Int32) | ::Range(Nil, Int32) | ::Range(Int32, Nil) - def initialize(@expected : TestExpression(Symbol), @args : Mocks::GenericArguments(T, NT), @range : Range? = nil) + def initialize(@expected : TestExpression(Symbol), @args : Mocks::Arguments, @range : Range? = nil) end def description : String diff --git a/src/spectator/mocks/generic_method_stub.cr b/src/spectator/mocks/generic_method_stub.cr index 373de46..c0ee38f 100644 --- a/src/spectator/mocks/generic_method_stub.cr +++ b/src/spectator/mocks/generic_method_stub.cr @@ -4,10 +4,10 @@ require "./method_call" require "./method_stub" module Spectator::Mocks - abstract class GenericMethodStub(ReturnType, T, NT) < MethodStub - getter! arguments : GenericArguments(T, NT) + abstract class GenericMethodStub(ReturnType) < MethodStub + getter! arguments : Arguments - def initialize(name, source, @args : GenericArguments(T, NT) = nil) + def initialize(name, source, @args : Arguments? = nil) super(name, source) end diff --git a/src/spectator/mocks/nil_method_stub.cr b/src/spectator/mocks/nil_method_stub.cr index 0bfe4d7..64e10bb 100644 --- a/src/spectator/mocks/nil_method_stub.cr +++ b/src/spectator/mocks/nil_method_stub.cr @@ -3,7 +3,7 @@ require "./generic_method_stub" require "./value_method_stub" module Spectator::Mocks - class NilMethodStub < GenericMethodStub(Nil, Tuple, NamedTuple) + class NilMethodStub < GenericMethodStub(Nil) def call(_args : GenericArguments(T, NT), _rt : RT.class) forall T, NT, RT nil end diff --git a/src/spectator/mocks/proc_method_stub.cr b/src/spectator/mocks/proc_method_stub.cr index f4a9603..b0d921f 100644 --- a/src/spectator/mocks/proc_method_stub.cr +++ b/src/spectator/mocks/proc_method_stub.cr @@ -2,7 +2,7 @@ require "./arguments" require "./generic_method_stub" module Spectator::Mocks - class ProcMethodStub(ReturnType, T, NT) < GenericMethodStub(ReturnType, T, NT) + class ProcMethodStub(ReturnType) < GenericMethodStub(ReturnType) def initialize(name, source, @proc : -> ReturnType, args = nil) super(name, source, args) end diff --git a/src/spectator/mocks/value_method_stub.cr b/src/spectator/mocks/value_method_stub.cr index f55ea49..6cdec7b 100644 --- a/src/spectator/mocks/value_method_stub.cr +++ b/src/spectator/mocks/value_method_stub.cr @@ -2,7 +2,7 @@ require "./generic_arguments" require "./generic_method_stub" module Spectator::Mocks - class ValueMethodStub(ReturnType, T, NT) < GenericMethodStub(ReturnType, T, NT) + class ValueMethodStub(ReturnType) < GenericMethodStub(ReturnType) def initialize(name, source, @value : ReturnType, args = nil) super(name, source, args) end