2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-30 19:29:18 +02:00
|
|
|
require "lazy_object"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe LazyObject do
|
2018-07-30 19:29:18 +02:00
|
|
|
describe "#initialize" do
|
|
|
|
it "does not evaluate the block" do
|
2023-03-08 23:14:46 +00:00
|
|
|
expect do |block|
|
2018-07-30 19:29:18 +02:00
|
|
|
described_class.new(&block)
|
2023-03-08 23:14:46 +00:00
|
|
|
end.not_to yield_control
|
2018-07-30 19:29:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when receiving a message" do
|
|
|
|
it "evaluates the block" do
|
|
|
|
expect(described_class.new { 42 }.to_s).to eq "42"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#!" do
|
|
|
|
it "delegates to the underlying object" do
|
|
|
|
expect(!(described_class.new { false })).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#!=" do
|
|
|
|
it "delegates to the underlying object" do
|
|
|
|
expect(described_class.new { 42 }).not_to eq 13
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#==" do
|
|
|
|
it "delegates to the underlying object" do
|
|
|
|
expect(described_class.new { 42 }).to eq 42
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|