From 6cc6e55f205c421ca6ca010a8afcafc3ed7dc299 Mon Sep 17 00:00:00 2001 From: Josh Cheek Date: Mon, 3 Jun 2019 03:09:31 -0500 Subject: MemoizedValue memoizes nil results (#2053) I moved the existing `subject` into the test because it didn't make sense for the second test I added. --- spec/config/memoized_value_spec.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/config/memoized_value_spec.rb b/spec/config/memoized_value_spec.rb index 22e278dc..9b8ab864 100644 --- a/spec/config/memoized_value_spec.rb +++ b/spec/config/memoized_value_spec.rb @@ -2,10 +2,20 @@ RSpec.describe Pry::Config::MemoizedValue do describe "#call" do - subject { described_class.new { rand } } - it "memoizes the result of call" do - expect(subject.call).to eq(subject.call) + instance = described_class.new { rand } + expect(instance.call).to eq(instance.call) + end + + it "doesn't conflate falsiness with unmemoizedness" do + count = 0 + instance = described_class.new do + count += 1 + nil + end + expect(instance.call).to eq nil + expect(instance.call).to eq nil + expect(count).to eq 1 end end end -- cgit v1.2.1