Test value types

This commit is contained in:
Michael Miller 2021-02-09 22:50:21 -07:00
parent 8b5fd099bb
commit 35946dc993
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 97 additions and 0 deletions

View 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