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
|
||||
struct ReceiveMatcher < StandardMatcher
|
||||
def initialize(@expected : TestExpression(Symbol))
|
||||
def initialize(@expected : TestExpression(Symbol), @count : Int32? = nil)
|
||||
end
|
||||
|
||||
def description : String
|
||||
|
@ -13,17 +13,23 @@ module Spectator::Matchers
|
|||
def match?(actual : TestExpression(T)) : Bool forall T
|
||||
double = actual.value.as(Mocks::Double)
|
||||
calls = double.spectator_stub_calls(@expected.value)
|
||||
if (count = @count)
|
||||
count == calls.size
|
||||
else
|
||||
!calls.empty?
|
||||
end
|
||||
end
|
||||
|
||||
def failure_message(actual : TestExpression(T)) : String forall T
|
||||
"#{actual.label} did not receive #{@expected.label}"
|
||||
end
|
||||
|
||||
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",
|
||||
received: "0 times with any arguments",
|
||||
expected: "#{@count ? "#{@count} time(s)" : "At least once"} with any arguments",
|
||||
received: "#{calls.size} time(s) with any arguments",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue