mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Clear stubs defined with expect().to receive()
syntax after test finishes
This commit is contained in:
parent
25b9931002
commit
5c910e5a85
3 changed files with 25 additions and 6 deletions
|
@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fixed
|
||||||
|
- Clear stubs defined with `expect().to receive()` syntax after test finishes to prevent leakage between tests.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Removed support for stubbing undefined (untyped) methods in lazy doubles. Avoids possible segfault.
|
- Removed support for stubbing undefined (untyped) methods in lazy doubles. Avoids possible segfault.
|
||||||
|
|
||||||
|
|
|
@ -146,9 +146,9 @@ Spectator.describe "Mocks Docs" do
|
||||||
inst.something
|
inst.something
|
||||||
end
|
end
|
||||||
|
|
||||||
it "leaks stubs to other examples" do
|
it "reverts to default stub for other examples" do
|
||||||
inst = mock(MyStruct)
|
inst = mock(MyStruct)
|
||||||
expect(inst.something).to eq(7) # Previous stub was leaked.
|
expect(inst.something).to eq(5) # Default stub used instead of original behavior.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -160,9 +160,17 @@ module Spectator
|
||||||
stubbable._spectator_define_stub(unconstrained_stub)
|
stubbable._spectator_define_stub(unconstrained_stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Apply the stub that is expected to be called.
|
||||||
stubbable._spectator_define_stub(stub)
|
stubbable._spectator_define_stub(stub)
|
||||||
matcher = Matchers::ReceiveMatcher.new(stub)
|
|
||||||
to_eventually(matcher, message)
|
# Check if the stub was invoked after the test completes.
|
||||||
|
Harness.current.defer do
|
||||||
|
matcher = Matchers::ReceiveMatcher.new(stub)
|
||||||
|
to(matcher, message)
|
||||||
|
ensure
|
||||||
|
# Prevent leaking stubs between tests.
|
||||||
|
stubbable._spectator_remove_stub(stub)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asserts that some criteria defined by the matcher is eventually satisfied.
|
# Asserts that some criteria defined by the matcher is eventually satisfied.
|
||||||
|
@ -190,9 +198,17 @@ module Spectator
|
||||||
stubbable._spectator_define_stub(unconstrained_stub)
|
stubbable._spectator_define_stub(unconstrained_stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Apply the stub that could be called in case it is.
|
||||||
stubbable._spectator_define_stub(stub)
|
stubbable._spectator_define_stub(stub)
|
||||||
matcher = Matchers::ReceiveMatcher.new(stub)
|
|
||||||
to_never(matcher, message)
|
# Check if the stub was invoked after the test completes.
|
||||||
|
Harness.current.defer do
|
||||||
|
matcher = Matchers::ReceiveMatcher.new(stub)
|
||||||
|
to_not(matcher, message)
|
||||||
|
ensure
|
||||||
|
# Prevent leaking stubs between tests.
|
||||||
|
stubbable._spectator_remove_stub(stub)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# :ditto:
|
# :ditto:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue