|
418 | 418 | end |
419 | 419 | end |
420 | 420 |
|
| 421 | + context "specifying per operation timeouts with long form keys" do |
| 422 | + let(:client) { HTTP.timeout read_timeout: 123 } |
| 423 | + |
| 424 | + it "sets given timeout options" do |
| 425 | + assert_equal({ read_timeout: 123 }, client.default_options.timeout_options) |
| 426 | + end |
| 427 | + end |
| 428 | + |
| 429 | + context "specifying all per operation timeouts" do |
| 430 | + let(:client) { HTTP.timeout read: 1, write: 2, connect: 3 } |
| 431 | + |
| 432 | + it "sets all timeout options" do |
| 433 | + assert_equal({ read_timeout: 1, write_timeout: 2, connect_timeout: 3 }, client.default_options.timeout_options) |
| 434 | + end |
| 435 | + end |
| 436 | + |
421 | 437 | context "specifying per operation timeouts as frozen hash" do |
422 | 438 | let(:frozen_options) { { read: 123 }.freeze } |
423 | 439 | let(:client) { HTTP.timeout(frozen_options) } |
|
427 | 443 | end |
428 | 444 | end |
429 | 445 |
|
| 446 | + context "with empty hash" do |
| 447 | + it "raises ArgumentError" do |
| 448 | + assert_raises(ArgumentError) { HTTP.timeout({}) } |
| 449 | + end |
| 450 | + end |
| 451 | + |
| 452 | + context "with unknown timeout key" do |
| 453 | + it "raises ArgumentError" do |
| 454 | + assert_raises(ArgumentError) { HTTP.timeout(timeout: 2) } |
| 455 | + end |
| 456 | + end |
| 457 | + |
| 458 | + context "with both short and long form of same key" do |
| 459 | + it "raises ArgumentError" do |
| 460 | + assert_raises(ArgumentError) { HTTP.timeout(read: 2, read_timeout: 2) } |
| 461 | + end |
| 462 | + end |
| 463 | + |
| 464 | + context "with non-numeric timeout value" do |
| 465 | + it "raises ArgumentError" do |
| 466 | + assert_raises(ArgumentError) { HTTP.timeout(read: "2") } |
| 467 | + end |
| 468 | + end |
| 469 | + |
| 470 | + context "with string keys" do |
| 471 | + it "raises ArgumentError" do |
| 472 | + assert_raises(ArgumentError) { HTTP.timeout("read" => 2) } |
| 473 | + end |
| 474 | + end |
| 475 | + |
| 476 | + context "with global key as hash" do |
| 477 | + it "raises ArgumentError" do |
| 478 | + assert_raises(ArgumentError) { HTTP.timeout(global: 161) } |
| 479 | + end |
| 480 | + end |
| 481 | + |
430 | 482 | context "specifying a global timeout" do |
431 | 483 | let(:client) { HTTP.timeout 123 } |
432 | 484 |
|
|
439 | 491 | end |
440 | 492 | end |
441 | 493 |
|
| 494 | + context "specifying a float global timeout" do |
| 495 | + let(:client) { HTTP.timeout 2.5 } |
| 496 | + |
| 497 | + it "sets given timeout option" do |
| 498 | + assert_equal({ global_timeout: 2.5 }, client.default_options.timeout_options) |
| 499 | + end |
| 500 | + end |
| 501 | + |
442 | 502 | context "with unsupported options" do |
443 | 503 | it "raises ArgumentError" do |
444 | 504 | assert_raises(ArgumentError) { HTTP.timeout("invalid") } |
|
0 commit comments