Sha256: 7ae094dfd7448291281c52ae3e5cc99032fe0173d4c730859154f15ae2c2e47a

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe SmartIoC::BeanFactory do
  before :all do
    SmartIoC.clear

    class Repo
      include SmartIoC::Iocify
      bean :repo, context: :default, package: :bean_factory
    end

    class TestRepo
      include SmartIoC::Iocify
      bean :repo, context: :test, package: :bean_factory
    end

    class DAO
      include SmartIoC::Iocify
      bean :dao, context: :default, package: :bean_factory
    end
  end

  it 'returns proper bean for test context' do
    SmartIoC::Container.get_instance.set_extra_context_for_package(:bean_factory, :test)
    expect(SmartIoC::Container.get_bean(:repo)).to be_a(TestRepo)
  end

  it 'returns proper bean for default context' do
    SmartIoC::Container.get_instance.set_extra_context_for_package(:bean_factory, :default)
    expect(SmartIoC::Container.get_bean(:repo)).to be_a(Repo)
  end

  it 'returns proper bean for test context with fallback to default context' do
    SmartIoC::Container.get_instance.set_extra_context_for_package(:bean_factory, :test)
    expect(SmartIoC::Container.get_bean(:dao)).to be_a(DAO)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smart_ioc-0.1.19 spec/smart_ioc/bean_factory_spec.rb
smart_ioc-0.1.18 spec/smart_ioc/bean_factory_spec.rb