file-find 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODkxZjA0Y2IyNjQwOGJiMjVhYzBlOWM2MDJmNTU2YTA3YmRiNGVmZg==
5
- data.tar.gz: !binary |-
6
- MTlkYmUzYzBmOWE2Nzk0ZTVkMzk3OGU0NDZlZDg4MGM2MjRiN2I5OA==
2
+ SHA1:
3
+ metadata.gz: 0f07a119a3ad4179edcb7ea6dd0c0cfa0fd2efa9
4
+ data.tar.gz: 62762fc4f258b1174f673e198c5a6445bcf7a8d6
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjY4YzA4Y2I3ZTdkNWZmYWJmYTc1M2ZhMzQxOTk2MGJhOTllNmZjMzljMDUz
10
- ZmZhYTVlNTk4MDMwYjkwYjA1N2ZiNmE3ODllNDBjMjU3YjcxMmFjZDg5MTU2
11
- NWI3ZjkwMWQ5NjkyMDI4YzMxNjBiZjZkMjFjNDc5YzI3MTQ5NTk=
12
- data.tar.gz: !binary |-
13
- YjYyYTNmZGUyODI2OGZiZTA0MGJmYTg1OWFhOGFkMWY5Yjg5MjkyNmJkYjI1
14
- MjI3NzcwM2VkMzc5YTkwYmY0MmE2ZTlkYWQ4NTU1ZDBmN2YyZTA1MzYwYTY1
15
- NGQ2MmI3NmY4OWE4N2Q1MTk2NTM1OTI3YTQ2NjhjNWE5OTQ5MWM=
6
+ metadata.gz: f2f291fbd58a30acb7a0b8a9a58a00f90fea8466670428af17055dd3f499816ff014ac60641b66df409a0b4ec367158205c5b4f9cbfd73c426f3b7b0d7e6e83f
7
+ data.tar.gz: 6478327935c6eab676d1806d679e1ad26e920dbe6ff4e3663c2541f999bc5dfa01733e52364d0b3c6fd64fedeae40a14611bc21f178cce3d141a32a10f0689a7
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.3.8 - 12-Feb-2014
2
+ * Removed all references to the Etc module since the sys-admin library now uses
3
+ FFI and works with JRuby.
4
+ * The :user, :group, and :inum options will now work on MS Windows if you have
5
+ the win32-file gem installed.
6
+ * Fixed the perm option on Windows for its limited subset of available perms.
7
+ * You can now include a leading zero for the perm option if you wish.
8
+ * Some tests that were previously omitted on Windows are now included.
9
+ * Updates to the test suite, readme, etc.
10
+
1
11
  == 0.3.7 - 15-Jan-2014
2
12
  * Fixed a bug with brackets in the path name. Thanks go to Jeremy Lawler
3
13
  for the spot and the patch.
data/README CHANGED
@@ -2,6 +2,10 @@
2
2
  This is a drop-in replacement for the find module currently in the standard
3
3
  library. It is modeled on a typical 'find' command found on most Unix systems.
4
4
 
5
+ = Installation
6
+
7
+ gem install file-find
8
+
5
9
  = Synopsis
6
10
  require 'file/find'
7
11
 
@@ -15,12 +19,7 @@
15
19
  puts f
16
20
  }
17
21
 
18
- = Installation
19
-
20
- gem install file-find
21
-
22
22
  = Rationale
23
-
24
23
  The current find module in the standard library is inadequate. It is, quite
25
24
  frankly, not much more than a plain Dir.glob call. This library provides an
26
25
  interface based on options typically available on your command line 'find'
@@ -31,7 +30,7 @@
31
30
  * ctime
32
31
  * follow
33
32
  * ftype
34
- * inum (except Windows)
33
+ * inum
35
34
  * group (name or id)
36
35
  * maxdepth
37
36
  * mindepth
@@ -39,7 +38,7 @@
39
38
  * mtime
40
39
  * name (or 'pattern')
41
40
  * path
42
- * perm (except Windows)
41
+ * perm
43
42
  * prune
44
43
  * size
45
44
  * user (name or id)
@@ -50,15 +49,9 @@
50
49
  See the RDoc documentation for more details about these options.
51
50
 
52
51
  = Future Plans
53
- More options will be added as time permits, and requests will definitely be
54
- considered. Please log any feature requests on the project page at
55
- http://www.rubyforge.org/projects/shards.
52
+ None at this time. Please log any feature requests on the project page at:
56
53
 
57
- Some specific things I plan on adding:
58
-
59
- * exec
60
- * links
61
- * support for :user and :group on MS Windows
54
+ http://github.com/djberg96/file-find
62
55
 
63
56
  = Options I won't support
64
57
  Generally speaking, anything that would require mucking around with C code
@@ -78,13 +71,10 @@
78
71
  = Known Issues
79
72
  The mindepth and maxdepth options do not work for more than 1 path.
80
73
 
81
- The 'perm' option does not work on MS Windows, even for its limited subset of
82
- permissions, i.e. 664 and 666. This is arguably a bug in Ruby's
83
- File::Stat.mode method on MS Windows.
74
+ The :perm option is limited to 0644 and 0444 on MS Windows.
84
75
 
85
- The 'user' and 'group' options are not currently supported on MS Windows.
86
- This can be supported, but will require changes in the win32-file and
87
- win32-file-stat libraries (which would then become dependencies).
76
+ The :user, :group, and :inum options require the win32-file gem to work
77
+ properly on MS Windows. However, it is not officially a dependency.
88
78
 
89
79
  There are 3 test failures with JRuby, all related to the 'perm' option. I
90
80
  have not been able to reduce them to a simple test case and discern the
@@ -107,7 +97,7 @@
107
97
  Artistic 2.0
108
98
 
109
99
  = Copyright
110
- (C) 2007-2013, Daniel J. Berger, All Rights Reserved
100
+ (C) 2007-2014, Daniel J. Berger, All Rights Reserved
111
101
 
112
102
  = Author
113
103
  Daniel J. Berger
data/Rakefile CHANGED
@@ -8,12 +8,6 @@ namespace :gem do
8
8
  desc 'Create the file-find gem'
9
9
  task :create => [:clean] do
10
10
  spec = eval(IO.read('file-find.gemspec'))
11
- if RUBY_PLATFORM.match('java')
12
- spec.platform = Gem::Platform::CURRENT
13
- else
14
- spec.add_dependency('sys-admin', '>= 1.5.2')
15
- end
16
-
17
11
  if Gem::VERSION.to_f < 2.0
18
12
  Gem::Builder.new(spec).build
19
13
  else
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'file-find'
5
- spec.version = '0.3.7'
5
+ spec.version = '0.3.8'
6
6
  spec.author = 'Daniel Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.summary = 'A better way to find files'
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.rubyforge_project = 'shards'
15
15
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
16
 
17
- spec.add_development_dependency('test-unit', '>= 2.5.0')
18
- spec.add_development_dependency('sys-admin')
17
+ spec.add_dependency('sys-admin', '>= 1.6.0')
18
+ spec.add_development_dependency('test-unit')
19
19
  spec.add_development_dependency('rake')
20
20
 
21
21
  spec.description = <<-EOF
@@ -1,19 +1,18 @@
1
1
  require 'date'
2
+ require 'sys/admin'
2
3
 
3
- # For alternate implementations of Ruby, such as JRuby, that cannot
4
- # build C extensions fall back to the Etc module.
5
4
  begin
6
- require 'sys/admin'
5
+ require 'win32/file'
7
6
  rescue LoadError
8
- require 'etc'
7
+ # Do nothing, not required, just nicer.
9
8
  end
10
9
 
11
10
  class File::Find
12
11
  # The version of the file-find library
13
- VERSION = '0.3.7'
12
+ VERSION = '0.3.8'
14
13
 
15
14
  # :stopdoc:
16
- VALID_OPTIONS = %w/
15
+ VALID_OPTIONS = %w[
17
16
  atime
18
17
  ctime
19
18
  follow
@@ -32,7 +31,7 @@ class File::Find
32
31
  prune
33
32
  size
34
33
  user
35
- /
34
+ ]
36
35
  # :startdoc:
37
36
 
38
37
  # The starting path(s) for the search. The default is the current directory.
@@ -60,8 +59,6 @@ class File::Find
60
59
  # Limits searches to files that belong to a specific group, where the
61
60
  # group can be either a group name or ID.
62
61
  #
63
- # Not currently supported on MS Windows.
64
- #
65
62
  attr_accessor :group
66
63
 
67
64
  # An array of two element arrays for storing FileTest methods and their
@@ -80,8 +77,7 @@ class File::Find
80
77
  #
81
78
  attr_accessor :ftype
82
79
 
83
- # Limits search to a file with a specific inode number. Ignored on MS
84
- # Windows.
80
+ # Limits search to a file with a specific inode number.
85
81
  #
86
82
  attr_accessor :inum
87
83
 
@@ -117,12 +113,11 @@ class File::Find
117
113
 
118
114
  # Limits searches to files which have permissions that match the octal
119
115
  # value that you provide. For purposes of this comparison, only the user,
120
- # group, and world settings are used. Do not use a leading 0 in the values
121
- # that you supply, e.g. use 755 not 0755.
116
+ # group, and world settings are used.
122
117
  #
123
118
  # You may optionally use symbolic permissions, e.g. "g+rw", "u=rwx", etc.
124
119
  #
125
- # Not currently supported on MS Windows.
120
+ # MS Windows only recognizes two modes, 0644 and 0444.
126
121
  #
127
122
  attr_accessor :perm
128
123
 
@@ -140,8 +135,6 @@ class File::Find
140
135
  # Limits searches to files that belong to a specific user, where the user
141
136
  # can be either a user name or an ID.
142
137
  #
143
- # Not currently supported on MS Windows.
144
- #
145
138
  attr_accessor :user
146
139
 
147
140
  # The file that matched previously in the current search.
@@ -339,28 +332,35 @@ class File::Find
339
332
 
340
333
  if @group
341
334
  if @group.is_a?(String)
342
- next unless get_group(stat_info.gid).name == @group
335
+ if File::ALT_SEPARATOR
336
+ begin
337
+ next unless Sys::Admin.get_group(stat_info.gid, :LocalAccount => true).name == @group
338
+ rescue Sys::Admin::Error
339
+ next
340
+ end
341
+ else
342
+ begin
343
+ next unless Sys::Admin.get_group(stat_info.gid).name == @group
344
+ rescue Sys::Admin::Error
345
+ next
346
+ end
347
+ end
343
348
  else
344
349
  next unless stat_info.gid == @group
345
350
  end
346
351
  end
347
352
 
348
- unless File::ALT_SEPARATOR
349
- if @inum
350
- next unless stat_info.ino == @inum
351
- end
353
+ if @inum
354
+ next unless stat_info.ino == @inum
352
355
  end
353
356
 
354
- # This currently doesn't work on MS Windows, even in limited
355
- # fashion for 0666 and 0664, because File.stat.mode doesn't
356
- # return the proper value.
357
- #
357
+ # Note that only 0644 and 0444 are supported on MS Windows.
358
358
  if @perm
359
359
  if @perm.is_a?(String)
360
360
  octal_perm = sym2oct(@perm)
361
361
  next unless stat_info.mode & octal_perm == octal_perm
362
362
  else
363
- next unless sprintf("%o", stat_info.mode & 07777) == @perm.to_s
363
+ next unless sprintf("%o", stat_info.mode & 07777) == sprintf("%o", @perm)
364
364
  end
365
365
  end
366
366
 
@@ -385,7 +385,19 @@ class File::Find
385
385
 
386
386
  if @user
387
387
  if @user.is_a?(String)
388
- next unless get_user(stat_info.uid).name == @user
388
+ if File::ALT_SEPARATOR
389
+ begin
390
+ next unless Sys::Admin.get_user(stat_info.uid, :LocalAccount => true).name == @user
391
+ rescue Sys::Admin::Error
392
+ next
393
+ end
394
+ else
395
+ begin
396
+ next unless Sys::Admin.get_user(stat_info.uid).name == @user
397
+ rescue Sys::Admin::Error
398
+ next
399
+ end
400
+ end
389
401
  else
390
402
  next unless stat_info.uid == @user
391
403
  end
@@ -477,26 +489,4 @@ class File::Find
477
489
 
478
490
  perm
479
491
  end
480
-
481
- # Returns the group object based on the group id. Implemented for the
482
- # sake of platforms that cannot build extensions, such as JRuby.
483
- #
484
- def get_group(gid)
485
- if defined? Sys::Admin
486
- Sys::Admin.get_group(gid)
487
- else
488
- Etc.getgrgid(gid)
489
- end
490
- end
491
-
492
- # Returns the user object based on the group id. Implemented for the
493
- # sake of platforms that cannot build extensions, such as JRuby.
494
- #
495
- def get_user(uid)
496
- if defined? Sys::Admin
497
- Sys::Admin.get_user(uid)
498
- else
499
- Etc.getpwuid(uid)
500
- end
501
- end
502
492
  end
@@ -7,11 +7,11 @@
7
7
  require 'test-unit'
8
8
  require 'fileutils'
9
9
  require 'file/find'
10
+ require 'sys/admin'
10
11
 
11
- begin
12
- require 'sys/admin'
13
- rescue LoadError
14
- require 'etc'
12
+ if File::ALT_SEPARATOR
13
+ require 'win32/file'
14
+ require 'win32/security'
15
15
  end
16
16
 
17
17
  include FileUtils
@@ -23,14 +23,16 @@ class TC_File_Find < Test::Unit::TestCase
23
23
  @@windows = File::ALT_SEPARATOR
24
24
  @@jruby = RUBY_PLATFORM.match('java')
25
25
 
26
- unless @@windows
27
- if @@jruby || !defined? Sys::Admin
28
- @@loguser = Etc.getpwnam(Etc.getlogin)
29
- @@logroup = Etc.getgrgid(@@loguser.gid)
26
+ if @@windows
27
+ @@elevated = Win32::Security.elevated_security?
28
+ if @@elevated
29
+ @@loguser = Sys::Admin.get_group("Administrators", :LocalAccount => true)
30
30
  else
31
- @@loguser = Sys::Admin.get_user(Sys::Admin.get_login)
32
- @@logroup = Sys::Admin.get_group(@@loguser.gid)
31
+ @@loguser = Sys::Admin.get_user(Sys::Admin.get_login, :LocalAccount => true)
33
32
  end
33
+ else
34
+ @@loguser = Sys::Admin.get_user(Sys::Admin.get_login)
35
+ @@logroup = Sys::Admin.get_group(@@loguser.gid)
34
36
  end
35
37
  end
36
38
 
@@ -47,13 +49,16 @@ class TC_File_Find < Test::Unit::TestCase
47
49
  File.open(@file_txt2, 'w'){}
48
50
  File.open(@file_doc, 'w'){}
49
51
 
50
- unless @@windows
51
- @link1 = 'link1'
52
+ @link1 = 'link1'
53
+
54
+ if @@windows
55
+ File.symlink(@file_rb, @link1) if @@elevated
56
+ else
52
57
  File.symlink(@file_rb, @link1)
53
58
  end
54
59
 
55
- Dir.mkdir(@directory1) unless File.exists?(@directory1)
56
- Dir.mkdir(@directory2) unless File.exists?(@directory2)
60
+ Dir.mkdir(@directory1) unless File.exist?(@directory1)
61
+ Dir.mkdir(@directory2) unless File.exist?(@directory2)
57
62
 
58
63
  File.open(File.join(@directory1, 'bar.txt'), 'w'){}
59
64
  File.open(File.join(@directory2, 'baz.txt'), 'w'){}
@@ -62,29 +67,38 @@ class TC_File_Find < Test::Unit::TestCase
62
67
  @rule2 = File::Find.new
63
68
  end
64
69
 
65
- def test_version
66
- assert_equal('0.3.7', File::Find::VERSION)
70
+ test "version constant is set to expected value" do
71
+ assert_equal('0.3.8', File::Find::VERSION)
67
72
  end
68
73
 
69
- def test_path
74
+ test "path accessor basic functionality" do
70
75
  assert_respond_to(@rule1, :path)
71
76
  assert_respond_to(@rule1, :path=)
77
+ end
78
+
79
+ test "path method returns expected value" do
72
80
  assert_equal(Dir.pwd, @rule1.path)
73
81
  end
74
82
 
75
- def test_options
83
+ test "options accessor basic functionality" do
76
84
  assert_respond_to(@rule1, :options)
77
85
  assert_respond_to(@rule1, :options=)
86
+ end
87
+
88
+ test "options method returns expected value" do
78
89
  assert_equal({:name => '*.txt'}, @rule1.options)
79
90
  end
80
91
 
81
- def test_atime_basic
92
+ test "atime accessor basic functionality" do
82
93
  assert_respond_to(@rule1, :atime)
83
94
  assert_respond_to(@rule1, :atime=)
95
+ end
96
+
97
+ test "atime method returns expected default value" do
84
98
  assert_nil(@rule1.atime)
85
99
  end
86
100
 
87
- def test_atime
101
+ test "find with atime option works as expected" do
88
102
  rule1 = File::Find.new(:name => "*.rb", :atime => 0)
89
103
  rule2 = File::Find.new(:name => "*.rb", :atime => 1)
90
104
 
@@ -92,13 +106,16 @@ class TC_File_Find < Test::Unit::TestCase
92
106
  assert_true(rule2.find.empty?)
93
107
  end
94
108
 
95
- def test_ctime_basic
109
+ test "ctime accessor basic functionality" do
96
110
  assert_respond_to(@rule1, :ctime)
97
111
  assert_respond_to(@rule1, :ctime=)
112
+ end
113
+
114
+ test "ctime method returns expected default value" do
98
115
  assert_nil(@rule1.ctime)
99
116
  end
100
117
 
101
- def test_ctime
118
+ test "find with ctime option works as expected" do
102
119
  rule1 = File::Find.new(:name => "*.rb", :ctime => 0)
103
120
  rule2 = File::Find.new(:name => "*.rb", :ctime => 1)
104
121
 
@@ -106,31 +123,32 @@ class TC_File_Find < Test::Unit::TestCase
106
123
  assert_true(rule2.find.empty?)
107
124
  end
108
125
 
109
- def test_find_basic
126
+ test "find method basic functionality" do
110
127
  assert_respond_to(@rule1, :find)
111
128
  assert_nothing_raised{ @rule1.find }
112
129
  end
113
130
 
114
- def test_find
131
+ test "find method returns expected value" do
115
132
  assert_kind_of(Array, @rule1.find)
116
133
  assert_nil(@rule1.find{})
117
134
  end
118
135
 
119
- def test_filetest_basic
136
+ test "filetest accessor basic functionality" do
120
137
  assert_respond_to(@rule1, :filetest)
121
138
  assert_respond_to(@rule1, :filetest=)
122
139
  assert_nothing_raised{ @rule1.filetest }
140
+ end
141
+
142
+ test "filetest method returns expected value" do
123
143
  assert_kind_of(Array, @rule1.filetest)
124
144
  end
125
145
 
126
- def test_filetest_valid_options
146
+ test "valid filetest options work as expected" do
127
147
  assert_nothing_raised{ File::Find.new(:readable? => true) }
128
148
  assert_nothing_raised{ File::Find.new(:writable? => true) }
129
149
  end
130
150
 
131
- def test_filetest
132
- omit_if(@@windows && @@jruby, "Skipping file test on JRuby/Windows")
133
-
151
+ test "find method works with filetest option" do
134
152
  rule = File::Find.new(:name => "*.doc", :writable? => true)
135
153
  File.chmod(0644, @file_doc)
136
154
 
@@ -141,7 +159,16 @@ class TC_File_Find < Test::Unit::TestCase
141
159
  assert_equal([], rule.find)
142
160
  end
143
161
 
144
- def test_mtime
162
+ test "mtime accessor basic functionality" do
163
+ assert_respond_to(@rule1, :mtime)
164
+ assert_respond_to(@rule1, :mtime=)
165
+ end
166
+
167
+ test "mtime method returns expected default value" do
168
+ assert_nil(@rule1.mtime)
169
+ end
170
+
171
+ test "find with mtime option works as expected" do
145
172
  rule1 = File::Find.new(:name => "*.rb", :mtime => 0)
146
173
  rule2 = File::Find.new(:name => "*.rb", :mtime => 1)
147
174
 
@@ -149,19 +176,16 @@ class TC_File_Find < Test::Unit::TestCase
149
176
  assert_true(rule2.find.empty?)
150
177
  end
151
178
 
152
- def test_mtime_basic
153
- assert_respond_to(@rule1, :mtime)
154
- assert_respond_to(@rule1, :mtime=)
155
- assert_nil(@rule1.mtime)
156
- end
157
-
158
- def test_ftype_basic
179
+ test "ftype accessor basic functionality" do
159
180
  assert_respond_to(@rule1, :ftype)
160
181
  assert_respond_to(@rule1, :ftype=)
182
+ end
183
+
184
+ test "ftype method returns expected default value" do
161
185
  assert_nil(@rule1.ftype)
162
186
  end
163
187
 
164
- def test_ftype
188
+ test "ftype method works as expected" do
165
189
  rule1 = File::Find.new(:name => "*.rb", :ftype => "file")
166
190
  rule2 = File::Find.new(:name => "*.rb", :ftype => "characterSpecial")
167
191
 
@@ -169,25 +193,30 @@ class TC_File_Find < Test::Unit::TestCase
169
193
  assert_true(rule2.find.empty?)
170
194
  end
171
195
 
172
- def test_group_basic
196
+ test "group accessor basic functionality" do
173
197
  assert_respond_to(@rule1, :group)
174
198
  assert_respond_to(@rule1, :group=)
199
+ end
200
+
201
+ test "group method returns expected default value" do
175
202
  assert_nil(@rule1.group)
176
203
  end
177
204
 
178
- def test_group_with_numeric_id
205
+ # TODO: Update test for Windows
206
+ test "find with numeric group id works as expected" do
179
207
  omit_if(@@windows, 'group test skipped on MS Windows')
180
208
  @rule1 = File::Find.new(:name => '*.doc', :group => @@loguser.gid)
181
209
  assert_equal([File.expand_path(@file_doc)], @rule1.find)
182
210
  end
183
211
 
184
- def test_group_with_string
212
+ # TODO: Update test for Windows
213
+ test "find with string group id works as expected" do
185
214
  omit_if(@@windows, 'group test skipped on MS Windows')
186
215
  @rule1 = File::Find.new(:name => '*.doc', :group => @@logroup.name)
187
216
  assert_equal([File.expand_path(@file_doc)], @rule1.find)
188
217
  end
189
218
 
190
- def test_group_with_bad_id
219
+ test "find with bogus group returns empty results" do
191
220
  omit_if(@@windows, 'group test skipped on MS Windows')
192
221
  @rule1 = File::Find.new(:name => '*.doc', :group => 'totallybogus')
193
222
  @rule2 = File::Find.new(:name => '*.doc', :group => 99999999)
@@ -195,27 +224,35 @@ class TC_File_Find < Test::Unit::TestCase
195
224
  assert_equal([], @rule2.find)
196
225
  end
197
226
 
198
- def test_inum_basic
227
+ test "inum accessor basic functionality" do
199
228
  assert_respond_to(@rule1, :inum)
200
229
  assert_respond_to(@rule1, :inum=)
230
+ end
231
+
232
+ test "inum method returns expected default value" do
201
233
  assert_nil(@rule1.inum)
202
234
  end
203
235
 
204
- def test_follow_basic
236
+ test "follow accessor basic functionality" do
205
237
  assert_respond_to(@rule1, :follow)
206
238
  assert_respond_to(@rule1, :follow=)
239
+ end
240
+
241
+ test "follow method returns expected default value" do
207
242
  assert_true(@rule1.follow)
208
243
  end
209
244
 
210
- def test_links_basic
245
+ test "links accessor basic functionality" do
211
246
  assert_respond_to(@rule1, :links)
212
247
  assert_respond_to(@rule1, :links=)
213
- assert_nil(@rule1.links)
214
248
  end
215
249
 
216
- def test_links
217
- omit_if(@@windows, 'links test skipped on MS Windows')
250
+ test "links method returns expected default value" do
251
+ assert_nil(@rule1.links)
252
+ end
218
253
 
254
+ test "links method returns expected result" do
255
+ omit_if(@@windows && !@@elevated)
219
256
  @rule1 = File::Find.new(:name => '*.rb', :links => 2)
220
257
  @rule2 = File::Find.new(:name => '*.doc', :links => 1)
221
258
 
@@ -234,7 +271,7 @@ class TC_File_Find < Test::Unit::TestCase
234
271
  # I did this because I'm a little paranoid about the directory
235
272
  # not getting mangled. - jlawler.
236
273
  #
237
- def test_dirs_with_brackets
274
+ test "find method works on dirs that contain brackets" do
238
275
  omit_if(@@windows, 'dirs with brackets test skipped on MS Windows')
239
276
 
240
277
  bracket_files = [ 'bracket/a[1]/a.foo', 'bracket/a [2] /b.foo', 'bracket/[a] b [c]/d.foo' ].sort
@@ -264,7 +301,7 @@ class TC_File_Find < Test::Unit::TestCase
264
301
  assert_equal(bracket_paths, @dir_rule.find.sort )
265
302
  end
266
303
 
267
- def test_maxdepth_file
304
+ test "find with maxdepth option returns expected results" do
268
305
  mkpath('a1/a2/a3')
269
306
  touch('a1/a.foo')
270
307
  touch('a1/a2/b.foo')
@@ -290,7 +327,7 @@ class TC_File_Find < Test::Unit::TestCase
290
327
  )
291
328
  end
292
329
 
293
- def test_maxdepth_directory
330
+ test "find with maxdepth option returns expected results for directories" do
294
331
  mkpath('a/b/c')
295
332
  @rule2.pattern = "c"
296
333
 
@@ -304,13 +341,16 @@ class TC_File_Find < Test::Unit::TestCase
304
341
  assert_equal(['c'], @rule2.find.map{ |e| File.basename(e) })
305
342
  end
306
343
 
307
- def test_mindepth_basic
344
+ test "mindepth accessor basic functionality" do
308
345
  assert_respond_to(@rule1, :mindepth)
309
346
  assert_respond_to(@rule1, :mindepth=)
347
+ end
348
+
349
+ test "mindepth method returns expected default value" do
310
350
  assert_nil(@rule1.mindepth)
311
351
  end
312
352
 
313
- def test_mindepth_file
353
+ test "find with mindepth option returns expected results" do
314
354
  mkpath('a1/a2/a3')
315
355
  touch('z.min')
316
356
  touch('a1/a.min')
@@ -353,7 +393,7 @@ class TC_File_Find < Test::Unit::TestCase
353
393
  assert_equal([], @rule2.find.map{ |e| File.basename(e) })
354
394
  end
355
395
 
356
- def test_mindepth_directory
396
+ test "find with mindepth option returns expected results for directories" do
357
397
  mkpath('a/b/c')
358
398
  @rule2.pattern = "a"
359
399
 
@@ -367,42 +407,54 @@ class TC_File_Find < Test::Unit::TestCase
367
407
  assert_equal([], @rule2.find)
368
408
  end
369
409
 
370
- def test_mount_basic
410
+ test "mount accessor basic functionality" do
371
411
  assert_respond_to(@rule1, :mount)
372
412
  assert_respond_to(@rule1, :mount=)
413
+ end
414
+
415
+ test "mount method returns expected default value" do
373
416
  assert_nil(@rule1.mount)
374
417
  end
375
418
 
376
- def test_name_basic
419
+ test "name accessor basic functionality" do
377
420
  assert_respond_to(@rule1, :name)
378
421
  assert_respond_to(@rule1, :name=)
422
+ end
423
+
424
+ test "name method returns expected default value" do
379
425
  assert_equal('*.txt', @rule1.name)
380
426
  end
381
427
 
382
- def test_pattern_alias
428
+ test "pattern accessor basic functionality" do
383
429
  assert_respond_to(@rule1, :pattern)
384
430
  assert_respond_to(@rule1, :pattern=)
385
- assert_true(@rule1.method(:name) == @rule1.method(:pattern))
386
- assert_true(@rule1.method(:name=) == @rule1.method(:pattern=))
387
431
  end
388
432
 
389
- def test_perm_basic
433
+ test "pattern is an alias for name" do
434
+ assert_alias_method(@rule1, :name, :pattern)
435
+ assert_alias_method(@rule1, :name=, :pattern=)
436
+ end
437
+
438
+ test "perm accessor basic functionality" do
390
439
  assert_respond_to(@rule1, :perm)
391
440
  assert_respond_to(@rule1, :perm=)
441
+ end
442
+
443
+ test "perm method returns expected default value" do
392
444
  assert_nil(@rule1.perm)
393
445
  end
394
446
 
395
- def test_perm
396
- omit_if(@@windows, 'perm test skipped on MS Windows')
397
- File.chmod(0664, @file_rb)
447
+ test "perm method returns expected results" do
448
+ File.chmod(0444, @file_rb)
398
449
  File.chmod(0644, @file_txt1)
399
- results = File::Find.new(:name => "test1*", :perm => 664).find
450
+
451
+ results = File::Find.new(:name => "test1*", :perm => 0644).find
400
452
 
401
453
  assert_equal(1, results.length)
402
- assert_equal('test1.rb', File.basename(results.first))
454
+ assert_equal('test1.txt', File.basename(results.first))
403
455
  end
404
456
 
405
- def test_perm_with_symbolic_permissions
457
+ test "perm method works with symbolic permissions" do
406
458
  omit_if(@@windows, 'symbolic perm test skipped on MS Windows')
407
459
 
408
460
  File.chmod(0664, @file_rb) # test1.rb
@@ -416,55 +468,71 @@ class TC_File_Find < Test::Unit::TestCase
416
468
  assert_equal(['test1.rb', 'test1.txt'], results2.map{ |e| File.basename(e) }.sort)
417
469
  end
418
470
 
419
- def test_prune_basic
471
+ test "prune accessor basic functionality" do
420
472
  assert_respond_to(@rule1, :prune)
421
473
  assert_respond_to(@rule1, :prune=)
474
+ end
475
+
476
+ test "prune method returns expected default value" do
422
477
  assert_nil(@rule1.prune)
423
478
  end
424
479
 
425
- def test_prune
480
+ test "find method with prune option works as expected" do
426
481
  rule = File::Find.new(:name => "*.txt", :prune => 'foo')
427
482
  assert_equal('test1.txt', File.basename(rule.find.first))
428
483
  end
429
484
 
430
- def test_size_basic
485
+ test "size accessor basic functionality" do
431
486
  assert_respond_to(@rule1, :size)
432
487
  assert_respond_to(@rule1, :size=)
488
+ end
489
+
490
+ test "size method returns expected default value" do
433
491
  assert_nil(@rule1.size)
434
492
  end
435
493
 
436
- def test_user_basic
494
+ test "user accessor basic functionality" do
437
495
  assert_respond_to(@rule1, :user)
438
496
  assert_respond_to(@rule1, :user=)
497
+ end
498
+
499
+ test "user method returns expected default value" do
439
500
  assert_nil(@rule1.user)
440
501
  end
441
502
 
442
- def test_user_with_numeric_id
443
- omit_if(@@windows, 'user test skipped on MS Windows')
444
- @rule1 = File::Find.new(:name => '*.doc', :user => @@loguser.uid)
503
+ test "user method works with numeric id as expected" do
504
+ if @@windows && @@elevated
505
+ uid = @@loguser.gid # Windows assigns the group if any member is an admin
506
+ else
507
+ uid = @@loguser.uid
508
+ end
509
+
510
+ @rule1 = File::Find.new(:name => '*.doc', :user => uid)
445
511
  assert_equal([File.expand_path(@file_doc)], @rule1.find)
446
512
  end
447
513
 
448
- def test_user_with_string
449
- omit_if(@@windows, 'user test skipped on MS Windows')
514
+ test "user method works with string as expected" do
515
+ omit_if(@@windows && @@elevated)
450
516
  @rule1 = File::Find.new(:name => '*.doc', :user => @@loguser.name)
451
517
  assert_equal([File.expand_path(@file_doc)], @rule1.find)
452
518
  end
453
519
 
454
- def test_user_with_bad_id
455
- omit_if(@@windows, 'user test skipped on MS Windows')
520
+ test "find method with user option using invalid user returns expected results" do
456
521
  @rule1 = File::Find.new(:name => '*.doc', :user => 'totallybogus')
457
522
  @rule2 = File::Find.new(:name => '*.doc', :user => 99999999)
458
523
  assert_equal([], @rule1.find)
459
524
  assert_equal([], @rule2.find)
460
525
  end
461
526
 
462
- def test_previous_basic
527
+ test "previous method basic functionality" do
463
528
  assert_respond_to(@rule1, :previous)
464
529
  end
465
530
 
466
- def test_expected_errors
531
+ test "an error is raised if the path does not exist" do
467
532
  assert_raise(Errno::ENOENT){ File::Find.new(:path => '/bogus/dir').find }
533
+ end
534
+
535
+ test "an error is raised if an invalid option is passed" do
468
536
  assert_raise(ArgumentError){ File::Find.new(:bogus => 1) }
469
537
  assert_raise(ArgumentError){ File::Find.new(:bogus? => true) }
470
538
  end
@@ -476,11 +544,11 @@ class TC_File_Find < Test::Unit::TestCase
476
544
  rm_rf(@file_doc)
477
545
  rm_rf(@directory1)
478
546
  rm_rf(@directory2)
479
- rm_rf(@link1) unless @@windows
547
+ rm_rf(@link1) #unless @@windows
480
548
  rm_rf('a')
481
549
  rm_rf('a1')
482
550
  rm_rf('bracket')
483
- rm_rf('z.min') if File.exists?('z.min')
551
+ rm_rf('z.min') if File.exist?('z.min')
484
552
 
485
553
  @rule1 = nil
486
554
  @rule2 = nil
@@ -493,7 +561,7 @@ class TC_File_Find < Test::Unit::TestCase
493
561
  def self.shutdown
494
562
  @@windows = nil
495
563
  @@jruby = nil
496
- @@loguser = nil unless @@windows
564
+ @@elevated = nil if @@windows
497
565
  @@logroup = nil unless @@windows
498
566
  end
499
567
  end
metadata CHANGED
@@ -1,75 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-find
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: test-unit
14
+ name: sys-admin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.0
20
- type: :development
19
+ version: 1.6.0
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.0
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: sys-admin
28
+ name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: sys-admin
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: 1.5.2
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: 1.5.2
69
- description: ! " The file-find library provides a better, more object oriented
70
- approach\n to finding files. It allows you to find files based on a variety of\n
71
- \ properties, such as access time, size, owner, etc. You can also limit\n directory
72
- depth.\n"
55
+ description: |2
56
+ The file-find library provides a better, more object oriented approach
57
+ to finding files. It allows you to find files based on a variety of
58
+ properties, such as access time, size, owner, etc. You can also limit
59
+ directory depth.
73
60
  email: djberg96@gmail.com
74
61
  executables: []
75
62
  extensions: []
@@ -79,11 +66,11 @@ extra_rdoc_files:
79
66
  - MANIFEST
80
67
  files:
81
68
  - CHANGES
82
- - file-find.gemspec
83
- - lib/file/find.rb
84
69
  - MANIFEST
85
- - Rakefile
86
70
  - README
71
+ - Rakefile
72
+ - file-find.gemspec
73
+ - lib/file/find.rb
87
74
  - test/test_file_find.rb
88
75
  homepage: http://github.com/djberg96/file-find
89
76
  licenses:
@@ -95,17 +82,17 @@ require_paths:
95
82
  - lib
96
83
  required_ruby_version: !ruby/object:Gem::Requirement
97
84
  requirements:
98
- - - ! '>='
85
+ - - '>='
99
86
  - !ruby/object:Gem::Version
100
87
  version: '0'
101
88
  required_rubygems_version: !ruby/object:Gem::Requirement
102
89
  requirements:
103
- - - ! '>='
90
+ - - '>='
104
91
  - !ruby/object:Gem::Version
105
92
  version: '0'
106
93
  requirements: []
107
94
  rubyforge_project: shards
108
- rubygems_version: 2.1.9
95
+ rubygems_version: 2.2.2
109
96
  signing_key:
110
97
  specification_version: 4
111
98
  summary: A better way to find files