Sha256: 5a1c1ab7ee8f6694bfd7dc95a400b4e69dc8a446ad4f05bb4449fb4149fc18be

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 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

8 entries across 8 versions & 1 rubygems

Version Path
smart_ioc-0.1.27 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.26 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.25 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.24 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.23 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.22 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.21 spec/smart_ioc/smart_ioc_spec.rb
smart_ioc-0.1.20 spec/smart_ioc/smart_ioc_spec.rb