mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add initial support for exect-receive syntax
This commit is contained in:
parent
3d7655a5d1
commit
c91e288f61
2 changed files with 128 additions and 0 deletions
|
@ -99,6 +99,14 @@ module Spectator
|
|||
def initialize(@expression : Expression(T), @location : Location)
|
||||
end
|
||||
|
||||
# Asserts that a method is called some point before the example completes.
|
||||
@[AlwaysInline]
|
||||
def to(stub : Stub, message = nil) : Nil
|
||||
{% raise "The syntax `expect(...).to receive(...)` requires the expression passed to `expect` be stubbable (a mock or double)" unless T < ::Spectator::Stubbable || T < ::Spectator::StubbedType %}
|
||||
|
||||
to_eventually(stub, message)
|
||||
end
|
||||
|
||||
# Asserts that some criteria defined by the matcher is satisfied.
|
||||
# Allows a custom message to be used.
|
||||
def to(matcher, message = nil) : Nil
|
||||
|
@ -106,6 +114,20 @@ module Spectator
|
|||
report(match_data, message)
|
||||
end
|
||||
|
||||
# Asserts that a method is not called before the example completes.
|
||||
@[AlwaysInline]
|
||||
def to_not(stub : Stub, message = nil) : Nil
|
||||
{% raise "The syntax `expect(...).to_not receive(...)` requires the expression passed to `expect` be stubbable (a mock or double)" unless T < ::Spectator::Stubbable || T < ::Spectator::StubbedType %}
|
||||
|
||||
to_never(stub, message)
|
||||
end
|
||||
|
||||
# :ditto:
|
||||
@[AlwaysInline]
|
||||
def not_to(stub : Stub, message = nil) : Nil
|
||||
to_not(stub, message)
|
||||
end
|
||||
|
||||
# Asserts that some criteria defined by the matcher is not satisfied.
|
||||
# This is effectively the opposite of `#to`.
|
||||
# Allows a custom message to be used.
|
||||
|
@ -120,6 +142,16 @@ module Spectator
|
|||
to_not(matcher, message)
|
||||
end
|
||||
|
||||
# Asserts that a method is called some point before the example completes.
|
||||
def to_eventually(stub : Stub, message = nil) : Nil
|
||||
{% raise "The syntax `expect(...).to_eventually receive(...)` requires the expression passed to `expect` be stubbable (a mock or double)" unless T < ::Spectator::Stubbable || T < ::Spectator::StubbedType %}
|
||||
|
||||
stubbable = @expression.value
|
||||
stubbable._spectator_define_stub(stub)
|
||||
matcher = Matchers::ReceiveMatcher.new(stub)
|
||||
to_eventually(matcher, message)
|
||||
end
|
||||
|
||||
# Asserts that some criteria defined by the matcher is eventually satisfied.
|
||||
# The expectation is checked after the example finishes and all hooks have run.
|
||||
# Allows a custom message to be used.
|
||||
|
@ -127,6 +159,22 @@ module Spectator
|
|||
Harness.current.defer { to(matcher, message) }
|
||||
end
|
||||
|
||||
# Asserts that a method is not called before the example completes.
|
||||
def to_never(stub : Stub, message = nil) : Nil
|
||||
{% raise "The syntax `expect(...).to_never receive(...)` requires the expression passed to `expect` be stubbable (a mock or double)" unless T < ::Spectator::Stubbable || T < ::Spectator::StubbedType %}
|
||||
|
||||
stubbable = @expression.value
|
||||
stubbable._spectator_define_stub(stub)
|
||||
matcher = Matchers::ReceiveMatcher.new(stub)
|
||||
to_never(matcher, message)
|
||||
end
|
||||
|
||||
# :ditto:
|
||||
@[AlwaysInline]
|
||||
def never_to(stub : Stub, message = nil) : Nil
|
||||
to_never(stub, message)
|
||||
end
|
||||
|
||||
# Asserts that some criteria defined by the matcher is never satisfied.
|
||||
# The expectation is checked after the example finishes and all hooks have run.
|
||||
# Allows a custom message to be used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue