mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Better stub DSL tests
This commit is contained in:
parent
519836147e
commit
f1ce914b73
1 changed files with 21 additions and 2 deletions
|
@ -1,11 +1,30 @@
|
||||||
require "../../../spec_helper"
|
require "../../../spec_helper"
|
||||||
|
|
||||||
Spectator.describe "Stub DSL" do
|
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) }
|
let(dbl) { double(:foobar) }
|
||||||
|
|
||||||
specify do
|
it "overrides default stubs" do
|
||||||
allow(dbl).to receive(:foo).and_return(123)
|
allow(dbl).to receive(:foo).and_return(123)
|
||||||
expect(dbl.foo).to eq(123)
|
expect(dbl.foo).to eq(123)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue