Use TypedStub instead of ValueStub

Test possible issues around stub returning nil
This commit is contained in:
Michael Miller 2022-03-16 21:07:20 -06:00
parent 8e38d3b054
commit 280f117e23
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
3 changed files with 64 additions and 7 deletions

View file

@ -50,6 +50,24 @@ Spectator.describe Spectator::Double do
end
end
context "with nillable return type annotations" do
Spectator::Double.define(TestDouble) do
abstract_stub abstract def foo : String?
abstract_stub abstract def bar : Nil
end
let(foo_stub) { Spectator::ValueStub.new(:foo, nil).as(Spectator::Stub) }
let(bar_stub) { Spectator::ValueStub.new(:bar, nil).as(Spectator::Stub) }
subject(dbl) { TestDouble.new([foo_stub, bar_stub]) }
it "doesn't raise on nil" do
aggregate_failures do
expect(dbl.foo).to be_nil
expect(dbl.bar).to be_nil
end
end
end
context "with common object methods" do
subject(dbl) do
EmptyDouble.new([

View file

@ -58,6 +58,24 @@ Spectator.describe Spectator::NullDouble do
end
end
context "with nillable return type annotations" do
Spectator::NullDouble.define(TestDouble) do
abstract_stub abstract def foo : String?
abstract_stub abstract def bar : Nil
end
let(foo_stub) { Spectator::ValueStub.new(:foo, nil).as(Spectator::Stub) }
let(bar_stub) { Spectator::ValueStub.new(:bar, nil).as(Spectator::Stub) }
subject(dbl) { TestDouble.new([foo_stub, bar_stub]) }
it "doesn't raise on nil" do
aggregate_failures do
expect(dbl.foo).to be_nil
expect(dbl.bar).to be_nil
end
end
end
context "with common object methods" do
subject(dbl) do
EmptyDouble.new([