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
1 changed files with 24 additions and 0 deletions

View File

@ -50,6 +50,30 @@ Spectator.describe Spectator::Double do
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
Spectator::Double.define(TestDouble) do
abstract_stub abstract def foo : String?