mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Test value types
This commit is contained in:
parent
8b5fd099bb
commit
35946dc993
3 changed files with 97 additions and 0 deletions
28
spec/spectator/lazy_wrapper_spec.cr
Normal file
28
spec/spectator/lazy_wrapper_spec.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
require "../spec_helper"
|
||||
|
||||
Spectator.describe Spectator::LazyWrapper do
|
||||
it "returns the value of the block" do
|
||||
expect { subject.get { 42 } }.to eq(42)
|
||||
end
|
||||
|
||||
it "caches the value" do
|
||||
wrapper = described_class.new
|
||||
count = 0
|
||||
expect { wrapper.get { count += 1 } }.to change { count }.from(0).to(1)
|
||||
expect { wrapper.get { count += 1 } }.to_not change { count }
|
||||
end
|
||||
|
||||
# This type of nesting is used when `super` is called in a subject block.
|
||||
# ```
|
||||
# subject { super.to_s }
|
||||
# ```
|
||||
it "works with nested wrappers" do
|
||||
outer = described_class.new
|
||||
inner = described_class.new
|
||||
value = outer.get do
|
||||
inner.get { 42 }.to_s
|
||||
end
|
||||
expect(value).to eq("42")
|
||||
expect(value).to be_a(String)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue