File: memoize_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 (40 lines) | stat: -rw-r--r-- 969 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
# encoding: utf-8

require 'spec_helper'
require File.expand_path('../../fixtures/classes', __FILE__)

describe Memoizable::InstanceMethods, '#memoize' do
  subject { object.memoize(method => value) }

  let(:described_class) { Class.new(Fixture::Object) }
  let(:object)          { described_class.new        }
  let(:method)          { :test                      }

  before do
    described_class.memoize(method)
  end

  context 'when the method is not memoized' do
    let(:value) { String.new }

    it 'sets the memoized value for the method to the value' do
      subject
      expect(object.send(method)).to be(value)
    end

    it_should_behave_like 'a command method'
  end

  context 'when the method is already memoized' do
    let(:value)    { double }
    let(:original) { nil    }

    before do
      object.memoize(method => original)
    end

    it 'raises an exception' do
      expect { subject }.to raise_error(ArgumentError)
    end
  end
end