Sha256: e2f5dc82ea84b446fec9167dc2d71c983d1d36a10bb3839b3a1339d58b2277b0

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

require 'dry/component/loader'

RSpec.describe Dry::Component::Loader do
  before do
    module Test
      class Bar
      end
    end
  end

  shared_examples_for 'a valid component' do
    describe '#constant' do
      it 'returns the constant' do
        expect(component.constant).to be(Test::Bar)
      end
    end

    describe '#identifier' do
      it 'returns container identifier' do
        expect(component.identifier).to eql('test.bar')
      end
    end

    describe '#path' do
      it 'returns relative path to file defining the component constant' do
        expect(component.path).to eql('test/bar')
      end
    end

    describe '#file' do
      it 'returns relative path to file with ext defining the component constant' do
        expect(component.file).to eql('test/bar.rb')
      end
    end

    describe '#instance' do
      it 'builds a component class instance' do
        expect(component.instance).to be_instance_of(Test::Bar)
      end
    end
  end

  context 'from identifier as a symbol' do
    subject(:component) { Dry::Component::Loader.new(:'test.bar') }

    it_behaves_like 'a valid component'
  end

  context 'from identifier as a string' do
    subject(:component) { Dry::Component::Loader.new('test.bar') }

    it_behaves_like 'a valid component'
  end

  context 'from path' do
    subject(:component) { Dry::Component::Loader.new('test/bar') }

    it_behaves_like 'a valid component'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-component-0.3.0 spec/unit/loader_spec.rb
dry-component-0.2.0 spec/unit/loader_spec.rb
dry-component-0.1.0 spec/unit/loader_spec.rb