Sha256: cb367762f4fff1c3d1975dc9a6b0781a64528e9b95413d99f7d90581907ecd5b

Contents?: true

Size: 882 Bytes

Versions: 5

Compression:

Stored size: 882 Bytes

Contents

require_relative '../spec_helper'

describe Dependor::Instantiator do
  let(:injector) { stub(: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

5 entries across 5 versions & 1 rubygems

Version Path
dependor-0.0.5 spec/dependor/instantiator_spec.rb
dependor-0.0.4 spec/dependor/instantiator_spec.rb
dependor-0.0.3 spec/dependor/instantiator_spec.rb
dependor-0.0.2 spec/dependor/instantiator_spec.rb
dependor-0.0.1 spec/dependor/instantiator_spec.rb