aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 11:19:42 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 11:19:42 +0000
commit3028ac24103cbee81d41bafaf736fe77a1b1dc84 (patch)
tree2a39d8b605a16bb62fb2d066ed2830abdddeef9f /spec
parentea33f860df2477a5eb627604b108b25c47667ce2 (diff)
downloadruby-3028ac24103cbee81d41bafaf736fe77a1b1dc84.tar.gz
Simplify, avoid extra exceptions and add test for concurrent mspec mkdir_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/mspec/lib/mspec/helpers/fs.rb13
-rw-r--r--spec/mspec/spec/helpers/fs_spec.rb13
2 files changed, 21 insertions, 5 deletions
diff --git a/spec/mspec/lib/mspec/helpers/fs.rb b/spec/mspec/lib/mspec/helpers/fs.rb
index 5a9c3bdba1..2200339bd7 100644
--- a/spec/mspec/lib/mspec/helpers/fs.rb
+++ b/spec/mspec/lib/mspec/helpers/fs.rb
@@ -17,16 +17,19 @@ class Object
parts.each do |part|
name = File.join name, part
- stat = File.stat name rescue nil
- if stat and stat.file?
+ if File.file? name
raise ArgumentError, "path component of #{path} is a file"
end
- unless stat and stat.directory?
+ unless File.directory? name
begin
Dir.mkdir name
- rescue Errno::EEXIST
- raise unless File.directory? name
+ rescue Errno::EEXIST => e
+ if File.directory? name
+ # OK, another process/thread created the same directory
+ else
+ raise e
+ end
end
end
end
diff --git a/spec/mspec/spec/helpers/fs_spec.rb b/spec/mspec/spec/helpers/fs_spec.rb
index 5afa91ff58..e40c6c5607 100644
--- a/spec/mspec/spec/helpers/fs_spec.rb
+++ b/spec/mspec/spec/helpers/fs_spec.rb
@@ -93,6 +93,19 @@ describe Object, "#mkdir_p" do
File.open(@dir1, "w") { |f| }
lambda { mkdir_p @dir2 }.should raise_error(ArgumentError)
end
+
+ it "works if multiple processes try to create the same directory concurrently" do
+ original = File.method(:directory?)
+ File.should_receive(:directory?).at_least(:once) { |dir|
+ ret = original.call(dir)
+ if !ret and dir == @dir1
+ Dir.mkdir(dir) # Simulate race
+ end
+ ret
+ }
+ mkdir_p @dir1
+ original.call(@dir1).should be_true
+ end
end
describe Object, "#rm_r" do