shard-spectator/spec/spectator/lazy_spec.cr

16 lines
416 B
Crystal
Raw Normal View History

2021-02-13 20:30:05 +00:00
require "../spec_helper"
Spectator.describe Spectator::Lazy do
it "returns the value of the block" do
2021-02-14 00:33:52 +00:00
lazy = Spectator::Lazy(Int32).new
expect { lazy.get { 42 } }.to eq(42)
2021-02-13 20:30:05 +00:00
end
it "caches the value" do
2021-02-14 00:33:52 +00:00
lazy = Spectator::Lazy(Int32).new
2021-02-13 20:30:05 +00:00
count = 0
2021-02-14 00:33:52 +00:00
expect { lazy.get { count += 1 } }.to change { count }.from(0).to(1)
expect { lazy.get { count += 1 } }.to_not change { count }
2021-02-13 20:30:05 +00:00
end
end