Sha256: 858482561f8d9d1ef2c58b6601a9900d2c175c738d04f1799b4bf61ad6c98fb9

Contents?: true

Size: 1.92 KB

Versions: 18

Compression:

Stored size: 1.92 KB

Contents

require 'aruba/event_bus/name_resolver'

describe Aruba::EventBus::NameResolver do
  subject(:resolver) { described_class.new(default_name_space) }
  let(:default_name_space) { 'Events' }
  let(:resolved_name) { resolver.transform(original_name) }

  before :each do
    stub_const('Events::MyEvent', Class.new)
    stub_const('Events::MyEvent', Class.new)
  end

  describe '#transform' do
    context 'when name is string' do
      context 'when simple' do
        let(:original_name) { 'Events::MyEvent' }
        it { expect(resolved_name).to eq Events::MyEvent }
      end

      context 'when prefixed' do
        let(:original_name) { '::Events::MyEvent' }
        it { expect(resolved_name).to eq Events::MyEvent }
      end
    end

    context 'when name is class' do
      context 'when simple' do
        let(:original_name) { Events::MyEvent }
        it { expect(resolved_name).to eq Events::MyEvent }
      end

      context 'when prefixed' do
        let(:original_name) { ::Events::MyEvent }
        it { expect(resolved_name).to eq Events::MyEvent }
      end
    end

    context 'when name is symbol' do
      let(:original_name) { :my_event }
      it { expect(resolved_name).to eq Events::MyEvent }
    end

    context 'when namespace ...' do
      before :each do
        stub_const('MyLib::Events::MyEvent', Class.new)
      end

      context 'when is string' do
        let!(:default_name_space) { 'MyLib::Events' }
        let!(:original_name) { :my_event }

        it { expect(resolved_name).to eq MyLib::Events::MyEvent }
      end

      context 'when is module' do
        let!(:default_name_space) { MyLib::Events }
        let!(:original_name) { :my_event }

        it { expect(resolved_name).to eq MyLib::Events::MyEvent }
      end
    end

    context 'when invalid' do
      let(:original_name) { 1 }
      it { expect { resolved_name }.to raise_error Aruba::EventNameResolveError, /Transforming "1"/ }
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
aruba-0.14.14 spec/event_bus/name_resolver_spec.rb
aruba-0.14.13 spec/event_bus/name_resolver_spec.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/spec/event_bus/name_resolver_spec.rb
aruba-0.14.12 spec/event_bus/name_resolver_spec.rb
aruba-0.14.11 spec/event_bus/name_resolver_spec.rb
aruba-0.14.10 spec/event_bus/name_resolver_spec.rb
aruba-0.14.9 spec/event_bus/name_resolver_spec.rb
aruba-0.14.8 spec/event_bus/name_resolver_spec.rb
aruba-0.14.7 spec/event_bus/name_resolver_spec.rb
aruba-0.14.6 spec/event_bus/name_resolver_spec.rb
aruba-0.14.5 spec/event_bus/name_resolver_spec.rb
aruba-0.14.4 spec/event_bus/name_resolver_spec.rb
aruba-0.14.3 spec/event_bus/name_resolver_spec.rb
aruba-win-fix-0.14.2 spec/event_bus/name_resolver_spec.rb
aruba-0.14.2 spec/event_bus/name_resolver_spec.rb
aruba-0.14.1 spec/event_bus/name_resolver_spec.rb
aruba-0.14.0 spec/event_bus/name_resolver_spec.rb
aruba-0.13.0 spec/event_bus/name_resolver_spec.rb