mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add initial support for exect-receive syntax
This commit is contained in:
parent
3d7655a5d1
commit
c91e288f61
2 changed files with 128 additions and 0 deletions
80
spec/spectator/dsl/mocks/expect_receive_spec.cr
Normal file
80
spec/spectator/dsl/mocks/expect_receive_spec.cr
Normal file
|
@ -0,0 +1,80 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
Spectator.describe "Deferred stub expectation DSL" do
|
||||
context "with a double" do
|
||||
double(:dbl) do
|
||||
# Ensure the original is never called.
|
||||
stub abstract def foo : Nil
|
||||
stub abstract def foo(arg) : Nil
|
||||
end
|
||||
|
||||
let(dbl) { double(:dbl) }
|
||||
|
||||
it "matches when a message is received" do
|
||||
expect(dbl).to receive(:foo)
|
||||
dbl.foo
|
||||
end
|
||||
|
||||
it "matches when a message isn't received" do
|
||||
expect(dbl).to_not receive(:foo)
|
||||
end
|
||||
|
||||
it "matches when a message is received with matching arguments" do
|
||||
expect(dbl).to receive(:foo).with(:bar)
|
||||
dbl.foo(:bar)
|
||||
end
|
||||
|
||||
it "matches when a message without arguments is received" do
|
||||
expect(dbl).to_not receive(:foo).with(:bar)
|
||||
dbl.foo
|
||||
end
|
||||
|
||||
it "matches when a message without arguments isn't received" do
|
||||
expect(dbl).to_not receive(:foo).with(:bar)
|
||||
end
|
||||
|
||||
it "matches when a message with arguments isn't received" do
|
||||
expect(dbl).to_not receive(:foo).with(:baz)
|
||||
dbl.foo(:bar)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a mock" do
|
||||
abstract class MyClass
|
||||
abstract def foo : Int32
|
||||
abstract def foo(arg) : Int32
|
||||
end
|
||||
|
||||
mock(MyClass)
|
||||
|
||||
let(fake) { mock(MyClass) }
|
||||
|
||||
it "matches when a message is received" do
|
||||
expect(fake).to receive(:foo).and_return(42)
|
||||
fake.foo(:bar)
|
||||
end
|
||||
|
||||
it "matches when a message isn't received" do
|
||||
expect(fake).to_not receive(:foo)
|
||||
end
|
||||
|
||||
it "matches when a message is received with matching arguments" do
|
||||
expect(fake).to receive(:foo).with(:bar).and_return(42)
|
||||
fake.foo(:bar)
|
||||
end
|
||||
|
||||
it "matches when a message without arguments is received" do
|
||||
expect(fake).to_not receive(:foo).with(:bar)
|
||||
fake.foo
|
||||
end
|
||||
|
||||
it "matches when a message without arguments is received" do
|
||||
expect(fake).to_not receive(:foo).with(:bar)
|
||||
end
|
||||
|
||||
it "matches when a message with arguments isn't received" do
|
||||
expect(fake).to_not receive(:foo).with(:baz).and_return(42)
|
||||
fake.foo(:bar)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue