From 6531140f068f639f17b385d9671e36b836643adc Mon Sep 17 00:00:00 2001 From: strcmp <28xdb6+fvutuvy4f@grr.la> Date: Thu, 31 Dec 2015 15:25:33 -0800 Subject: [PATCH] add tests --- spec/config/behavior_spec.rb | 16 ++++++++++++++++ spec/config/lazy_spec.rb | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 spec/config/behavior_spec.rb diff --git a/spec/config/behavior_spec.rb b/spec/config/behavior_spec.rb new file mode 100644 index 00000000..5f62991f --- /dev/null +++ b/spec/config/behavior_spec.rb @@ -0,0 +1,16 @@ +require 'helper' +RSpec.describe Pry::Config::Behavior do + let(:behavior) do + Class.new do + include Pry::Config::Behavior + end + end + + describe "#last_default" do + it "returns the last default in a list of defaults" do + last = behavior.from_hash({}, nil) + middle = behavior.from_hash({}, last) + expect(behavior.from_hash({}, middle).last_default).to be(last) + end + end +end diff --git a/spec/config/lazy_spec.rb b/spec/config/lazy_spec.rb index 7f512333..69884f20 100644 --- a/spec/config/lazy_spec.rb +++ b/spec/config/lazy_spec.rb @@ -1,13 +1,22 @@ require 'helper' RSpec.describe Pry::Config::Lazy do - let(:lazyobject) do + let(:lazyobj) do Class.new do include Pry::Config::Lazy - lazy_implement({foo: proc {"bar"}}) + lazy_implement({foo: proc {"foo"}, bar: proc {"bar"}}) end.new end - it 'memorizes value after first call' do - expect(lazyobject.foo).to equal(lazyobject.foo) + describe "on call of a lazy method" do + it "memoizes the return value" do + expect(lazyobj.foo).to be(lazyobj.foo) + end + end + + describe "#lazy_keys" do + it "tracks a list of lazy keys" do + lazyobj.foo # at least one lazy method has to be called before #lazy_keys could return a non-empty array. + expect(lazyobj.lazy_keys).to eq([:foo, :bar]) + end end end