require "spec_helper"

describe Mem do
  describe "#memoize" do
    let(:klass) do
      Class.new do
        extend Mem

        def foo(&block)
          bar(&block)
        end
        memoize :foo

        def bar
          yield
        end
      end
    end

    let(:object) do
      klass.new
    end

    it "memoizes the result of specified method call" do
      expect(object).to receive(:bar).once.and_call_original
      expect(object.foo { "foo" }).to eq "foo"
    end
  end
end

require "spec_helper"

describe Mem do
  describe "#memoize" do
    let(:klass) do
      Class.new do
        extend Mem

        def foo(&block)
          bar(&block)
        end
        memoize :foo

        def bar
          yield
        end
      end
    end

    let(:object) do
      klass.new
    end

    it "memoizes the result of specified method call" do
      expect(object).to receive(:bar).once.and_call_original
      expect(object.foo { "foo" }).to eq "foo"
      expect(object.foo { "baz" }).to eq "foo"
    end
  end
end

Fix spec to call a method twice
Fix spec to call a method twice

To make sure that a method is memoized, I think the method should
be called twice under conditions where it normally returns a
different value.

Otherwise, we can't know if the result is memoized or the original
method is invoked every time.
