From f1ce914b73f9c778d6a5ca6b5c5b76613fdc8d21 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 2 Apr 2022 12:07:30 -0600 Subject: [PATCH] Better stub DSL tests --- spec/spectator/dsl/mocks/stub_spec.cr | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/spec/spectator/dsl/mocks/stub_spec.cr b/spec/spectator/dsl/mocks/stub_spec.cr index 250b705..586a1b9 100644 --- a/spec/spectator/dsl/mocks/stub_spec.cr +++ b/spec/spectator/dsl/mocks/stub_spec.cr @@ -1,11 +1,30 @@ require "../../../spec_helper" Spectator.describe "Stub DSL" do - double(:foobar, foo: 42, bar: "baz") + double(:foobar, foo: 42, bar: "baz") do + stub abstract def other : String + stub abstract def null : Nil + end + let(dbl) { double(:foobar) } - specify do + it "overrides default stubs" do allow(dbl).to receive(:foo).and_return(123) expect(dbl.foo).to eq(123) end + + it "overrides abstract stubs" do + allow(dbl).to receive(:other).and_return("test") + expect(dbl.other).to eq("test") + end + + it "returns nil by default" do + allow(dbl).to receive(:null) + expect(dbl.null).to be_nil + end + + it "raises on cast errors" do + allow(dbl).to receive(:foo).and_return(:xyz) + expect { dbl.foo }.to raise_error(TypeCastError, /Int32/) + end end