Sha256: a0fd2677a41dbde2b79692eb56625aabfb9755b90fe263d61368853cfa13ff73

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

require 'spec_helper'

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

  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dependor-1.0.0 spec/dependor/instantiator_spec.rb