mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Test handling of blocks in doubles
This commit is contained in:
parent
043ebd818f
commit
0c7f72dc78
4 changed files with 154 additions and 2 deletions
|
@ -39,8 +39,26 @@ Spectator.describe Spectator::Double do
|
|||
expect { dbl.baz }.to compile_as(Nil)
|
||||
end
|
||||
|
||||
it "supports blocks" do
|
||||
dbl.bar
|
||||
context "blocks" do
|
||||
it "supports blocks" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq(42)
|
||||
expect(dbl.bar { nil }).to eq("baz")
|
||||
end
|
||||
end
|
||||
|
||||
it "supports blocks and has non-union return types" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to compile_as(Int32)
|
||||
expect(dbl.bar { nil }).to compile_as(String)
|
||||
end
|
||||
end
|
||||
|
||||
it "fails on undefined messages" do
|
||||
expect do
|
||||
dbl.baz { nil }
|
||||
end.to raise_error(Spectator::UnexpectedMessage, /baz/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -208,6 +226,7 @@ Spectator.describe Spectator::Double do
|
|||
context "without common object methods" do
|
||||
Spectator::Double.define(TestDouble) do
|
||||
abstract_stub abstract def foo(value) : String
|
||||
abstract_stub abstract def foo(value, & : -> _) : String
|
||||
end
|
||||
|
||||
let(stub) { Spectator::ValueStub.new(:foo, "bar", arguments).as(Spectator::Stub) }
|
||||
|
@ -228,6 +247,10 @@ Spectator.describe Spectator::Double do
|
|||
it "has a non-union return type" do
|
||||
expect(dbl.foo("foobar")).to compile_as(String)
|
||||
end
|
||||
|
||||
it "ignores the block argument if not in the constraint" do
|
||||
expect(dbl.foo("foobar") { nil }).to eq("bar")
|
||||
end
|
||||
end
|
||||
|
||||
context "with common object methods" do
|
||||
|
@ -291,5 +314,14 @@ Spectator.describe Spectator::Double do
|
|||
expect(dbl.foo(:lucky)).to eq(7)
|
||||
end
|
||||
end
|
||||
|
||||
it "ignores the block argument if not in the constraint" do
|
||||
dbl._spectator_define_stub(stub5)
|
||||
dbl._spectator_define_stub(stub7)
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq(5)
|
||||
expect(dbl.foo(:lucky) { nil }).to eq(7)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,26 @@ Spectator.describe Spectator::NullDouble do
|
|||
expect(dbl.bar).to compile_as(String)
|
||||
end
|
||||
end
|
||||
|
||||
context "blocks" do
|
||||
it "supports blocks" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq(42)
|
||||
expect(dbl.bar { nil }).to eq("baz")
|
||||
end
|
||||
end
|
||||
|
||||
it "supports blocks and has non-union return types" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to compile_as(Int32)
|
||||
expect(dbl.bar { nil }).to compile_as(String)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns self on undefined messages" do
|
||||
expect_null_double(dbl, dbl.baz { nil })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with abstract stubs and return type annotations" do
|
||||
|
@ -168,6 +188,7 @@ Spectator.describe Spectator::NullDouble do
|
|||
context "without common object methods" do
|
||||
Spectator::NullDouble.define(TestDouble) do
|
||||
abstract_stub abstract def foo(value)
|
||||
abstract_stub abstract def foo(value, & : -> _)
|
||||
end
|
||||
|
||||
let(stub) { Spectator::ValueStub.new(:foo, "bar", arguments).as(Spectator::Stub) }
|
||||
|
@ -184,6 +205,10 @@ Spectator.describe Spectator::NullDouble do
|
|||
it "returns self when argument count doesn't match" do
|
||||
expect_null_double(dbl, dbl.foo)
|
||||
end
|
||||
|
||||
it "ignores the block argument if not in the constraint" do
|
||||
expect(dbl.foo("foobar") { nil }).to eq("bar")
|
||||
end
|
||||
end
|
||||
|
||||
context "with common object methods" do
|
||||
|
@ -243,5 +268,14 @@ Spectator.describe Spectator::NullDouble do
|
|||
expect(dbl.foo(:lucky)).to eq(7)
|
||||
end
|
||||
end
|
||||
|
||||
it "ignores the block argument if not in the constraint" do
|
||||
dbl._spectator_define_stub(stub5)
|
||||
dbl._spectator_define_stub(stub7)
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq(5)
|
||||
expect(dbl.foo(:lucky) { nil }).to eq(7)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue