Add tests around problematic issues in NullDouble to Double

This commit is contained in:
Michael Miller 2022-03-16 21:10:47 -06:00
parent 280f117e23
commit b68c75dda5
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2

View file

@ -50,6 +50,30 @@ Spectator.describe Spectator::Double do
end end
end end
context "with abstract stubs and return type annotations" do
Spectator::Double.define(TestDouble) do
abstract_stub abstract def foo(value) : String
end
let(arguments) { Spectator::Arguments.capture(/foo/) }
let(stub) { Spectator::ValueStub.new(:foo, "bar", arguments).as(Spectator::Stub) }
subject(dbl) { TestDouble.new([stub]) }
it "enforces the return type" do
expect(dbl.foo("foobar")).to compile_as(String)
end
it "raises on non-matching arguments" do
expect { dbl.foo("bar") }.to raise_error(Spectator::UnexpectedMessage, /foo/)
end
it "raises on non-matching stub" do
stub = Spectator::ValueStub.new(:foo, 42, arguments).as(Spectator::Stub)
dbl._spectator_define_stub(stub)
expect { dbl.foo("foobar") }.to raise_error(TypeCastError, /String/)
end
end
context "with nillable return type annotations" do context "with nillable return type annotations" do
Spectator::Double.define(TestDouble) do Spectator::Double.define(TestDouble) do
abstract_stub abstract def foo : String? abstract_stub abstract def foo : String?