Ensure stubs don't leak between examples

This commit is contained in:
Michael Miller 2022-10-09 16:59:39 -06:00
parent c6afa0adb3
commit b3aa2d62c0
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -14,6 +14,12 @@ Spectator.describe "Deferred stub expectation DSL" do
# Ensure invocations don't leak between examples.
pre_condition { expect(dbl).to_not have_received(:foo), "Leaked method calls from previous examples" }
# Ensure stubs don't leak between examples.
pre_condition do
expect { dbl.foo }.to raise_error(Spectator::UnexpectedMessage)
dbl._spectator_clear_calls # Don't include previous call in results.
end
it "matches when a message is received" do
expect(dbl).to receive(:foo)
dbl.foo
@ -67,6 +73,12 @@ Spectator.describe "Deferred stub expectation DSL" do
# Ensure invocations don't leak between examples.
pre_condition { expect(dbl).to_not have_received(:foo), "Leaked method calls from previous examples" }
# Ensure stubs don't leak between examples.
pre_condition do
expect { dbl.foo }.to raise_error(Spectator::UnexpectedMessage)
dbl._spectator_clear_calls # Don't include previous call in results.
end
it "matches when a message is received" do
expect(dbl).to receive(:foo)
dbl.foo
@ -114,6 +126,12 @@ Spectator.describe "Deferred stub expectation DSL" do
# Ensure invocations don't leak between examples.
pre_condition { expect(fake).to_not have_received(:foo), "Leaked method calls from previous examples" }
# Ensure stubs don't leak between examples.
pre_condition do
expect { fake.foo }.to raise_error(Spectator::UnexpectedMessage)
fake._spectator_clear_calls # Don't include previous call in results.
end
it "matches when a message is received" do
expect(fake).to receive(:foo).and_return(42)
fake.foo(:bar)
@ -166,6 +184,12 @@ Spectator.describe "Deferred stub expectation DSL" do
# Ensure invocations don't leak between examples.
pre_condition { expect(fake).to_not have_received(:foo), "Leaked method calls from previous examples" }
# Ensure stubs don't leak between examples.
pre_condition do
expect(fake.foo).to eq(42)
fake._spectator_clear_calls # Don't include previous call in results.
end
it "matches when a message is received" do
expect(fake).to receive(:foo).and_return(0)
fake.foo(:bar)