Sha256: 7e8c43249112b14f4568c0d83a27e74a8ab69ec21ac5ea434babbacfff443c1e

Contents?: true

Size: 858 Bytes

Versions: 5

Compression:

Stored size: 858 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Memoizable::ModuleMethods, '#unmemoized_instance_method' do
  subject { object.unmemoized_instance_method(name) }

  let(:object) do
    Class.new do
      include Memoizable

      def initialize
        @foo = 0
      end

      def foo
        @foo += 1
      end

      memoize :foo
    end
  end

  context 'when the method was memoized' do
    let(:name) { :foo }

    it { should be_instance_of(UnboundMethod) }

    it 'returns the original method' do
      # original method is not memoized
      method = subject.bind(object.new)
      expect(method.call).to_not be(method.call)
    end
  end

  context 'when the method was not memoized' do
    let(:name) { :bar }

    it 'raises an exception' do
      expect { subject }.to raise_error(NameError, 'No method bar is memoized')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
memoizable-0.4.2 spec/unit/memoizable/module_methods/unmemoized_instance_method_spec.rb
memoizable-0.4.1 spec/unit/memoizable/module_methods/unmemoized_instance_method_spec.rb
memoizable-0.4.0 spec/unit/memoizable/module_methods/unmemoized_instance_method_spec.rb
memoizable-0.3.1 spec/unit/memoizable/module_methods/unmemoized_instance_method_spec.rb
memoizable-0.3.0 spec/unit/memoizable/module_methods/unmemoized_instance_method_spec.rb