Sha256: 600281f1647b59e335b5e798e8cf31888aec53ba740deb44b7558e9725f01237

Contents?: true

Size: 1.47 KB

Versions: 15

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe SmartIoC do
  before :all do
    SmartIoC.clear

    dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/users')
    SmartIoC.find_package_beans(:users, dir_path)

    dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/admins')
    SmartIoC.find_package_beans(:admins, dir_path)

    dir_path = File.join(File.expand_path(File.dirname(__FILE__)), 'example/utils')
    SmartIoC.find_package_beans(:utils, dir_path)

    @container = SmartIoC.container
  end

  it 'loads all beans' do
    SmartIoC.load_all_beans
  end

  it 'sets beans' do
    users_creator = @container.get_bean(:users_creator)
    users_creator.create(1, 'test@test.com')

    repository = @container.get_bean(:repository, package: :admins)

    expect(repository.get(1)).to be_a(User)
    expect(users_creator.send(:repository)).to be_a(AdminsRepository)
    expect(users_creator.send(:logger)).to be_a(LoggerFactory::SmartIoCLogger)
  end

  it 'sets beans with extra package context' do
    SmartIoC.set_extra_context_for_package(:admins, :test)
    SmartIoC.force_clear_scopes
    
    users_creator = @container.get_bean(:users_creator)
    users_creator.create(1, 'test@test.com')

    repository = @container.get_bean(:repository, package: :admins)

    expect(users_creator.send(:repository)).to eq(TestAdminsRepository)
    expect(repository.get(1)).to be_a(User)
    expect(users_creator.send(:logger)).to be_a(LoggerFactory::SmartIoCLogger)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
smart_ioc-0.4.0 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.3.6 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.3.5 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.3.2 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.3.1 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.3.0 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.5 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.4 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.3 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.2 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.1 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.2.0 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.30 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.29 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.28 spec/smart_ioc/smart_ioc_spec.rb