File: lazy_module_spec.rb

package info (click to toggle)
libextlib-ruby 0.9.13-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 532 kB
  • ctags: 487
  • sloc: ruby: 7,120; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (2)
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
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
require 'extlib/lazy_module'

describe LazyModule do
  describe "instantiated with a block" do
    it "defers block body evaluation" do
      lambda do
        LazyModule.new do
          raise "Will only be evaluated when mixed in"
        end
      end.should_not raise_error
    end
  end


  describe "included into hosting class" do
    before :all do
      KlazzyLazyModule = LazyModule.new do
        def self.klassy
          "Klazz"
        end

        def instancy
          "Instanzz"
        end
      end

      @klass = Class.new do
        include KlazzyLazyModule
      end
    end

    it "class evals block body" do
      @klass.klassy.should == "Klazz"
      @klass.new.instancy.should == "Instanzz"
    end
  end
end