summaryrefslogtreecommitdiff
path: root/spec/rubyspec/library/find
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
commit95e8c48dd3348503a8c7db5d0498894a1b676395 (patch)
tree9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/library/find
parented7d803500de38186c74bce94d233e85ef51e503 (diff)
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/library/find')
-rw-r--r--spec/rubyspec/library/find/find_spec.rb30
-rw-r--r--spec/rubyspec/library/find/fixtures/common.rb174
-rw-r--r--spec/rubyspec/library/find/prune_spec.rb12
3 files changed, 216 insertions, 0 deletions
diff --git a/spec/rubyspec/library/find/find_spec.rb b/spec/rubyspec/library/find/find_spec.rb
new file mode 100644
index 0000000000..14c9e2926e
--- /dev/null
+++ b/spec/rubyspec/library/find/find_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
+require 'find'
+
+describe "Find.find" do
+ before :each do
+ FindDirSpecs.create_mock_dirs
+ end
+
+ after :each do
+ FindDirSpecs.delete_mock_dirs
+ end
+
+ describe "when called without a block" do
+ it "returns an Enumerator" do
+ Find.find(FindDirSpecs.mock_dir).should be_an_instance_of(Enumerator)
+ Find.find(FindDirSpecs.mock_dir).to_a.sort.should == FindDirSpecs.expected_paths
+ end
+ end
+
+ it "should recursively yield every file in the directory" do
+ a = []
+
+ Find.find(FindDirSpecs.mock_dir) do |file|
+ a << file
+ end
+
+ a.sort.should == FindDirSpecs.expected_paths
+ end
+end
diff --git a/spec/rubyspec/library/find/fixtures/common.rb b/spec/rubyspec/library/find/fixtures/common.rb
new file mode 100644
index 0000000000..14a7edb09a
--- /dev/null
+++ b/spec/rubyspec/library/find/fixtures/common.rb
@@ -0,0 +1,174 @@
+module FindDirSpecs
+ def self.mock_dir(dirs = ['find_specs_mock'])
+ @mock_dir ||= tmp("")
+ File.join @mock_dir, dirs
+ end
+
+ # The names of the fixture directories and files used by
+ # various Find specs.
+ def self.mock_dir_files
+ unless @mock_dir_files
+ @mock_dir_files = %w[
+ .dotfile
+ .dotsubdir/.dotfile
+ .dotsubdir/nondotfile
+
+ deeply/.dotfile
+ deeply/nested/.dotfile.ext
+ deeply/nested/directory/structure/.ext
+ deeply/nested/directory/structure/bar
+ deeply/nested/directory/structure/baz
+ deeply/nested/directory/structure/file_one
+ deeply/nested/directory/structure/file_one.ext
+ deeply/nested/directory/structure/foo
+ deeply/nondotfile
+
+ file_one.ext
+ file_two.ext
+
+ dir_filename_ordering
+ dir/filename_ordering
+
+ nondotfile
+
+ subdir_one/.dotfile
+ subdir_one/nondotfile
+ subdir_two/nondotfile
+ subdir_two/nondotfile.ext
+
+ brace/a
+ brace/a.js
+ brace/a.erb
+ brace/a.js.rjs
+ brace/a.html.erb
+
+ special/+
+
+ special/^
+ special/$
+
+ special/(
+ special/)
+ special/[
+ special/]
+ special/{
+ special/}
+
+ special/test{1}/file[1]
+ ]
+
+ platform_is_not :windows do
+ @mock_dir_files += %w[
+ special/*
+ special/?
+
+ special/|
+ ]
+ end
+ end
+
+ @mock_dir_files
+ end
+
+ def self.create_mock_dirs
+ umask = File.umask 0
+ mock_dir_files.each do |name|
+ file = File.join mock_dir, name
+ mkdir_p File.dirname(file)
+ touch file
+ end
+ File.umask umask
+ end
+
+ def self.delete_mock_dirs
+ rm_r mock_dir
+ end
+
+ def self.expected_paths
+ unless @expected_paths
+ @expected_paths = %w[
+ .dotfile
+
+ .dotsubdir
+ .dotsubdir/.dotfile
+ .dotsubdir/nondotfile
+
+ deeply
+ deeply/.dotfile
+
+ deeply/nested
+ deeply/nested/.dotfile.ext
+
+ deeply/nested/directory
+
+ deeply/nested/directory/structure
+ deeply/nested/directory/structure/.ext
+ deeply/nested/directory/structure/bar
+ deeply/nested/directory/structure/baz
+ deeply/nested/directory/structure/file_one
+ deeply/nested/directory/structure/file_one.ext
+ deeply/nested/directory/structure/foo
+ deeply/nondotfile
+
+ file_one.ext
+ file_two.ext
+
+ dir_filename_ordering
+
+ dir
+ dir/filename_ordering
+
+ nondotfile
+
+ subdir_one
+ subdir_one/.dotfile
+ subdir_one/nondotfile
+
+ subdir_two
+ subdir_two/nondotfile
+ subdir_two/nondotfile.ext
+
+ brace
+ brace/a
+ brace/a.js
+ brace/a.erb
+ brace/a.js.rjs
+ brace/a.html.erb
+
+ special
+ special/+
+
+ special/^
+ special/$
+
+ special/(
+ special/)
+ special/[
+ special/]
+ special/{
+ special/}
+
+ special/test{1}
+ special/test{1}/file[1]
+ ]
+
+ platform_is_not :windows do
+ @expected_paths += %w[
+ special/*
+ special/?
+
+ special/|
+ ]
+ end
+
+ @expected_paths.map! do |file|
+ File.join(mock_dir, file)
+ end
+
+ @expected_paths << mock_dir
+ @expected_paths.sort!
+ end
+
+ @expected_paths
+ end
+end
diff --git a/spec/rubyspec/library/find/prune_spec.rb b/spec/rubyspec/library/find/prune_spec.rb
new file mode 100644
index 0000000000..1aef7d3d23
--- /dev/null
+++ b/spec/rubyspec/library/find/prune_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'find'
+
+describe "Find.prune" do
+ it "should throw :prune" do
+ msg = catch(:prune) do
+ Find.prune
+ end
+
+ msg.should == nil
+ end
+end