# frozen_string_literal: true require 'spec_helper' RSpec.describe TwilioBase::Routers::Voice::Default do let(:protocol) do TwilioBase::Protocols::Voice::Pstn.new(to: '+1234567890') end describe '.init' do context 'with set routing_method' do it 'overwrites ENV variable' do stub_const('ENV', ENV.to_h.merge('ROUTING_METHOD' => 'direct_dial')) allow(TwilioBase::Routers::Voice::DirectDial).to receive(:new) allow(TwilioBase::Routers::Voice::TaskRouter).to receive(:new) described_class.init(protocol: protocol, routing_method: 'task_router') expect(TwilioBase::Routers::Voice::DirectDial) .to_not have_received(:new) expect(TwilioBase::Routers::Voice::TaskRouter).to have_received(:new) .with(protocol: protocol) end end context 'with not set routing_method' do context 'with direct dial routing method' do before do stub_const('ENV', ENV.to_h.merge('ROUTING_METHOD' => 'direct_dial')) end it 'inits Routers::Voice::DirectDial' do allow(TwilioBase::Routers::Voice::DirectDial).to receive(:new) described_class.init(protocol: protocol) expect(TwilioBase::Routers::Voice::DirectDial).to have_received(:new) .with(protocol: protocol) end end context 'with task router routing method' do before do stub_const('ENV', ENV.to_h.merge('ROUTING_METHOD' => 'task_router')) end it 'inits Routers::Voice::TaskRouter' do allow(TwilioBase::Routers::Voice::TaskRouter).to receive(:new) described_class.init(protocol: protocol) expect(TwilioBase::Routers::Voice::TaskRouter).to have_received(:new) .with(protocol: protocol) end end end end end