File: new_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 (34 lines) | stat: -rw-r--r-- 954 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
# encoding: utf-8

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

describe Memoizable::MethodBuilder, '.new' do
  subject { described_class.new(descendant, method_name, freezer) }

  let(:descendant) { Fixture::Object                   }
  let(:freezer)    { lambda { |object| object.freeze } }

  context 'with a zero arity method' do
    let(:method_name) { :zero_arity }

    it { should be_instance_of(described_class) }

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

  context 'with a one arity method' do
    let(:method_name) { :one_arity }

    it 'raises an exception' do
      expect { subject }.to raise_error(
        described_class::InvalidArityError,
        'Cannot memoize Fixture::Object#one_arity, its arity is 1'
      )
    end
  end
end