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
|
@ -32,6 +32,28 @@ Spectator.describe "Double DSL" do
|
|||
expect { dbl.baz(:xyz, 123, a: "XYZ") }.to raise_error(Spectator::UnexpectedMessage, /\(:xyz, 123, a: "XYZ"\)/)
|
||||
end
|
||||
end
|
||||
|
||||
context "blocks" do
|
||||
it "supports blocks" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq("foobar")
|
||||
expect(dbl.bar { nil }).to eq(42)
|
||||
end
|
||||
end
|
||||
|
||||
it "supports blocks and has non-union return types" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to compile_as(String)
|
||||
expect(dbl.bar { nil }).to compile_as(Int32)
|
||||
end
|
||||
end
|
||||
|
||||
it "fails on undefined messages" do
|
||||
expect do
|
||||
dbl.baz { nil }
|
||||
end.to raise_error(Spectator::UnexpectedMessage, /baz/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "block with stubs" do
|
||||
|
@ -143,6 +165,28 @@ Spectator.describe "Double DSL" do
|
|||
expect(dbl.baz(42)).to eq("block2")
|
||||
end
|
||||
end
|
||||
|
||||
context "methods accepting blocks" do
|
||||
double(:test7) do
|
||||
stub def foo
|
||||
yield
|
||||
end
|
||||
|
||||
stub def bar(& : Int32 -> String)
|
||||
yield 42
|
||||
end
|
||||
end
|
||||
|
||||
subject(dbl) { double(:test7) }
|
||||
|
||||
it "defines the method and yields" do
|
||||
expect(dbl.foo { :xyz }).to eq(:xyz)
|
||||
end
|
||||
|
||||
it "matches methods with block argument type restrictions" do
|
||||
expect(dbl.bar &.to_s).to eq("42")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "double naming" do
|
||||
|
|
|
@ -28,6 +28,26 @@ Spectator.describe "Null double DSL" do
|
|||
it "returns self for unexpected messages" do
|
||||
expect_null_double(dbl, dbl.baz)
|
||||
end
|
||||
|
||||
context "blocks" do
|
||||
it "supports blocks" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to eq("foobar")
|
||||
expect(dbl.bar { nil }).to eq(42)
|
||||
end
|
||||
end
|
||||
|
||||
it "supports blocks and has non-union return types" do
|
||||
aggregate_failures do
|
||||
expect(dbl.foo { nil }).to compile_as(String)
|
||||
expect(dbl.bar { nil }).to compile_as(Int32)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns self on undefined messages" do
|
||||
expect_null_double(dbl, dbl.baz { nil })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "block with stubs" do
|
||||
|
@ -139,5 +159,27 @@ Spectator.describe "Null double DSL" do
|
|||
expect(dbl.baz(42)).to eq("block2")
|
||||
end
|
||||
end
|
||||
|
||||
context "methods accepting blocks" do
|
||||
double(:test7) do
|
||||
stub def foo
|
||||
yield
|
||||
end
|
||||
|
||||
stub def bar(& : Int32 -> String)
|
||||
yield 42
|
||||
end
|
||||
end
|
||||
|
||||
subject(dbl) { double(:test7).as_null_object }
|
||||
|
||||
it "defines the method and yields" do
|
||||
expect(dbl.foo { :xyz }).to eq(:xyz)
|
||||
end
|
||||
|
||||
it "matches methods with block argument type restrictions" do
|
||||
expect(dbl.bar &.to_s).to eq("42")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue