Possible quirk with to_eventually?
to_eventually
seems to pass in all cases, yet I'm expecting (possibly mistakenly) that it should fail in two (noted below: triggers a notification eventually (should fail?)
).
class Subscriber
def call
puts "<-- subscriber notified. -->"
end
end
class Topic
def initialize(@subscribers = [] of Subscriber); end
def subscribe(subscriber : Subscriber)
@subscribers << subscriber
end
def sync_work
puts "<-- notifying #{@subscribers.size} subscribers. -->"
@subscribers.each(&.call)
end
def async_work
spawn do
puts "<-- notifying #{@subscribers.size} subscribers. -->"
@subscribers.each(&.call)
sleep 1
end
end
end
Spectator.describe Topic do
mock Subscriber do
stub call
end
let(:subscriber) { Subscriber.new }
subject(:topic) { described_class.new }
describe "#sync_work" do
subject(:sync_work) { topic.sync_work }
it "does not trigger a notification immediately" do
sync_work
expect(subscriber).not_to have_received(:call)
end
it "does not trigger a notification eventually" do
expect(subscriber).to_never receive(:call)
sync_work
end
it "triggers a notification eventually (should fail?)" do
expect(subscriber).to_eventually receive(:call)
sync_work
end
context "given a subscriber" do
before_each { topic.subscribe(subscriber) }
it "triggers a notification immediately" do
sync_work
expect(subscriber).to have_received(:call)
end
end
end
describe "#async_work" do
after_each { Fiber.yield }
subject(:async_work) { topic.async_work }
it "does not trigger a notification immediately" do
expect(subscriber).not_to receive(:call)
async_work
end
it "does not trigger a notification eventually" do
expect(subscriber).to_never receive(:call)
async_work
end
it "triggers a notification eventually (should fail?)" do
expect(subscriber).to_eventually receive(:call)
async_work
end
context "given a subscriber" do
before_each { topic.subscribe(subscriber) }
it "does not trigger a notification immediately" do
async_work
expect(subscriber).not_to have_received(:call)
end
it "triggers a notification eventually" do
expect(subscriber).to_eventually receive(:call)
async_work
end
end
end
end