Use harness' cleanup instead of defer

This commit is contained in:
Michael Miller 2022-10-09 15:32:32 -06:00
parent 5c910e5a85
commit e9d3f31ac3
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -164,13 +164,11 @@ module Spectator
stubbable._spectator_define_stub(stub)
# Check if the stub was invoked after the test completes.
Harness.current.defer do
matcher = Matchers::ReceiveMatcher.new(stub)
to(matcher, message)
ensure
Harness.current.defer { to(matcher, message) }
# Prevent leaking stubs between tests.
stubbable._spectator_remove_stub(stub)
end
Harness.current.cleanup { stubbable._spectator_remove_stub(stub) }
end
# Asserts that some criteria defined by the matcher is eventually satisfied.
@ -202,13 +200,11 @@ module Spectator
stubbable._spectator_define_stub(stub)
# Check if the stub was invoked after the test completes.
Harness.current.defer do
matcher = Matchers::ReceiveMatcher.new(stub)
to_not(matcher, message)
ensure
Harness.current.defer { to_not(matcher, message) }
# Prevent leaking stubs between tests.
stubbable._spectator_remove_stub(stub)
end
Harness.current.cleanup { stubbable._spectator_remove_stub(stub) }
end
# :ditto: