file-find 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d99bb72ba56fc51995a186e6f06869318c1f29b1965d49d8aa42853aa341bf57
4
- data.tar.gz: c04db8e76c5a4ab4f953a373a6d089379cf4f99064ec18883a70ed7db1d82963
3
+ metadata.gz: f6a005f38ff57e7ecba774576e6d8d8c005a386b50ec65197c4047cdd156d876
4
+ data.tar.gz: 50c000e4e15dd13bdab23fc396d0062ccc5392efd808036cc3df0a512f6ced50
5
5
  SHA512:
6
- metadata.gz: bac0f7a26c507ae51dd15a19611bb0af91f43a93a717cf32a0c6787b244abb4680b8b12372525b51635696a4aa2c11f312107c1374c16f5f891c7d53cba111d8
7
- data.tar.gz: d27462d46d37ad567c9d7eaa29cadd7962e08066850d75a4b35983feb0a81a03ad63e224b10348099da0ffe74992b4604a576099dd1fde4f81f401d678d9baf5
6
+ metadata.gz: '09d5c030c2312a89f03c21a69578ab08d437890151f943f37ebcf27cd62d51fb42694f833605207afbf8c2e6aeb2a7d852f9373a6bc251b5336d0933b6a0f082'
7
+ data.tar.gz: c2c7b029ba2fdf2ea2760e84ee5600ef5fa1670922d01924773688854edb9a7e2eee6b32581c25861ff5095c984c53ec86ffa54e7f4b71a3fda73d7dca732a26
@@ -1,6 +1,2 @@
1
- h��߼�ɢ ϵ�g�Ï���o �($��� �>�u��J����D'���� ���nO�am ����>�)��z+������?ސ����^O��"Ѫ >v�d�O&��^�_9��/����:;µu
2
- xߎ\���Iv2U��
3
- ~��ẖq���B9AH�麋EPu�i��w3��楚2�M��Ӆ�>k�(� ?��2�� �$y�j�Gu]�0J�z���#�,�'>�
4
- ��9���'�~�� RJE}�8{'�λ[�*ߗ
5
- b����۳w��X{�ţ;xE�%
6
- �9po�'���� k e~�Oi��Nۡ��@,����HsV�nJj�w��uD
1
+ �Uw�!W�A����� I�K�(�kG�/�5С��[4yeW��}��,Va�a=�@�0�����\�yU%,��$��f_HA��c�ʣ��u� nu7��.��M���4{�@��{ed/�3��D�r�iq�b�f�X+�����^�� �����e���e���,��'ac��yU�a�(�g�e���2#���!B�d�F��vr�����Fod�~�˜��܇C ,�DJjAW�]��,w�|�s�ֶHf'����+x�_ݼX���Ҷ��h�
2
+ )f�Y_C� 4��#a���a'|%*�CiimuƄhz
data.tar.gz.sig CHANGED
Binary file
@@ -1,25 +1,36 @@
1
- == 0.4.3 - 8-Jun-2020
1
+ ## 0.5.0 - 19-Jan-2021
2
+ * Switched from test-unit to rspec, with an added development
3
+ dependency on the fakefs gem.
4
+ * Switched from rdoc to markdown because github doesn't render rdoc
5
+ properly any more.
6
+ * Fixed a bug in the maxdepth option with root paths.
7
+ * Added a Gemfile.
8
+
9
+ ## 0.4.4 - 6-Aug-2020
10
+ * Added .rdoc extensions to the CHANGES, README and MANIFEST files.
11
+
12
+ ## 0.4.3 - 8-Jun-2020
2
13
  * Fixed a bug with ELOOP handling. Thanks go to joast for the spot and fix.
3
14
 
4
- == 0.4.2 - 6-May-2020
15
+ ## 0.4.2 - 6-May-2020
5
16
  * Added LICENSE file as required by the Apache-2.0 license.
6
17
 
7
- == 0.4.1 - 23-Jan-2019
18
+ ## 0.4.1 - 23-Jan-2019
8
19
  * Added metadata to the gemspec.
9
20
 
10
- == 0.4.0 - 26-Dec-2018
21
+ ## 0.4.0 - 26-Dec-2018
11
22
  * License changed to Apache-2.0.
12
23
  * Fixed a bug where mindepth and maxdepth would break if more than one
13
24
  path was specified as part of the rule. Thanks go to flagos for the spot.
14
25
  * The VERSION constant is now frozen.
15
26
  * The cert has been updated.
16
27
 
17
- == 0.3.9 - 16-Dec-2015
28
+ ## 0.3.9 - 16-Dec-2015
18
29
  * This gem is now signed.
19
30
  * Added a file-find.rb file for convenience.
20
31
  * Updates to the Rakefile and gemspec.
21
32
 
22
- == 0.3.8 - 12-Feb-2014
33
+ ## 0.3.8 - 12-Feb-2014
23
34
  * Removed all references to the Etc module since the sys-admin library now uses
24
35
  FFI and works with JRuby.
25
36
  * The :user, :group, and :inum options will now work on MS Windows if you have
@@ -29,27 +40,27 @@
29
40
  * Some tests that were previously omitted on Windows are now included.
30
41
  * Updates to the test suite, readme, etc.
31
42
 
32
- == 0.3.7 - 15-Jan-2014
43
+ ## 0.3.7 - 15-Jan-2014
33
44
  * Fixed a bug with brackets in the path name. Thanks go to Jeremy Lawler
34
45
  for the spot and the patch.
35
46
 
36
- == 0.3.6 - 6-Sep-2013
47
+ ## 0.3.6 - 6-Sep-2013
37
48
  * Removed rbconfig from library and test file. Just use File::ALT_SEPARATOR
38
49
  to check for Windows instead.
39
50
  * Removed unused variables.
40
51
  * Updated dev dependencies.
41
52
 
42
- == 0.3.5 - 15-Jul-2011
53
+ ## 0.3.5 - 15-Jul-2011
43
54
  * Fixed a bug with the :follow option.
44
55
  * Gemspec, Rakefile and test cleanup.
45
56
 
46
- == 0.3.4 - 19-Sep-2009
57
+ ## 0.3.4 - 19-Sep-2009
47
58
  * Fixed a packaging bug. Thanks go to Gabriel Horner for the spot.
48
59
  * Added the 'gem' task to the Rakefile for building the gem. Removed the
49
60
  gem builder code that was in the gemspec itself.
50
61
  * Updated the dependency for sys-admin to 1.5.2.
51
62
 
52
- == 0.3.3 - 3-Aug-2009
63
+ ## 0.3.3 - 3-Aug-2009
53
64
  * Now compatible with Ruby 1.9.x.
54
65
  * Added support for the :links option
55
66
  * Updated the :mount accessor to work properly if the value is changed
@@ -58,35 +69,35 @@
58
69
  * Added a fuller description to the gemspec.
59
70
  * Minor test refactoring.
60
71
 
61
- == 0.3.2 - 20-Feb-2009
72
+ ## 0.3.2 - 20-Feb-2009
62
73
  * Added support for the :mount option.
63
74
  * Added some basic tests for the :mount option.
64
75
 
65
- == 0.3.1 - 9-Jan-2009
76
+ ## 0.3.1 - 9-Jan-2009
66
77
  * Now defaults to using Etc instead of Sys::Admin for implementations
67
78
  that don't support building C extensions, e.g. JRuby.
68
79
  * Updated the test suite to work with JRuby.
69
80
  * Minor optimizations for symbolic perms and atime/ctime/mtime checks.
70
81
  Thanks go in part to Ryan Davis' flay library.
71
82
 
72
- == 0.3.0 - 30-Dec-2008
83
+ ## 0.3.0 - 30-Dec-2008
73
84
  * Added support for FileTest operations. All options passed to the constructor
74
85
  that end with '?' are now validated and treated as FileTest operations.
75
86
 
76
- == 0.2.5 - 29-Dec-2008
87
+ ## 0.2.5 - 29-Dec-2008
77
88
  * Added maxdepth and mindepth support.
78
89
  * Added a 'clean' rake task to cleanup any test-unit results files.
79
90
 
80
- == 0.2.4 - 10-Dec-2008
91
+ ## 0.2.4 - 10-Dec-2008
81
92
  * Added support for symbolic permissions. Thanks go to Bill Kleb for the
82
93
  suggestion and to Hal Fulton for providing the solution.
83
94
 
84
- == 0.2.3 - 25-Nov-2008
95
+ ## 0.2.3 - 25-Nov-2008
85
96
  * Added mtime support. My previous concerns, which I believe stemmed from
86
97
  the find(2) man page on Solaris 10 with regards to atime checks modifying
87
98
  the mtime, appear have been unfounded.
88
99
 
89
- == 0.2.2 - 19-Nov-2008
100
+ ## 0.2.2 - 19-Nov-2008
90
101
  * The :user and :group options now accept a name or a numeric id. Thanks go
91
102
  to Bill Kleb for the suggestion.
92
103
  * Fixed yet another path bug for MS Windows.
@@ -95,23 +106,23 @@
95
106
  * Added sys-admin and test-unit as prerequisites.
96
107
  * Added tests for the :user and :group options.
97
108
 
98
- == 0.2.1 - 4-Oct-2007
109
+ ## 0.2.1 - 4-Oct-2007
99
110
  * Added the File::Find#previous method, which lets you see the previous
100
111
  match, if any.
101
112
  * Path name bug fix for MS Windows.
102
113
  * Test suite bug fixes for MS Windows (perm test now skipped).
103
114
  * Inaccessible directories are now skipped instead of raising an error.
104
115
 
105
- == 0.2.0 - 26-Apr-2007
116
+ ## 0.2.0 - 26-Apr-2007
106
117
  * Fixed a bug where it was not traversing subdirectories.
107
118
  * Added support for the perm and prune options.
108
119
 
109
- == 0.1.1 - 25-Apr-2007
120
+ ## 0.1.1 - 25-Apr-2007
110
121
  * The default for name is now '*', i.e. everything.
111
122
  * Fixed a bug where directories were not matched. Thanks go to Leslie Viljoen
112
123
  for the spot.
113
124
  * The size option now accepts strings with comparable operators. For example,
114
125
  you can now look for files greater than 400 bytes with the string "> 400".
115
126
 
116
- == 0.1.0 - 24-Apr-2007
127
+ ## 0.1.0 - 24-Apr-2007
117
128
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org' do
2
+ gemspec
3
+ end
@@ -1,6 +1,7 @@
1
- * CHANGES
2
- * LICENSE
3
- * MANIFEST
1
+ * CHANGES.md
2
+ * Gemfile
3
+ * LICENSE.md
4
+ * MANIFEST.md
4
5
  * Rakefile
5
6
  * README
6
7
  * file-find.gemspec
@@ -1,15 +1,15 @@
1
- = Description
1
+ ## Description
2
2
 
3
3
  This is a drop-in replacement for the find module currently in the standard
4
4
  library. It is modeled on a typical 'find' command found on most Unix systems.
5
5
 
6
- = Installation
6
+ ## Installation
7
7
 
8
- gem install file-find
8
+ `gem install file-find`
9
9
 
10
- = Synopsis
11
-
12
- require 'file/find'
10
+ ## Synopsis
11
+ ```ruby
12
+ require 'file/find' # 'file-find' also works
13
13
 
14
14
  rule = File::Find.new(
15
15
  :pattern => "*.rb",
@@ -20,15 +20,16 @@ gem install file-find
20
20
  rule.find{ |f|
21
21
  puts f
22
22
  }
23
+ ```
23
24
 
24
- = Rationale
25
+ ## Rationale
25
26
 
26
27
  The current find module in the standard library is inadequate. It is, quite
27
28
  frankly, not much more than a plain Dir.glob call. This library provides an
28
29
  interface based on options typically available on your command line 'find'
29
30
  command, thus allowing you much greater control over how you find your files.
30
31
 
31
- = Options
32
+ ## Options
32
33
 
33
34
  * atime
34
35
  * ctime
@@ -47,18 +48,18 @@ command, thus allowing you much greater control over how you find your files.
47
48
  * size
48
49
  * user (name or id)
49
50
 
50
- In addition to the above options, FileTest methods such as 'readable?' and
51
- 'writable?' may be used as keys, with true or false for their values.
51
+ In addition to the above options, `FileTest` methods such as `readable?` and
52
+ `writable?` may be used as keys, with true or false for their values.
52
53
 
53
- See the RDoc documentation for more details about these options.
54
+ See the documentation for more details about these options.
54
55
 
55
- = Future Plans
56
+ ## Future Plans
56
57
 
57
58
  None at this time. Please log any feature requests on the project page at:
58
59
 
59
60
  http://github.com/djberg96/file-find
60
61
 
61
- = Options I won't support
62
+ ## Options I won't support
62
63
 
63
64
  Generally speaking, anything that would require mucking around with C code
64
65
  or is just too difficult to implement in a cross platform manner will not be
@@ -74,35 +75,35 @@ supported. These include the following options:
74
75
 
75
76
  * ok - This is not interactive software.
76
77
 
77
- = Known Issues
78
+ ## Known Issues
78
79
 
79
- The :perm option is limited to 0644 and 0444 on MS Windows.
80
+ The `:perm` option is limited to 0644 and 0444 on MS Windows.
80
81
 
81
- The :user, :group, and :inum options require the win32-file gem to work
82
- properly on MS Windows. However, it is not officially a dependency.
82
+ The `:user`, `:group`, and `:inum` options require the win32-file gem to work
83
+ properly on MS Windows. However, win32-file is not officially a dependency.
83
84
 
84
- = Bugs
85
+ ## Bugs
85
86
 
86
87
  None that I'm aware of beyond the ones mentioned in the Known Issues. Please
87
88
  log any bug reports on the project page at:
88
89
 
89
90
  http://github.com/djberg96/file-find
90
91
 
91
- = Acknowledgements
92
+ ## Acknowledgements
92
93
 
93
94
  * Richard Clamp's File::Find::Rule Perl module for additional ideas and
94
95
  inspiration.
95
96
  * Bill Kleb for ideas regarding name, group and perm enhancements.
96
97
  * Hal Fulton for his implementation of symbolic permissions.
97
98
 
98
- = License
99
+ ## License
99
100
 
100
101
  Apache-2.0
101
102
 
102
- = Copyright
103
+ ## Copyright
103
104
 
104
- (C) 2007-2020, Daniel J. Berger, All Rights Reserved
105
+ (C) 2007-2021, Daniel J. Berger, All Rights Reserved
105
106
 
106
- = Author
107
+ ## Author
107
108
 
108
109
  Daniel J. Berger
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
4
 
5
5
  CLEAN.include("**/*.gem", "**/*.rbc", "**/link*")
6
6
 
@@ -21,10 +21,8 @@ namespace :gem do
21
21
  end
22
22
  end
23
23
 
24
- Rake::TestTask.new do |t|
25
- task :test => 'clean'
26
- t.warning = true
27
- t.verbose = true
24
+ RSpec::Core::RakeTask.new(:spec) do |t|
25
+ t.pattern = ['spec/file_find_spec.rb']
28
26
  end
29
27
 
30
- task :default => :test
28
+ task :default => :spec
@@ -2,29 +2,28 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-find'
5
- spec.version = '0.4.4'
5
+ spec.version = '0.5.0'
6
6
  spec.author = 'Daniel Berger'
7
7
  spec.license = 'Apache-2.0'
8
8
  spec.summary = 'A better way to find files'
9
9
  spec.email = 'djberg96@gmail.com'
10
10
  spec.homepage = 'http://github.com/djberg96/file-find'
11
- spec.test_file = 'test/test_file_find.rb'
11
+ spec.test_file = 'spec/file_find_spec.rb'
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = Dir['certs/*']
14
14
 
15
- spec.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc', 'MANIFEST.rdoc']
16
-
17
15
  spec.metadata = {
18
16
  'homepage_uri' => 'https://github.com/djberg96/file-find',
19
17
  'bug_tracker_uri' => 'https://github.com/djberg96/file-find/issues',
20
- 'changelog_uri' => 'https://github.com/djberg96/file-find/blob/master/CHANGES',
18
+ 'changelog_uri' => 'https://github.com/djberg96/file-find/blob/master/CHANGES.md',
21
19
  'documentation_uri' => 'https://github.com/djberg96/file-find/wiki',
22
20
  'source_code_uri' => 'https://github.com/djberg96/file-find',
23
21
  'wiki_uri' => 'https://github.com/djberg96/file-find/wiki'
24
22
  }
25
23
 
26
- spec.add_dependency('sys-admin', '>= 1.6.0')
27
- spec.add_development_dependency('test-unit')
24
+ spec.add_dependency('sys-admin', '~> 1.7')
25
+ spec.add_development_dependency('rspec', '~> 3.9')
26
+ spec.add_development_dependency('fakefs', '~> 1.3')
28
27
  spec.add_development_dependency('rake')
29
28
 
30
29
  spec.description = <<-EOF
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  class File::Find
11
11
  # The version of the file-find library
12
- VERSION = '0.4.4'.freeze
12
+ VERSION = '0.5.0'.freeze
13
13
 
14
14
  # :stopdoc:
15
15
  VALID_OPTIONS = %w[
@@ -241,8 +241,9 @@ class File::Find
241
241
  end
242
242
  end
243
243
 
244
- # We need to escape any brackets in the directory name.
245
- glob = File.join(File.dirname(file).gsub(/([\[\]])/,'\\\\\1'), @name)
244
+ # We need to escape any brackets in the directory name, unless already escaped.
245
+ temp = File.dirname(file).gsub(/(?<!\\)([\[\]])/, '\\\\\1')
246
+ glob = File.join(temp, @name)
246
247
 
247
248
  # Dir[] doesn't like backslashes
248
249
  if File::ALT_SEPARATOR
@@ -259,7 +260,7 @@ class File::Find
259
260
  end
260
261
 
261
262
  if @maxdepth || @mindepth
262
- file_depth = file.split(File::SEPARATOR).length
263
+ file_depth = file.split(File::SEPARATOR).reject{ |e| e.size.zero? }.length
263
264
  current_base_path = [@path].flatten.find{ |tpath| file.include?(tpath) }
264
265
  path_depth = current_base_path.split(File::SEPARATOR).length
265
266
 
@@ -0,0 +1,613 @@
1
+ ######################################################################
2
+ # file_find_spec.rb
3
+ #
4
+ # Test case for the file-find library. You should run this via the
5
+ # 'rake spec' task.
6
+ ######################################################################
7
+ require 'rspec'
8
+ require 'file-find'
9
+ require 'sys-admin'
10
+ require 'pp' # stops fakefs class mismatch errors
11
+ require 'tmpdir'
12
+ require 'fakefs/spec_helpers'
13
+
14
+ RSpec.describe File::Find do
15
+ include FakeFS::SpecHelpers
16
+
17
+ let(:windows) { File::ALT_SEPARATOR }
18
+ let(:ruby_file) { 'file_find_test.rb' }
19
+ let(:doc_file) { 'file_find_test.doc' }
20
+ let(:text_file1) { 'file_find_test1.txt' }
21
+ let(:text_file2) { 'file_find_test2.txt' }
22
+
23
+ let(:rule) { File::Find.new }
24
+ let(:txt_rule) { File::Find.new(:name => '*.txt') }
25
+
26
+ before(:all) do
27
+ @loguser = Sys::Admin.get_user(Sys::Admin.get_login)
28
+ @logroup = Sys::Admin.get_group(@loguser.gid)
29
+ end
30
+
31
+ context "constants", :constants => true do
32
+ example "version constant is set to expected value" do
33
+ expect(File::Find::VERSION).to eq('0.5.0')
34
+ expect(File::Find::VERSION).to be_frozen
35
+ end
36
+ end
37
+
38
+ context "path", :path => true do
39
+ example "path accessor basic functionality" do
40
+ expect(rule).to respond_to(:path)
41
+ expect(rule).to respond_to(:path=)
42
+ end
43
+
44
+ example "path method returns expected value" do
45
+ expect(rule.path).to eq(Dir.pwd)
46
+ end
47
+ end
48
+
49
+ context "options", :options => true do
50
+ example "options accessor basic functionality" do
51
+ expect(rule).to respond_to(:options)
52
+ expect(rule).to respond_to(:options=)
53
+ end
54
+
55
+ example "options method returns expected value" do
56
+ expect(txt_rule.options).to eq({:name => '*.txt'})
57
+ end
58
+ end
59
+
60
+ context "atime", :atime => true do
61
+ before do
62
+ FileUtils.touch(ruby_file)
63
+ end
64
+
65
+ example "atime accessor basic functionality" do
66
+ expect(rule).to respond_to(:atime)
67
+ expect(rule).to respond_to(:atime=)
68
+ end
69
+
70
+ example "atime method returns expected default value" do
71
+ expect(rule.atime).to be_nil
72
+ end
73
+
74
+ example "find with atime option works as expected" do
75
+ rule1 = File::Find.new(:name => "*.rb", :atime => 0)
76
+ rule2 = File::Find.new(:name => "*.rb", :atime => 1)
77
+
78
+ expect(rule1.find.empty?).to be false
79
+ expect(rule2.find.empty?).to be true
80
+ end
81
+ end
82
+
83
+ context "ctime", :ctime => true do
84
+ before do
85
+ FileUtils.touch(ruby_file)
86
+ end
87
+
88
+ example "ctime accessor basic functionality" do
89
+ expect(rule).to respond_to(:ctime)
90
+ expect(rule).to respond_to(:ctime=)
91
+ end
92
+
93
+ example "ctime method returns expected default value" do
94
+ expect(rule.ctime).to be_nil
95
+ end
96
+
97
+ example "find with ctime option works as expected" do
98
+ rule1 = File::Find.new(:name => "*.rb", :ctime => 0)
99
+ rule2 = File::Find.new(:name => "*.rb", :ctime => 1)
100
+
101
+ expect(rule1.find.empty?).to be false
102
+ expect(rule2.find.empty?).to be true
103
+ end
104
+ end
105
+
106
+ context "find", :find => true do
107
+ example "find method basic functionality" do
108
+ expect(rule).to respond_to(:find)
109
+ expect{ rule.find }.not_to raise_error
110
+ end
111
+
112
+ example "find method returns expected value" do
113
+ expect(rule.find).to be_kind_of(Array)
114
+ expect(rule.find{}).to be_nil
115
+ end
116
+ end
117
+
118
+ context "filetest", :filetest => true do
119
+ before do
120
+ FileUtils.touch(doc_file, :mode => 0644)
121
+ end
122
+
123
+ example "filetest accessor basic functionality" do
124
+ expect(rule).to respond_to(:filetest)
125
+ expect(rule).to respond_to(:filetest=)
126
+ expect{ rule.filetest }.not_to raise_error
127
+ end
128
+
129
+ example "filetest method returns expected value" do
130
+ expect(rule.filetest).to be_kind_of(Array)
131
+ end
132
+
133
+ example "valid filetest options work as expected" do
134
+ expect{ File::Find.new(:readable? => true) }.not_to raise_error
135
+ expect{ File::Find.new(:writable? => true) }.not_to raise_error
136
+ end
137
+
138
+ example "find method works with filetest option" do
139
+ rule = File::Find.new(:name => "*.doc", :writable? => true)
140
+
141
+ expect(rule.find.map{ |f| File.basename(f) }).to eq([doc_file])
142
+ FileUtils.chmod(0444, doc_file)
143
+ expect(rule.find).to eq([])
144
+ end
145
+ end
146
+
147
+ context "mtime", :mtime => true do
148
+ before do
149
+ FileUtils.touch(ruby_file)
150
+ end
151
+
152
+ example "mtime accessor basic functionality" do
153
+ expect(rule).to respond_to(:mtime)
154
+ expect(rule).to respond_to(:mtime=)
155
+ end
156
+
157
+ example "mtime method returns expected default value" do
158
+ expect(rule.mtime).to be_nil
159
+ end
160
+
161
+ example "find with mtime option works as expected" do
162
+ rule1 = File::Find.new(:name => "*.rb", :mtime => 0)
163
+ rule2 = File::Find.new(:name => "*.rb", :mtime => 1)
164
+
165
+ expect(rule1.find.empty?).to be false
166
+ expect(rule2.find.empty?).to be true
167
+ end
168
+ end
169
+
170
+ context "ftype", :ftype => true do
171
+ before do
172
+ FileUtils.touch(ruby_file)
173
+ end
174
+
175
+ example "ftype accessor basic functionality" do
176
+ expect(rule).to respond_to(:ftype)
177
+ expect(rule).to respond_to(:ftype=)
178
+ end
179
+
180
+ example "ftype method returns expected default value" do
181
+ expect(rule.ftype).to be_nil
182
+ end
183
+
184
+ example "ftype method works as expected" do
185
+ rule1 = File::Find.new(:name => "*.rb", :ftype => "file")
186
+ rule2 = File::Find.new(:name => "*.rb", :ftype => "characterSpecial")
187
+
188
+ expect(rule1.find.empty?).to be false
189
+ expect(rule2.find.empty?).to be true
190
+ end
191
+ end
192
+
193
+ context "group", :group => true do
194
+ before do
195
+ FileUtils.touch(doc_file)
196
+ end
197
+
198
+ example "group accessor basic functionality" do
199
+ expect(rule).to respond_to(:group)
200
+ expect(rule).to respond_to(:group=)
201
+ end
202
+
203
+ example "group method returns expected default value" do
204
+ expect(rule.group).to be_nil
205
+ end
206
+
207
+ # TODO: Update example for Windows
208
+ example "find with numeric group id works as expected" do
209
+ skip 'group example skipped on MS Windows' if windows
210
+ rule = File::Find.new(:name => '*.doc', :group => @loguser.gid)
211
+ expect(rule.find).to eq([File.expand_path(doc_file)])
212
+ end
213
+
214
+ # TODO: Update example for Windows
215
+ example "find with string group id works as expected" do
216
+ skip 'group example skipped on MS Windows' if windows
217
+
218
+ rule = File::Find.new(:name => '*.doc', :group => @logroup.name)
219
+ expect(rule.find).to eq([File.expand_path(doc_file)])
220
+ end
221
+
222
+ example "find with bogus group returns empty results" do
223
+ skip 'group test skipped on MS Windows' if windows
224
+
225
+ rule1 = File::Find.new(:name => '*.doc', :group => 'totallybogus')
226
+ rule2 = File::Find.new(:name => '*.doc', :group => 99999999)
227
+ expect(rule1.find).to eq([])
228
+ expect(rule2.find).to eq([])
229
+ end
230
+ end
231
+
232
+ context "inum", :inum => true do
233
+ example "inum accessor basic functionality" do
234
+ expect(rule).to respond_to(:inum)
235
+ expect(rule).to respond_to(:inum=)
236
+ end
237
+
238
+ example "inum method returns expected default value" do
239
+ expect(rule.inum).to be_nil
240
+ end
241
+ end
242
+
243
+ context "follow", :follow => true do
244
+ example "follow accessor basic functionality" do
245
+ expect(rule).to respond_to(:follow)
246
+ expect(rule).to respond_to(:follow=)
247
+ end
248
+
249
+ example "follow method returns expected default value" do
250
+ expect(rule.follow).to be true
251
+ end
252
+ end
253
+
254
+ context "links", :links => true do
255
+ before do
256
+ FileUtils.touch(ruby_file)
257
+ FileUtils.touch(doc_file)
258
+ end
259
+
260
+ example "links accessor basic functionality" do
261
+ expect(rule).to respond_to(:links)
262
+ expect(rule).to respond_to(:links=)
263
+ end
264
+
265
+ example "links method returns expected default value" do
266
+ expect(rule.links).to be_nil
267
+ end
268
+
269
+ example "links method returns expected result" do
270
+ # skip if @@windows && !@@elevated # TODO: Update
271
+
272
+ rule1 = File::Find.new(:name => '*.rb', :links => 2)
273
+ rule2 = File::Find.new(:name => '*.doc', :links => 1)
274
+
275
+ expect(rule1.find).to eq([])
276
+ expect(rule2.find).to eq([File.expand_path(doc_file)])
277
+ end
278
+ end
279
+
280
+ context "brackets", :brackets => true do
281
+ before do
282
+ allow(FakeFS::FileSystem).to receive(:find).and_call_original
283
+ allow(FakeFS::FileSystem).to receive(:find).with(anything, 0, false)
284
+ end
285
+
286
+ example "find method works on dirs that contain brackets" do
287
+ skip 'dirs with brackets example skipped on MS Windows' if windows
288
+
289
+ # We use absolute paths here because of fakefs, which converts it anyway
290
+ bracket_files = ['/bracket/a[1]/a.foo', '/bracket/a [2] /b.foo', '/bracket/[a] b [c]/d.foo' ]
291
+ bracket_paths = ['/bracket/a[1]', '/bracket/a [2] ', '/bracket/[a] b [c]', '/bracket/[z] x' ]
292
+
293
+ bracket_paths.each{ |e| FakeFS::FileSystem.add(e) }
294
+ bracket_files.each{ |e| FileUtils.touch(e) }
295
+
296
+ file_rule = File::Find.new(
297
+ :ftype => 'file',
298
+ :path => ['/bracket']
299
+ )
300
+
301
+ dir_rule = File::Find.new(
302
+ :ftype => 'directory',
303
+ :path => ['/bracket']
304
+ )
305
+
306
+ file_results = file_rule.find
307
+ dir_results = dir_rule.find
308
+
309
+ expect(file_results).to match_array(bracket_files)
310
+ expect(dir_results).to match_array(bracket_paths)
311
+ end
312
+ end
313
+
314
+ context "maxdepth", :maxdepth => true do
315
+ before do
316
+ fs = FakeFS::FileSystem.add('a1/a2/a3')
317
+ rule.pattern = "*.foo"
318
+
319
+ FileUtils.touch('a1/a.foo')
320
+ FileUtils.touch('a1/a2/b.foo')
321
+ FileUtils.touch('a1/a2/c.foo')
322
+ FileUtils.touch('a1/a2/a3/d.foo')
323
+ FileUtils.touch('a1/a2/a3/e.foo')
324
+ FileUtils.touch('a1/a2/a3/f.foo')
325
+ end
326
+
327
+ example "maxdepth_basic" do
328
+ expect(rule).to respond_to(:maxdepth)
329
+ expect(rule).to respond_to(:maxdepth=)
330
+ expect(rule.maxdepth).to be_nil
331
+ end
332
+
333
+ example "find with maxdepth option returns expected results" do
334
+ rule.maxdepth = 1
335
+
336
+ expect(rule.find).to eq([])
337
+
338
+ rule.maxdepth = 2
339
+ expect(rule.find.map{ |e| File.basename(e) }).to eq(['a.foo'])
340
+
341
+ rule.maxdepth = 3
342
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(['a.foo', 'b.foo', 'c.foo'])
343
+ end
344
+
345
+ example "find with nil maxdepth option returns everything" do
346
+ rule.maxdepth = nil
347
+ results = ['a.foo', 'b.foo', 'c.foo', 'd.foo', 'e.foo', 'f.foo']
348
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(results)
349
+ end
350
+
351
+ example "find with maxdepth option returns expected results for directories" do
352
+ rule.pattern = "a3"
353
+
354
+ rule.maxdepth = 1
355
+ expect(rule.find).to eq([])
356
+
357
+ rule.maxdepth = 2
358
+ expect(rule.find).to eq([])
359
+
360
+ rule.maxdepth = 3
361
+ expect(rule.find.map{ |e| File.basename(e) }).to eq(['a3'])
362
+ end
363
+ end
364
+
365
+ context "mindepth", :mindepth => true do
366
+ before do
367
+ fs = FakeFS::FileSystem.add('a1/a2/a3')
368
+ rule.pattern = "*.min"
369
+
370
+ FileUtils.touch('z.min')
371
+ FileUtils.touch('a1/a.min')
372
+ FileUtils.touch('a1/a2/b.min')
373
+ FileUtils.touch('a1/a2/c.min')
374
+ FileUtils.touch('a1/a2/a3/d.min')
375
+ FileUtils.touch('a1/a2/a3/e.min')
376
+ FileUtils.touch('a1/a2/a3/f.min')
377
+ end
378
+
379
+ example "mindepth accessor basic functionality" do
380
+ expect(rule).to respond_to(:mindepth)
381
+ expect(rule).to respond_to(:mindepth=)
382
+ expect(rule.mindepth).to be_nil
383
+ end
384
+
385
+ example "mindepth method returns expected default value" do
386
+ expect(rule.mindepth).to be_nil
387
+ end
388
+
389
+ example "find with mindepth option returns expected results at depth 0" do
390
+ rule.mindepth = 0
391
+ array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min']
392
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
393
+ end
394
+
395
+ example "find with mindepth option returns expected results at depth 1" do
396
+ rule.mindepth = 1
397
+ array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min', 'z.min']
398
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
399
+ end
400
+
401
+ example "find with mindepth option returns expected results at depth 2" do
402
+ rule.mindepth = 2
403
+ array = ['a.min', 'b.min', 'c.min', 'd.min', 'e.min', 'f.min']
404
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
405
+ end
406
+
407
+ example "find with mindepth option returns expected results at depth 3" do
408
+ rule.mindepth = 3
409
+ array = ['b.min', 'c.min', 'd.min', 'e.min', 'f.min']
410
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
411
+ end
412
+
413
+ example "find with mindepth option returns expected results at depth 4" do
414
+ rule.mindepth = 4
415
+ array = ['d.min', 'e.min', 'f.min']
416
+ expect(rule.find.map{ |e| File.basename(e) }).to match_array(array)
417
+ end
418
+
419
+ example "find with mindepth option returns expected results at depth 5" do
420
+ rule.mindepth = 5
421
+ expect(rule.find.map{ |e| File.basename(e) }).to eq([])
422
+ end
423
+
424
+ example "find with mindepth option returns expected results for directories" do
425
+ rule.pattern = 'a1'
426
+ rule.mindepth = 1
427
+
428
+ expect(rule.find.map{ |e| File.basename(e) }).to eq(['a1'])
429
+
430
+ rule.mindepth = 2
431
+ expect(rule.find).to eq([])
432
+
433
+ rule.mindepth = 3
434
+ expect(rule.find).to eq([])
435
+ end
436
+ end
437
+
438
+ context "mount", :mount => true do
439
+ example "mount accessor basic functionality" do
440
+ expect(rule).to respond_to(:mount)
441
+ expect(rule).to respond_to(:mount=)
442
+ end
443
+
444
+ example "mount method returns expected default value" do
445
+ expect(rule.mount).to be_nil
446
+ end
447
+ end
448
+
449
+ context "name", :name => true do
450
+ example "name accessor basic functionality" do
451
+ expect(rule).to respond_to(:name)
452
+ expect(rule).to respond_to(:name=)
453
+ end
454
+
455
+ example "name method returns expected default value" do
456
+ expect(txt_rule.name).to eq('*.txt')
457
+ end
458
+
459
+ example "pattern is an alias for name" do
460
+ expect(rule.method(:name)).to eq(rule.method(:pattern))
461
+ expect(rule.method(:name=)).to eq(rule.method(:pattern=))
462
+ end
463
+ end
464
+
465
+ context "perm", :perm => true do
466
+ before do
467
+ FileUtils.touch(ruby_file)
468
+ FileUtils.touch(text_file1)
469
+ FileUtils.touch(text_file2)
470
+ File.chmod(0464, ruby_file)
471
+ File.chmod(0644, text_file1)
472
+ File.chmod(0644, text_file2)
473
+ end
474
+
475
+ example "perm accessor basic functionality" do
476
+ expect(rule).to respond_to(:perm)
477
+ expect(rule).to respond_to(:perm=)
478
+ end
479
+
480
+ example "perm method returns expected default value" do
481
+ expect(rule.perm).to be_nil
482
+ end
483
+
484
+ example "perm method returns expected results" do
485
+ results = File::Find.new(:name => "*test1*", :perm => 0644).find
486
+
487
+ expect(results.length).to eq(1)
488
+ expect(File.basename(results.first)).to eq(text_file1)
489
+ end
490
+
491
+ example "perm method works with symbolic permissions" do
492
+ skip 'symbolic perm spec skipped on MS Windows' if windows
493
+
494
+ results1 = File::Find.new(:name => "file*", :perm => "g=rw").find
495
+ results2 = File::Find.new(:name => "file*", :perm => "u=rw").find
496
+
497
+ expect(results1.length).to eq(1)
498
+ expect(results2.length).to eq(2)
499
+ expect(File.basename(results1.first)).to eq(ruby_file)
500
+ expect(results2.map{ |e| File.basename(e) }.sort).to eq([text_file1, text_file2])
501
+ end
502
+ end
503
+
504
+ context "prune", :prune => true do
505
+ before do
506
+ FileUtils.touch(text_file1)
507
+ end
508
+
509
+ example "prune accessor basic functionality" do
510
+ expect(rule).to respond_to(:prune)
511
+ expect(rule).to respond_to(:prune=)
512
+ end
513
+
514
+ example "prune method returns expected default value" do
515
+ expect(rule.prune).to be_nil
516
+ end
517
+
518
+ example "find method with prune option works as expected" do
519
+ rule = File::Find.new(:name => "*.txt", :prune => 'foo')
520
+ expect(File.basename(rule.find.first)).to eq(text_file1)
521
+ end
522
+ end
523
+
524
+ context "size", :size => true do
525
+ example "size accessor basic functionality" do
526
+ expect(rule).to respond_to(:size)
527
+ expect(rule).to respond_to(:size=)
528
+ end
529
+
530
+ example "size method returns expected default value" do
531
+ expect(rule.size).to be_nil
532
+ end
533
+ end
534
+
535
+ context "user", :user => true do
536
+ before do
537
+ FileUtils.touch(doc_file)
538
+ end
539
+
540
+ example "user accessor basic functionality" do
541
+ expect(rule).to respond_to(:user)
542
+ expect(rule).to respond_to(:user=)
543
+ end
544
+
545
+ example "user method returns expected default value" do
546
+ expect(rule.user).to be_nil
547
+ end
548
+
549
+ example "user method works with numeric id as expected" do
550
+ if windows && elevated
551
+ uid = @loguser.gid # Windows assigns the group if any member is an admin
552
+ else
553
+ uid = @loguser.uid
554
+ end
555
+
556
+ rule = File::Find.new(:name => '*.doc', :user => uid)
557
+ expect(rule.find).to eq([File.expand_path(doc_file)])
558
+ end
559
+
560
+ example "user method works with string as expected" do
561
+ skip if windows && elevated
562
+ rule = File::Find.new(:name => '*.doc', :user => @loguser.name)
563
+ expect(rule.find).to eq([File.expand_path(doc_file)])
564
+ end
565
+
566
+ example "find method with user option using invalid user returns expected results" do
567
+ rule1 = File::Find.new(:name => '*.doc', :user => 'totallybogus')
568
+ rule2 = File::Find.new(:name => '*.doc', :user => 99999999)
569
+ expect(rule1.find).to eq([])
570
+ expect(rule2.find).to eq([])
571
+ end
572
+ end
573
+
574
+ context "previous", :previous => true do
575
+ example "previous method basic functionality" do
576
+ expect(rule).to respond_to(:previous)
577
+ end
578
+ end
579
+
580
+ example "an error is raised if the path does not exist" do
581
+ expect{ File::Find.new(:path => '/bogus/dir').find }.to raise_error(Errno::ENOENT)
582
+ end
583
+
584
+ example "an error is raised if an invalid option is passed" do
585
+ expect{ File::Find.new(:bogus => 1) }.to raise_error(ArgumentError)
586
+ expect{ File::Find.new(:bogus? => true) }.to raise_error(ArgumentError)
587
+ end
588
+
589
+ context "eloop", :eloop => true do
590
+ # Have to disable fakefs for this test because of bug: https://github.com/fakefs/fakefs/issues/459
591
+ before do
592
+ FakeFS.deactivate!
593
+ end
594
+
595
+ # TODO: Update example for Windows
596
+ example 'eloop handling works as expected' do
597
+ skip 'eloop handling example skipped on MS Windows' if windows
598
+
599
+ Dir.chdir(Dir.mktmpdir) do
600
+ File.symlink('eloop0', 'eloop1')
601
+ File.symlink('eloop1', 'eloop0')
602
+ expected = ['./eloop0', './eloop1']
603
+
604
+ results = File::Find.new(:path => '.', :follow => true).find
605
+ expect(results.sort).to eq(expected)
606
+ end
607
+ end
608
+
609
+ after do
610
+ FakeFS.activate!
611
+ end
612
+ end
613
+ end