tmptation 1.1 → 1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/tmptation.rb +5 -1
  2. data/test/tmptation_test.rb +32 -0
  3. metadata +2 -2
data/lib/tmptation.rb CHANGED
@@ -4,7 +4,7 @@ require 'tmpdir'
4
4
  require 'fileutils'
5
5
 
6
6
  module Tmptation
7
- VERSION = 1.1
7
+ VERSION = 1.2
8
8
 
9
9
  # Adds a #safe_delete method that will delete the object's associated path
10
10
  # (either #path or #to_s, if it exists) only if it lives within the system's
@@ -45,6 +45,8 @@ module Tmptation
45
45
  raise UnsafeDelete.new("refusing to remove non-tmp directory '#{path}'")
46
46
  end
47
47
  FileUtils.remove_entry_secure(path.to_s)
48
+ rescue Errno::ENOENT
49
+ # noop
48
50
  end
49
51
  end
50
52
 
@@ -111,6 +113,7 @@ module Tmptation
111
113
  instance.safe_delete
112
114
  instance.close
113
115
  end
116
+ instances.clear
114
117
  end
115
118
  alias -@ delete_all
116
119
  end
@@ -156,6 +159,7 @@ module Tmptation
156
159
  # Safe deletes and closes all instances
157
160
  def delete_all
158
161
  instances.each {|instance| instance.safe_delete }
162
+ instances.clear
159
163
  end
160
164
  alias -@ delete_all
161
165
  end
@@ -67,6 +67,14 @@ describe Tmptation::SafeDeletable do
67
67
  end
68
68
  end
69
69
 
70
+ it "should handle nonexistent entries" do
71
+ dir = Pathname(Dir.tmpdir).join("nonexistentdir-#{Time.now.to_f}")
72
+ dir.extend(SafeDeletable)
73
+
74
+ refute dir.exist?
75
+ dir.safe_delete #refute raises
76
+ end
77
+
70
78
  it "should use an object's #path if it exists" do
71
79
  begin
72
80
  file = Tempfile.new('safe_deletable')
@@ -187,6 +195,18 @@ describe Tmptation::TmpFile do
187
195
  foo.delete if foo.path.exist?
188
196
  end
189
197
  end
198
+
199
+ it "should clear the instance references" do
200
+ begin
201
+ foo = TmpFile.new
202
+ assert_equal [foo], TmpFile.instances
203
+
204
+ TmpFile.delete_all
205
+ assert_empty TmpFile.instances
206
+ ensure
207
+ foo.delete if foo.path.exist?
208
+ end
209
+ end
190
210
  end
191
211
 
192
212
  describe Tmptation::TmpDir do
@@ -252,5 +272,17 @@ describe Tmptation::TmpDir do
252
272
  foo.rmdir if foo.exist?
253
273
  end
254
274
  end
275
+
276
+ it "should clear the instance references" do
277
+ begin
278
+ foo = TmpDir.new
279
+ assert_equal [foo], TmpDir.instances
280
+
281
+ TmpDir.delete_all
282
+ assert_empty TmpDir.instances
283
+ ensure
284
+ foo.rmdir if foo.exist?
285
+ end
286
+ end
255
287
  end
256
288
 
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- version: "1.1"
7
+ - 2
8
+ version: "1.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Martin Aumont