|
68 | 68 | described_class.new(adapter: :typhoeus) |
69 | 69 | end |
70 | 70 |
|
71 | | - it 'uses Faraday' do |
| 71 | + it 'uses Faraday with the adapter' do |
| 72 | + expect(adapter).to include(Faraday::Adapter::Typhoeus) |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context 'when the adapter is specified as a string key' do |
| 77 | + |
| 78 | + let(:adapter) do |
| 79 | + client.transport.connections.all.first.connection.builder.handlers |
| 80 | + end |
| 81 | + |
| 82 | + let(:client) do |
| 83 | + described_class.new('adapter' => :typhoeus) |
| 84 | + end |
| 85 | + |
| 86 | + it 'uses Faraday with the adapter' do |
72 | 87 | expect(adapter).to include(Faraday::Adapter::Typhoeus) |
73 | 88 | end |
74 | 89 | end |
|
426 | 441 | context 'when hosts are specified with the \'host\' key' do |
427 | 442 |
|
428 | 443 | let(:client) do |
429 | | - described_class.new(hosts: ['host1', 'host2', 'host3', 'host4'], randomize_hosts: true) |
| 444 | + described_class.new(host: ['host1', 'host2', 'host3', 'host4'], randomize_hosts: true) |
430 | 445 | end |
431 | 446 |
|
432 | 447 | let(:hosts) do |
|
438 | 453 | end |
439 | 454 | end |
440 | 455 |
|
441 | | - context 'when hosts are specified with the \'host\' key' do |
| 456 | + context 'when hosts are specified with the \'host\' key as a String' do |
442 | 457 |
|
443 | 458 | let(:client) do |
444 | | - described_class.new(host: host) |
| 459 | + described_class.new('host' => ['host1', 'host2', 'host3', 'host4'], 'randomize_hosts' => true) |
445 | 460 | end |
446 | 461 |
|
447 | 462 | let(:hosts) do |
448 | 463 | client.transport.hosts |
449 | 464 | end |
450 | 465 |
|
451 | | - it_behaves_like 'a client that extracts hosts' |
| 466 | + it 'sets the hosts in random order' do |
| 467 | + expect(hosts.all? { |host| client.transport.hosts.include?(host) }).to be(true) |
| 468 | + end |
452 | 469 | end |
453 | 470 |
|
454 | 471 | context 'when hosts are specified with the \'hosts\' key' do |
455 | 472 |
|
456 | 473 | let(:client) do |
457 | | - described_class.new(host: host) |
| 474 | + described_class.new(hosts: host) |
| 475 | + end |
| 476 | + |
| 477 | + let(:hosts) do |
| 478 | + client.transport.hosts |
| 479 | + end |
| 480 | + |
| 481 | + it_behaves_like 'a client that extracts hosts' |
| 482 | + end |
| 483 | + |
| 484 | + context 'when hosts are specified with the \'hosts\' key as a String' do |
| 485 | + |
| 486 | + let(:client) do |
| 487 | + described_class.new('hosts' => host) |
458 | 488 | end |
459 | 489 |
|
460 | 490 | let(:hosts) do |
|
467 | 497 | context 'when hosts are specified with the \'url\' key' do |
468 | 498 |
|
469 | 499 | let(:client) do |
470 | | - described_class.new(host: host) |
| 500 | + described_class.new(url: host) |
| 501 | + end |
| 502 | + |
| 503 | + let(:hosts) do |
| 504 | + client.transport.hosts |
| 505 | + end |
| 506 | + |
| 507 | + it_behaves_like 'a client that extracts hosts' |
| 508 | + end |
| 509 | + |
| 510 | + context 'when hosts are specified with the \'url\' key as a String' do |
| 511 | + |
| 512 | + let(:client) do |
| 513 | + described_class.new('url' => host) |
471 | 514 | end |
472 | 515 |
|
473 | 516 | let(:hosts) do |
|
480 | 523 | context 'when hosts are specified with the \'urls\' key' do |
481 | 524 |
|
482 | 525 | let(:client) do |
483 | | - described_class.new(host: host) |
| 526 | + described_class.new(urls: host) |
| 527 | + end |
| 528 | + |
| 529 | + let(:hosts) do |
| 530 | + client.transport.hosts |
| 531 | + end |
| 532 | + |
| 533 | + it_behaves_like 'a client that extracts hosts' |
| 534 | + end |
| 535 | + |
| 536 | + context 'when hosts are specified with the \'urls\' key as a String' do |
| 537 | + |
| 538 | + let(:client) do |
| 539 | + described_class.new('urls' => host) |
484 | 540 | end |
485 | 541 |
|
486 | 542 | let(:hosts) do |
|
537 | 593 | end |
538 | 594 | end |
539 | 595 |
|
| 596 | + context 'when scheme is specified as a String key' do |
| 597 | + |
| 598 | + let(:client) do |
| 599 | + described_class.new('scheme' => 'https') |
| 600 | + end |
| 601 | + |
| 602 | + it 'sets the scheme' do |
| 603 | + expect(client.transport.connections[0].full_url('')).to match(/https/) |
| 604 | + end |
| 605 | + end |
| 606 | + |
540 | 607 | context 'when user and password are specified' do |
541 | 608 |
|
542 | 609 | let(:client) do |
|
563 | 630 | end |
564 | 631 | end |
565 | 632 |
|
| 633 | + context 'when user and password are specified as String keys' do |
| 634 | + |
| 635 | + let(:client) do |
| 636 | + described_class.new('user' => 'USERNAME', 'password' => 'PASSWORD') |
| 637 | + end |
| 638 | + |
| 639 | + it 'sets the user and password' do |
| 640 | + expect(client.transport.connections[0].full_url('')).to match(/USERNAME/) |
| 641 | + expect(client.transport.connections[0].full_url('')).to match(/PASSWORD/) |
| 642 | + end |
| 643 | + |
| 644 | + context 'when the connections are reloaded' do |
| 645 | + |
| 646 | + before do |
| 647 | + allow(client.transport.sniffer).to receive(:hosts).and_return([{ host: 'foobar', port: 4567, id: 'foobar4567' }]) |
| 648 | + client.transport.reload_connections! |
| 649 | + end |
| 650 | + |
| 651 | + it 'sets keeps user and password' do |
| 652 | + expect(client.transport.connections[0].full_url('')).to match(/USERNAME/) |
| 653 | + expect(client.transport.connections[0].full_url('')).to match(/PASSWORD/) |
| 654 | + expect(client.transport.connections[0].full_url('')).to match(/foobar/) |
| 655 | + end |
| 656 | + end |
| 657 | + end |
| 658 | + |
566 | 659 | context 'when port is specified' do |
567 | 660 |
|
568 | 661 | let(:client) do |
|
647 | 740 | expect(client.transport.options[:transport_options][:request]).to eq(timeout: 120) |
648 | 741 | end |
649 | 742 | end |
| 743 | + |
| 744 | + context 'when \'request_timeout\' is defined as a String key' do |
| 745 | + |
| 746 | + let(:client) do |
| 747 | + described_class.new('request_timeout' => 120) |
| 748 | + end |
| 749 | + |
| 750 | + it 'sets the options on the transport' do |
| 751 | + expect(client.transport.options[:transport_options][:request]).to eq(timeout: 120) |
| 752 | + end |
| 753 | + end |
650 | 754 | end |
651 | 755 |
|
652 | 756 | describe '#perform_request' do |
|
0 commit comments