Workaround for generic argument type issue

This commit is contained in:
Michael Miller 2019-11-15 21:18:51 -07:00
parent 2dc86c05ac
commit 3c94d1f8fd
6 changed files with 18 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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