From 3fa6baea4df550cf58d1f950bb66d3a59f1e3cf5 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 19 Mar 2022 12:52:23 -0600 Subject: [PATCH] Test mixing block and keyword stubs --- spec/spectator/dsl/mocks/double_spec.cr | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/spectator/dsl/mocks/double_spec.cr b/spec/spectator/dsl/mocks/double_spec.cr index dffa476..a61173e 100644 --- a/spec/spectator/dsl/mocks/double_spec.cr +++ b/spec/spectator/dsl/mocks/double_spec.cr @@ -105,6 +105,44 @@ Spectator.describe "Double DSL" do expect(dbl.foo).to eq("no stub") end end + + context "mixing keyword arguments" do + double(:test6, foo: "kwargs", bar: 42) do + stub def foo + "block" + end + + stub def baz + "block" + end + + stub def baz(value) + "block2" + end + end + + subject(dbl) { double(:test6) } + + it "overrides the keyword arguments with the block methods" do + expect(dbl.foo).to eq("block") + end + + it "falls back to the keyword argument value for mismatched arguments" do + expect(dbl.foo(42)).to eq("kwargs") + end + + it "can call methods defined only by keyword arguments" do + expect(dbl.bar).to eq(42) + end + + it "can call methods defined only by the block" do + expect(dbl.baz).to eq("block") + end + + it "can call methods defined by the block with different signatures" do + expect(dbl.baz(42)).to eq("block2") + end + end end describe "double naming" do