Ensure stubs defined with allow syntax are cleared

This commit is contained in:
Michael Miller 2022-10-09 15:48:00 -06:00
parent 2516803b0d
commit 090c95b162
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 29 additions and 0 deletions

View file

@ -9,5 +9,31 @@ Spectator.describe Spectator::Allow do
it "applies a stub" do
expect { alw.to(stub) }.to change { dbl.foo }.from(42).to(123)
end
context "leak" do
class Thing
def foo
42
end
end
mock Thing
getter(thing : Thing) { mock(Thing) }
# Workaround type restrictions requiring a constant.
def fake
class_mock(Thing).cast(thing)
end
specify do
expect { allow(fake).to(stub) }.to change { fake.foo }.from(42).to(123)
end
# This example must be run after the previous (random order may break this).
it "clears the stub after the example completes" do
expect { fake.foo }.to eq(42)
end
end
end
end