File: instantiator_spec.rb

package info (click to toggle)
ruby-dependor 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264 kB
  • sloc: ruby: 557; makefile: 2; sh: 1
file content (38 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (4)
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 'spec_helper'

describe Dependor::Instantiator do
  let(:injector) { double(:injector) }
  let(:dependency_names) { Dependor::DependencyNamesCache.new }
  let(:instantiator) { Dependor::Instantiator.new(injector, dependency_names) }

  it "instantiates objects with no-arg constructors" do
    klass = Class.new do
      def foo
        "foo"
      end
    end

    instance = instantiator.instantiate(klass)
    instance.foo.should == "foo"
  end

  it "instantiates objects with constructors" do
    klass = Class.new do
      def initialize(foo, bar, baz)
        @foo = [foo, bar, baz].join('-')
      end

      def foo
        @foo
      end
    end

    injector.should_receive(:get).with(:foo).and_return("foo")
    injector.should_receive(:get).with(:bar).and_return("bar")
    injector.should_receive(:get).with(:baz).and_return("baz")

    instance = instantiator.instantiate(klass)

    instance.foo.should == 'foo-bar-baz'
  end
end