File: unmemoized_instance_method_spec.rb

package info (click to toggle)
ruby-memoizable 0.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: ruby: 605; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 858 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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