diff options
Diffstat (limited to 'spec/rubyspec/core/io/close_on_exec_spec.rb')
-rw-r--r-- | spec/rubyspec/core/io/close_on_exec_spec.rb | 137 |
1 files changed, 58 insertions, 79 deletions
diff --git a/spec/rubyspec/core/io/close_on_exec_spec.rb b/spec/rubyspec/core/io/close_on_exec_spec.rb index 46a58374f9..057a9a1c20 100644 --- a/spec/rubyspec/core/io/close_on_exec_spec.rb +++ b/spec/rubyspec/core/io/close_on_exec_spec.rb @@ -1,44 +1,5 @@ require File.expand_path('../../../spec_helper', __FILE__) -describe :io_close_on_exec, shared: true do - it "sets the close-on-exec flag if true" do - @io.close_on_exec = true - @io.close_on_exec?.should == true - end - - it "sets the close-on-exec flag if non-false" do - @io.close_on_exec = :true - @io.close_on_exec?.should == true - end - - it "unsets the close-on-exec flag if false" do - @io.close_on_exec = true - @io.close_on_exec = false - @io.close_on_exec?.should == false - end - - it "unsets the close-on-exec flag if nil" do - @io.close_on_exec = true - @io.close_on_exec = nil - @io.close_on_exec?.should == false - end - - it "ensures the IO's file descriptor is closed in exec'ed processes" do - require 'fcntl' - @io.close_on_exec = true - (@io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC).should == Fcntl::FD_CLOEXEC - end - - it "raises IOError if called on a closed IO" do - @io.close - lambda { @io.close_on_exec = true }.should raise_error(IOError) - end - - it "returns nil" do - @io.send(:close_on_exec=, true).should be_nil - end -end - describe "IO#close_on_exec=" do before :each do @name = tmp('io_close_on_exec.txt') @@ -50,47 +11,59 @@ describe "IO#close_on_exec=" do rm_r @name end - platform_is :windows do - ruby_version_is ""..."2.3" do - it "returns false from #respond_to?" do - @io.respond_to?(:close_on_exec=).should be_false - end - - it "raises a NotImplementedError when called" do - lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError) - end + guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do + it "returns false from #respond_to?" do + @io.respond_to?(:close_on_exec=).should be_false end - ruby_version_is "2.3" do - it_should_behave_like :io_close_on_exec + it "raises a NotImplementedError when called" do + lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError) end end - platform_is_not :windows do - it_should_behave_like :io_close_on_exec - end -end + guard -> { platform_is_not :windows or ruby_version_is "2.3" } do + it "sets the close-on-exec flag if true" do + @io.close_on_exec = true + @io.close_on_exec?.should == true + end + it "sets the close-on-exec flag if non-false" do + @io.close_on_exec = :true + @io.close_on_exec?.should == true + end -describe :io_is_close_on_exec, shared: true do - it "returns true by default" do - @io.close_on_exec?.should == true - end + it "unsets the close-on-exec flag if false" do + @io.close_on_exec = true + @io.close_on_exec = false + @io.close_on_exec?.should == false + end - it "returns true if set" do - @io.close_on_exec = true - @io.close_on_exec?.should == true - end + it "unsets the close-on-exec flag if nil" do + @io.close_on_exec = true + @io.close_on_exec = nil + @io.close_on_exec?.should == false + end + + it "ensures the IO's file descriptor is closed in exec'ed processes" do + require 'fcntl' + @io.close_on_exec = true + (@io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC).should == Fcntl::FD_CLOEXEC + end + + it "raises IOError if called on a closed IO" do + @io.close + lambda { @io.close_on_exec = true }.should raise_error(IOError) + end - it "raises IOError if called on a closed IO" do - @io.close - lambda { @io.close_on_exec? }.should raise_error(IOError) + it "returns nil" do + @io.send(:close_on_exec=, true).should be_nil + end end end describe "IO#close_on_exec?" do before :each do - @name = tmp('io_close_on_exec.txt') + @name = tmp('io_is_close_on_exec.txt') @io = new_io @name end @@ -99,23 +72,29 @@ describe "IO#close_on_exec?" do rm_r @name end - platform_is :windows do - ruby_version_is ""..."2.3" do - it "returns false from #respond_to?" do - @io.respond_to?(:close_on_exec?).should be_false - end - - it "raises a NotImplementedError when called" do - lambda { @io.close_on_exec? }.should raise_error(NotImplementedError) - end + guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do + it "returns false from #respond_to?" do + @io.respond_to?(:close_on_exec?).should be_false end - ruby_version_is "2.3" do - it_should_behave_like :io_close_on_exec + it "raises a NotImplementedError when called" do + lambda { @io.close_on_exec? }.should raise_error(NotImplementedError) end end - platform_is_not :windows do - it_should_behave_like :io_is_close_on_exec + guard -> { platform_is_not :windows or ruby_version_is "2.3" } do + it "returns true by default" do + @io.close_on_exec?.should == true + end + + it "returns true if set" do + @io.close_on_exec = true + @io.close_on_exec?.should == true + end + + it "raises IOError if called on a closed IO" do + @io.close + lambda { @io.close_on_exec? }.should raise_error(IOError) + end end end |