Initial implementation of have_received

This commit is contained in:
Michael Miller 2022-07-11 20:25:15 -06:00
parent 4f46c98a86
commit 694e2e6259
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,70 @@
require "../../../spec_helper"
Spectator.describe "Stubbable receiver DSL" do
context "with a double" do
double(:dbl, foo: 42)
let(dbl) { double(:dbl) }
it "matches when a message is received" do
dbl.foo
expect(dbl).to have_received(:foo)
end
it "matches when a message isn't received" do
expect(dbl).to_not have_received(:foo)
end
it "matches when a message is received with matching arguments" do
dbl.foo(:bar)
expect(dbl).to have_received(:foo).with(:bar)
end
it "matches when a message without arguments is received" do
dbl.foo
expect(dbl).to_not have_received(:foo).with(:bar)
end
it "matches when a message without arguments isn't received" do
expect(dbl).to_not have_received(:foo).with(:bar)
end
it "matches when a message with arguments isn't received" do
dbl.foo(:bar)
expect(dbl).to_not have_received(:foo).with(:baz)
end
end
context "with a mock" do
abstract class MyClass
abstract def foo(arg) : Int32
end
mock(MyClass, foo: 42)
let(fake) { mock(MyClass) }
it "matches when a message is received" do
fake.foo(:bar)
expect(fake).to have_received(:foo)
end
it "matches when a message isn't received" do
expect(fake).to_not have_received(:foo)
end
it "matches when a message is received with matching arguments" do
fake.foo(:bar)
expect(fake).to have_received(:foo).with(:bar)
end
it "matches when a message without arguments is received" do
expect(fake).to_not have_received(:foo).with(:bar)
end
it "matches when a message with arguments isn't received" do
fake.foo(:bar)
expect(fake).to_not have_received(:foo).with(:baz)
end
end
end