From 3ded64f93fbfe99a5775387bbc83a8643c78732b Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Fri, 11 Jul 2008 14:22:46 -0700 Subject: [PATCH] Imported File#ftype spec from rubyspecs. --- spec/frozen/1.8/core/file/fixtures/file_types.rb | 26 ++++++++---------------- spec/frozen/1.8/core/file/ftype_spec.rb | 4 ---- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/spec/frozen/1.8/core/file/fixtures/file_types.rb b/spec/frozen/1.8/core/file/fixtures/file_types.rb index 658d5f6ef..b00bf4f2f 100644 --- a/spec/frozen/1.8/core/file/fixtures/file_types.rb +++ b/spec/frozen/1.8/core/file/fixtures/file_types.rb @@ -4,7 +4,6 @@ module FileSpecs @file = tmp("test.txt") @dir = Dir.pwd @fifo = tmp("test_fifo") - @sock = nil platform_is_not :windows do @block = `find /dev /devices -type b 2> /dev/null`.split("\n").first @@ -17,17 +16,6 @@ module FileSpecs break end - find_socket - end - end - - # TODO: This is probably too volatile - def self.find_socket() - %w[/tmp /var/run].each do |dir| - socks = `find #{dir} -type s 2> /dev/null`.split("\n") - next if socks.empty? - @sock = socks.first - break end end @@ -45,6 +33,7 @@ module FileSpecs yield @dir end + # TODO: need a platform-independent helper here def self.fifo() system "mkfifo #{@fifo} 2> /dev/null" yield @fifo @@ -64,12 +53,13 @@ module FileSpecs yield @link end - # This will silently not execute the block if no socket - # can be found. However, if you are running X, there is - # a good chance that if nothing else, at least the X - # Server socket exists. def self.socket() - find_socket - yield @sock if @sock + require 'socket' + name = tmp("ftype_socket.socket") + File.delete name if File.exist? name + socket = UNIXServer.new name + yield name + socket.close + File.delete name if File.exist? name end end diff --git a/spec/frozen/1.8/core/file/ftype_spec.rb b/spec/frozen/1.8/core/file/ftype_spec.rb index cfd228e12..00d186244 100644 --- a/spec/frozen/1.8/core/file/ftype_spec.rb +++ b/spec/frozen/1.8/core/file/ftype_spec.rb @@ -58,10 +58,6 @@ describe "File.ftype" do end end - # This will silently not execute the block if no socket - # can be found. However, if you are running X, there is - # a good chance that if nothing else, at least the X - # Server socket exists. it "returns 'socket' when the file is a socket" do FileSpecs.socket do |socket| File.ftype(socket).should == 'socket' -- 2.11.4.GIT