mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow specifying receive count
Updated checks and failure output to support this.
This commit is contained in:
parent
b107511c9e
commit
2048267eef
1 changed files with 10 additions and 4 deletions
|
@ -3,7 +3,7 @@ require "./standard_matcher"
|
||||||
|
|
||||||
module Spectator::Matchers
|
module Spectator::Matchers
|
||||||
struct ReceiveMatcher < StandardMatcher
|
struct ReceiveMatcher < StandardMatcher
|
||||||
def initialize(@expected : TestExpression(Symbol))
|
def initialize(@expected : TestExpression(Symbol), @count : Int32? = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def description : String
|
def description : String
|
||||||
|
@ -13,7 +13,11 @@ module Spectator::Matchers
|
||||||
def match?(actual : TestExpression(T)) : Bool forall T
|
def match?(actual : TestExpression(T)) : Bool forall T
|
||||||
double = actual.value.as(Mocks::Double)
|
double = actual.value.as(Mocks::Double)
|
||||||
calls = double.spectator_stub_calls(@expected.value)
|
calls = double.spectator_stub_calls(@expected.value)
|
||||||
!calls.empty?
|
if (count = @count)
|
||||||
|
count == calls.size
|
||||||
|
else
|
||||||
|
!calls.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_message(actual : TestExpression(T)) : String forall T
|
def failure_message(actual : TestExpression(T)) : String forall T
|
||||||
|
@ -21,9 +25,11 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
|
|
||||||
def values(actual : TestExpression(T)) forall T
|
def values(actual : TestExpression(T)) forall T
|
||||||
|
double = actual.value.as(Mocks::Double)
|
||||||
|
calls = double.spectator_stub_calls(@expected.value)
|
||||||
{
|
{
|
||||||
expected: "1 time with any arguments",
|
expected: "#{@count ? "#{@count} time(s)" : "At least once"} with any arguments",
|
||||||
received: "0 times with any arguments",
|
received: "#{calls.size} time(s) with any arguments",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue