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) stubbable._spectator_define_stub(stub)
# Check if the stub was invoked after the test completes. # Check if the stub was invoked after the test completes.
Harness.current.defer do matcher = Matchers::ReceiveMatcher.new(stub)
matcher = Matchers::ReceiveMatcher.new(stub) Harness.current.defer { to(matcher, message) }
to(matcher, message)
ensure # Prevent leaking stubs between tests.
# Prevent leaking stubs between tests. Harness.current.cleanup { stubbable._spectator_remove_stub(stub) }
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.
@ -202,13 +200,11 @@ module Spectator
stubbable._spectator_define_stub(stub) stubbable._spectator_define_stub(stub)
# Check if the stub was invoked after the test completes. # Check if the stub was invoked after the test completes.
Harness.current.defer do matcher = Matchers::ReceiveMatcher.new(stub)
matcher = Matchers::ReceiveMatcher.new(stub) Harness.current.defer { to_not(matcher, message) }
to_not(matcher, message)
ensure # Prevent leaking stubs between tests.
# Prevent leaking stubs between tests. Harness.current.cleanup { stubbable._spectator_remove_stub(stub) }
stubbable._spectator_remove_stub(stub)
end
end end
# :ditto: # :ditto: