diff options
Diffstat (limited to 'spec/ruby/core/io/reopen_spec.rb')
| -rw-r--r-- | spec/ruby/core/io/reopen_spec.rb | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb index 63020d5f3e..3b972d8978 100644 --- a/spec/ruby/core/io/reopen_spec.rb +++ b/spec/ruby/core/io/reopen_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' require 'fcntl' @@ -27,35 +27,35 @@ describe "IO#reopen" do it "changes the class of the instance to the class of the object returned by #to_io" do obj = mock("io") obj.should_receive(:to_io).and_return(@other_io) - @io.reopen(obj).should be_an_instance_of(File) + @io.reopen(obj).should.instance_of?(File) end it "raises an IOError if the object returned by #to_io is closed" do obj = mock("io") obj.should_receive(:to_io).and_return(IOSpecs.closed_io) - lambda { @io.reopen obj }.should raise_error(IOError) + -> { @io.reopen obj }.should.raise(IOError) end it "raises a TypeError if #to_io does not return an IO instance" do obj = mock("io") obj.should_receive(:to_io).and_return("something else") - lambda { @io.reopen obj }.should raise_error(TypeError) + -> { @io.reopen obj }.should.raise(TypeError) end it "raises an IOError when called on a closed stream with an object" do @io.close obj = mock("io") obj.should_not_receive(:to_io) - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should.raise(IOError) end it "raises an IOError if the IO argument is closed" do - lambda { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError) + -> { @io.reopen(IOSpecs.closed_io) }.should.raise(IOError) end it "raises an IOError when called on a closed stream with an IO" do @io.close - lambda { @io.reopen(STDOUT) }.should raise_error(IOError) + -> { @io.reopen(STDOUT) }.should.raise(IOError) end end @@ -77,12 +77,12 @@ describe "IO#reopen with a String" do it "does not raise an exception when called on a closed stream with a path" do @io.close @io.reopen @name, "r" - @io.closed?.should be_false + @io.closed?.should == false @io.gets.should == "Line 1: One\n" end it "returns self" do - @io.reopen(@name).should equal(@io) + @io.reopen(@name).should.equal?(@io) end it "positions a newly created instance at the beginning of the new stream" do @@ -145,31 +145,30 @@ describe "IO#reopen with a String" do File.read(@other_name).should == "new data" end - it "closes the file descriptor obtained by opening the new file" do + it "always resets the close-on-exec flag to true on non-STDIO objects" do @io = new_io @name, "w" - @other_io = File.open @other_name, "w" - max = @other_io.fileno - @other_io.close - + @io.close_on_exec = true @io.reopen @other_name + @io.should.close_on_exec? - @other_io = File.open @other_name, "w" - @other_io.fileno.should == max + @io.close_on_exec = false + @io.reopen @other_name + @io.should.close_on_exec? end it "creates the file if it doesn't exist if the IO is opened in write mode" do @io = new_io @name, "w" @io.reopen(@other_name) - File.exist?(@other_name).should be_true + File.should.exist?(@other_name) end it "creates the file if it doesn't exist if the IO is opened in write mode" do @io = new_io @name, "a" @io.reopen(@other_name) - File.exist?(@other_name).should be_true + File.should.exist?(@other_name) end end @@ -189,7 +188,7 @@ describe "IO#reopen with a String" do it "raises an Errno::ENOENT if the file does not exist and the IO is not opened in write mode" do @io = new_io @name, "r" - lambda { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT) + -> { @io.reopen(@other_name) }.should.raise(Errno::ENOENT) end end @@ -215,9 +214,9 @@ describe "IO#reopen with an IO at EOF" do end it "resets the EOF status to false" do - @io.eof?.should be_true + @io.eof?.should == true @io.reopen @other_io - @io.eof?.should be_false + @io.eof?.should == false end end @@ -231,7 +230,7 @@ describe "IO#reopen with an IO" do end @io = new_io @name - @other_io = new_io @other_name, "r" + @other_io = IO.new(new_fd(@other_name, "r"), "r") end after :each do @@ -245,7 +244,7 @@ describe "IO#reopen with an IO" do # MRI actually changes the class of @io in the call to #reopen # but does not preserve the existing singleton class of @io. def @io.to_io; flunk; end - @io.reopen(@other_io).should be_an_instance_of(IO) + @io.reopen(@other_io).should.instance_of?(IO) end it "does not change the object_id" do @@ -290,9 +289,21 @@ describe "IO#reopen with an IO" do File.read(@other_name).should == "io data" end + it "always resets the close-on-exec flag to true on non-STDIO objects" do + @other_io.close_on_exec = true + @io.close_on_exec = true + @io.reopen @other_io + @io.should.close_on_exec? + + @other_io.close_on_exec = false + @io.close_on_exec = false + @io.reopen @other_io + @io.should.close_on_exec? + end + it "may change the class of the instance" do @io.reopen @other_io - @io.should be_an_instance_of(File) + @io.should.instance_of?(File) end it "sets path equals to the other IO's path if other IO is File" do |
