tmptation 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,8 +5,8 @@ directories. Especially useful for use in tests.
5
5
 
6
6
  Features
7
7
  --------
8
- * garbage collection of all created tmp files and dirs
9
- * safe deletion - will refuse to delete non-tmp paths (where tmp within `Dir.tmpdir`)
8
+ * easy garbage collection of all created tmp files and dirs with `.delete_all`
9
+ * safe deletion - will refuse to delete non-tmp paths (as determined by `Dir.tmpdir`)
10
10
 
11
11
  Examples
12
12
  --------
@@ -42,7 +42,7 @@ They might be useful on their own. See the inline docs for more details.
42
42
  Protip
43
43
  ------
44
44
 
45
- If you use Tmptation in specs, add `TmpFile.delete_all` and `TmpDir.delete_all`
45
+ If you use Tmptation in tests, add `TmpFile.delete_all` and `TmpDir.delete_all`
46
46
  to your global teardown method:
47
47
 
48
48
  class MiniTest::Unit::TestCase
data/lib/tmptation.rb CHANGED
@@ -4,7 +4,7 @@ require 'tmpdir'
4
4
  require 'fileutils'
5
5
 
6
6
  module Tmptation
7
- VERSION = 1.2
7
+ VERSION = 1.3
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
@@ -168,7 +168,12 @@ module Tmptation
168
168
  # prefix of directory name
169
169
  #
170
170
  def initialize(prefix='TmpDir-')
171
- super(Pathname(Dir.mktmpdir(prefix)).expand_path)
171
+ # The `caller` lookup is used to determine if `::new` is being called
172
+ # from within `Pathname`. This is necessary since many `Pathname` methods
173
+ # call `self.class.new` internally, and these calls shouldn't create a
174
+ # new tmp dir. Not the cleanest approach, but allows keeping a simple and
175
+ # clean api.
176
+ caller[1].match(/pathname\.rb/) ? super : super(Pathname(Dir.mktmpdir(prefix)).expand_path)
172
177
  end
173
178
  end
174
179
  end
@@ -284,5 +284,18 @@ describe Tmptation::TmpDir do
284
284
  foo.rmdir if foo.exist?
285
285
  end
286
286
  end
287
+
288
+ it "should preserve existing Pathname behaviour" do
289
+ begin
290
+ foo = TmpDir.new('prefix-')
291
+
292
+ assert_equal Dir.tmpdir, foo.dirname.to_s
293
+ assert_match /^\//, foo.expand_path
294
+ assert_match /^\.\./, foo.relative_path_from(Pathname(Dir.pwd))
295
+ assert_match /^prefix-/, foo.basename
296
+ ensure
297
+ foo.rmdir if foo.exist?
298
+ end
299
+ end
287
300
  end
288
301
 
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
8
- version: "1.2"
7
+ - 3
8
+ version: "1.3"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Martin Aumont
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-11-04 00:00:00 -07:00
16
+ date: 2010-11-05 00:00:00 -07:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency