mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Workaround for generic argument type issue
This commit is contained in:
parent
2dc86c05ac
commit
3c94d1f8fd
6 changed files with 18 additions and 12 deletions
|
@ -24,10 +24,10 @@ module Spectator::Expectations
|
||||||
report(match_data)
|
report(match_data)
|
||||||
end
|
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)
|
value = TestValue.new(stub.name, stub.to_s)
|
||||||
matcher = if stub.arguments?
|
matcher = if (arguments = stub.arguments?)
|
||||||
Matchers::ReceiveArgumentsMatcher.new(value, stub.arguments)
|
Matchers::ReceiveArgumentsMatcher.new(value, arguments)
|
||||||
else
|
else
|
||||||
Matchers::ReceiveMatcher.new(value)
|
Matchers::ReceiveMatcher.new(value)
|
||||||
end
|
end
|
||||||
|
@ -42,7 +42,13 @@ module Spectator::Expectations
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_not(stub : Mocks::MethodStub) : Nil
|
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
|
end
|
||||||
|
|
||||||
# ditto
|
# ditto
|
||||||
|
|
|
@ -2,10 +2,10 @@ require "../mocks"
|
||||||
require "./standard_matcher"
|
require "./standard_matcher"
|
||||||
|
|
||||||
module Spectator::Matchers
|
module Spectator::Matchers
|
||||||
struct ReceiveArgumentsMatcher(T, NT) < StandardMatcher
|
struct ReceiveArgumentsMatcher < StandardMatcher
|
||||||
alias Range = ::Range(Int32, Int32) | ::Range(Nil, Int32) | ::Range(Int32, Nil)
|
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
|
end
|
||||||
|
|
||||||
def description : String
|
def description : String
|
||||||
|
|
|
@ -4,10 +4,10 @@ require "./method_call"
|
||||||
require "./method_stub"
|
require "./method_stub"
|
||||||
|
|
||||||
module Spectator::Mocks
|
module Spectator::Mocks
|
||||||
abstract class GenericMethodStub(ReturnType, T, NT) < MethodStub
|
abstract class GenericMethodStub(ReturnType) < MethodStub
|
||||||
getter! arguments : GenericArguments(T, NT)
|
getter! arguments : Arguments
|
||||||
|
|
||||||
def initialize(name, source, @args : GenericArguments(T, NT) = nil)
|
def initialize(name, source, @args : Arguments? = nil)
|
||||||
super(name, source)
|
super(name, source)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "./generic_method_stub"
|
||||||
require "./value_method_stub"
|
require "./value_method_stub"
|
||||||
|
|
||||||
module Spectator::Mocks
|
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
|
def call(_args : GenericArguments(T, NT), _rt : RT.class) forall T, NT, RT
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "./arguments"
|
||||||
require "./generic_method_stub"
|
require "./generic_method_stub"
|
||||||
|
|
||||||
module Spectator::Mocks
|
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)
|
def initialize(name, source, @proc : -> ReturnType, args = nil)
|
||||||
super(name, source, args)
|
super(name, source, args)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "./generic_arguments"
|
||||||
require "./generic_method_stub"
|
require "./generic_method_stub"
|
||||||
|
|
||||||
module Spectator::Mocks
|
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)
|
def initialize(name, source, @value : ReturnType, args = nil)
|
||||||
super(name, source, args)
|
super(name, source, args)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue