|
531 | 531 | end |
532 | 532 | end |
533 | 533 |
|
534 | | - describe "rb_io_open_descriptor" do |
535 | | - it "creates a new IO instance" do |
536 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
537 | | - io.should.is_a?(IO) |
538 | | - end |
| 534 | + quarantine! do # "Errno::EBADF: Bad file descriptor" at closing @r_io, @rw_io etc in the after :each hook |
| 535 | + describe "rb_io_open_descriptor" do |
| 536 | + it "creates a new IO instance" do |
| 537 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 538 | + io.should.is_a?(IO) |
| 539 | + end |
539 | 540 |
|
540 | | - it "return an instance of the specified class" do |
541 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
542 | | - io.class.should == File |
| 541 | + it "return an instance of the specified class" do |
| 542 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 543 | + io.class.should == File |
543 | 544 |
|
544 | | - io = @o.rb_io_open_descriptor(IO, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
545 | | - io.class.should == IO |
546 | | - end |
| 545 | + io = @o.rb_io_open_descriptor(IO, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 546 | + io.class.should == IO |
| 547 | + end |
547 | 548 |
|
548 | | - it "sets the specified file descriptor" do |
549 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
550 | | - io.fileno.should == @r_io.fileno |
551 | | - end |
| 549 | + it "sets the specified file descriptor" do |
| 550 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 551 | + io.fileno.should == @r_io.fileno |
| 552 | + end |
552 | 553 |
|
553 | | - it "sets the specified path" do |
554 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
555 | | - io.path.should == "a.txt" |
556 | | - end |
| 554 | + it "sets the specified path" do |
| 555 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 556 | + io.path.should == "a.txt" |
| 557 | + end |
557 | 558 |
|
558 | | - it "sets the specified mode" do |
559 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_BINMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
560 | | - io.should.binmode? |
| 559 | + it "sets the specified mode" do |
| 560 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_BINMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 561 | + io.should.binmode? |
561 | 562 |
|
562 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_TEXTMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
563 | | - io.should_not.binmode? |
564 | | - end |
| 563 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, CApiIOSpecs::FMODE_TEXTMODE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 564 | + io.should_not.binmode? |
| 565 | + end |
565 | 566 |
|
566 | | - it "sets the specified timeout" do |
567 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
568 | | - io.timeout.should == 60 |
569 | | - end |
| 567 | + it "sets the specified timeout" do |
| 568 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 569 | + io.timeout.should == 60 |
| 570 | + end |
570 | 571 |
|
571 | | - it "sets the specified internal encoding" do |
572 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
573 | | - io.internal_encoding.should == Encoding::US_ASCII |
574 | | - end |
| 572 | + it "sets the specified internal encoding" do |
| 573 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 574 | + io.internal_encoding.should == Encoding::US_ASCII |
| 575 | + end |
575 | 576 |
|
576 | | - it "sets the specified external encoding" do |
577 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
578 | | - io.external_encoding.should == Encoding::UTF_8 |
579 | | - end |
| 577 | + it "sets the specified external encoding" do |
| 578 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 579 | + io.external_encoding.should == Encoding::UTF_8 |
| 580 | + end |
580 | 581 |
|
581 | | - it "does not apply the specified encoding flags" do |
582 | | - name = tmp("rb_io_open_descriptor_specs") |
583 | | - File.write(name, "123\r\n456\n89") |
584 | | - file = File.open(name, "r") |
| 582 | + it "does not apply the specified encoding flags" do |
| 583 | + name = tmp("rb_io_open_descriptor_specs") |
| 584 | + File.write(name, "123\r\n456\n89") |
| 585 | + file = File.open(name, "r") |
585 | 586 |
|
586 | | - io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {}) |
587 | | - io.read_nonblock(20).should == "123\r\n456\n89" |
588 | | - ensure |
589 | | - file.close |
590 | | - rm_r name |
591 | | - end |
| 587 | + io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {}) |
| 588 | + io.read_nonblock(20).should == "123\r\n456\n89" |
| 589 | + ensure |
| 590 | + file.close |
| 591 | + rm_r name |
| 592 | + end |
592 | 593 |
|
593 | | - it "ignores the IO open options" do |
594 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {external_encoding: "windows-1251"}) |
595 | | - io.external_encoding.should == Encoding::UTF_8 |
| 594 | + it "ignores the IO open options" do |
| 595 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {external_encoding: "windows-1251"}) |
| 596 | + io.external_encoding.should == Encoding::UTF_8 |
596 | 597 |
|
597 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {internal_encoding: "windows-1251"}) |
598 | | - io.internal_encoding.should == Encoding::US_ASCII |
| 598 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {internal_encoding: "windows-1251"}) |
| 599 | + io.internal_encoding.should == Encoding::US_ASCII |
599 | 600 |
|
600 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {encoding: "windows-1251:binary"}) |
601 | | - io.external_encoding.should == Encoding::UTF_8 |
602 | | - io.internal_encoding.should == Encoding::US_ASCII |
| 601 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {encoding: "windows-1251:binary"}) |
| 602 | + io.external_encoding.should == Encoding::UTF_8 |
| 603 | + io.internal_encoding.should == Encoding::US_ASCII |
603 | 604 |
|
604 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {textmode: false}) |
605 | | - io.should_not.binmode? |
| 605 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {textmode: false}) |
| 606 | + io.should_not.binmode? |
606 | 607 |
|
607 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {binmode: true}) |
608 | | - io.should_not.binmode? |
| 608 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {binmode: true}) |
| 609 | + io.should_not.binmode? |
609 | 610 |
|
610 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {autoclose: false}) |
611 | | - io.should.autoclose? |
| 611 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {autoclose: false}) |
| 612 | + io.should.autoclose? |
612 | 613 |
|
613 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {path: "a.txt"}) |
614 | | - io.path.should == "a.txt" |
615 | | - end |
| 614 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, "a.txt", 60, "US-ASCII", "UTF-8", 0, {path: "a.txt"}) |
| 615 | + io.path.should == "a.txt" |
| 616 | + end |
616 | 617 |
|
617 | | - it "ignores the IO encoding options" do |
618 | | - io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_WRITABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {crlf_newline: true}) |
| 618 | + it "ignores the IO encoding options" do |
| 619 | + io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_WRITABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {crlf_newline: true}) |
619 | 620 |
|
620 | | - io.write("123\r\n456\n89") |
621 | | - io.flush |
| 621 | + io.write("123\r\n456\n89") |
| 622 | + io.flush |
622 | 623 |
|
623 | | - @r_io.read_nonblock(20).should == "123\r\n456\n89" |
624 | | - end |
| 624 | + @r_io.read_nonblock(20).should == "123\r\n456\n89" |
| 625 | + end |
625 | 626 |
|
626 | | - it "allows wrong mode" do |
627 | | - io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
628 | | - io.should.is_a?(File) |
| 627 | + it "allows wrong mode" do |
| 628 | + io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) |
| 629 | + io.should.is_a?(File) |
629 | 630 |
|
630 | | - platform_is_not :windows do |
631 | | - -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) |
632 | | - end |
| 631 | + platform_is_not :windows do |
| 632 | + -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) |
| 633 | + end |
633 | 634 |
|
634 | | - platform_is :windows do |
635 | | - -> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable) |
| 635 | + platform_is :windows do |
| 636 | + -> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable) |
| 637 | + end |
636 | 638 | end |
637 | | - end |
638 | 639 |
|
639 | | - it "tolerates NULL as rb_io_encoding *encoding parameter" do |
640 | | - io = @o.rb_io_open_descriptor_without_encoding(File, @r_io.fileno, 0, "a.txt", 60) |
641 | | - io.should.is_a?(File) |
642 | | - end |
| 640 | + it "tolerates NULL as rb_io_encoding *encoding parameter" do |
| 641 | + io = @o.rb_io_open_descriptor_without_encoding(File, @r_io.fileno, 0, "a.txt", 60) |
| 642 | + io.should.is_a?(File) |
| 643 | + end |
643 | 644 |
|
644 | | - it "deduplicates path String" do |
645 | | - path = "a.txt".dup |
646 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
647 | | - io.path.should_not equal(path) |
| 645 | + it "deduplicates path String" do |
| 646 | + path = "a.txt".dup |
| 647 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
| 648 | + io.path.should_not equal(path) |
648 | 649 |
|
649 | | - path = "a.txt".freeze |
650 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
651 | | - io.path.should_not equal(path) |
652 | | - end |
| 650 | + path = "a.txt".freeze |
| 651 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
| 652 | + io.path.should_not equal(path) |
| 653 | + end |
653 | 654 |
|
654 | | - it "calls #to_str to convert a path to a String" do |
655 | | - path = Object.new |
656 | | - def path.to_str; "a.txt"; end |
| 655 | + it "calls #to_str to convert a path to a String" do |
| 656 | + path = Object.new |
| 657 | + def path.to_str; "a.txt"; end |
657 | 658 |
|
658 | | - io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
| 659 | + io = @o.rb_io_open_descriptor(File, @r_io.fileno, 0, path, 60, "US-ASCII", "UTF-8", 0, {}) |
659 | 660 |
|
660 | | - io.path.should == "a.txt" |
| 661 | + io.path.should == "a.txt" |
| 662 | + end |
661 | 663 | end |
662 | 664 | end |
663 | 665 | end |
|
0 commit comments