Add return type restriction

This overrides the previous definition which doesn't have a restriction.
This is a workaround for the inability to infer a stub's return type.
This commit is contained in:
Michael Miller 2022-03-30 21:10:36 -06:00
parent b3f98cd50c
commit 231323bbf1
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
2 changed files with 7 additions and 6 deletions

View file

@ -210,15 +210,15 @@ Spectator.describe Spectator::NullDouble do
context "with common object methods" do
Spectator::NullDouble.define(TestDouble) do
@[Spectator::ReturnType(Crystal::Hasher)]
stub abstract def hash(hasher)
stub abstract def hash(hasher) : Crystal::Hasher
end
let(stub) { Spectator::ValueStub.new(:hash, 12345, arguments).as(Spectator::Stub) }
let(hasher) { Crystal::Hasher.new }
let(stub) { Spectator::ValueStub.new(:hash, hasher, arguments).as(Spectator::Stub) }
subject(dbl) { TestDouble.new([stub]) }
it "returns the response when constraint satisfied" do
expect(dbl.hash("foobar")).to eq(12345)
expect(dbl.hash("foobar")).to be(hasher)
end
it "raises when constraint unsatisfied" do