rubysl-tempfile 0.0.1 → 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/rubysl/tempfile.rb +2 -0
- data/lib/rubysl/tempfile/tempfile.rb +209 -0
- data/lib/{rubysl-tempfile → rubysl/tempfile}/version.rb +1 -1
- data/lib/tempfile.rb +1 -0
- data/rubysl-tempfile.gemspec +19 -17
- data/spec/_close_spec.rb +21 -0
- data/spec/callback_spec.rb +6 -0
- data/spec/close_spec.rb +59 -0
- data/spec/delete_spec.rb +7 -0
- data/spec/fixtures/common.rb +6 -0
- data/spec/initialize_spec.rb +36 -0
- data/spec/length_spec.rb +7 -0
- data/spec/open_spec.rb +93 -0
- data/spec/path_spec.rb +26 -0
- data/spec/shared/length.rb +31 -0
- data/spec/shared/unlink.rb +18 -0
- data/spec/size_spec.rb +7 -0
- data/spec/unlink_spec.rb +7 -0
- metadata +93 -88
- data/lib/rubysl-tempfile.rb +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ef0738dac62e35b9f6360922f94efc28d20fd39
|
4
|
+
data.tar.gz: fce5f3e54ef1085c072f867ae45bf51884d13061
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1ad962fc20d677dcb0b0179803065ef8f7ec8042808549b80e6b8dc12fea148327f19ee919974a3addcbd305474ee9917d58164715190fce6ec39ad033c51c1
|
7
|
+
data.tar.gz: 7b28bfb3515238570324440c5752d69d6b9def6feaa70847889e678b58bc88f0934853fa78a29f9ea665d70aa328f648a4a2dd5c458ca897b20a7ee40756db48
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Rubysl::Tempfile
|
2
2
|
|
3
3
|
TODO: Write a gem description
|
4
4
|
|
@@ -24,6 +24,6 @@ TODO: Write usage instructions here
|
|
24
24
|
|
25
25
|
1. Fork it
|
26
26
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am '
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -0,0 +1,209 @@
|
|
1
|
+
#
|
2
|
+
# tempfile - manipulates temporary files
|
3
|
+
#
|
4
|
+
# $Id: tempfile.rb 16127 2008-04-21 09:43:44Z knu $
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'delegate'
|
8
|
+
require 'tmpdir'
|
9
|
+
|
10
|
+
# A class for managing temporary files. This library is written to be
|
11
|
+
# thread safe.
|
12
|
+
class Tempfile < DelegateClass(File)
|
13
|
+
MAX_TRY = 10
|
14
|
+
@@cleanlist = []
|
15
|
+
|
16
|
+
# Creates a temporary file of mode 0600 in the temporary directory,
|
17
|
+
# opens it with mode "w+", and returns a Tempfile object which
|
18
|
+
# represents the created temporary file. A Tempfile object can be
|
19
|
+
# treated just like a normal File object.
|
20
|
+
#
|
21
|
+
# The basename parameter is used to determine the name of a
|
22
|
+
# temporary file. If an Array is given, the first element is used
|
23
|
+
# as prefix string and the second as suffix string, respectively.
|
24
|
+
# Otherwise it is treated as prefix string.
|
25
|
+
#
|
26
|
+
# If tmpdir is omitted, the temporary directory is determined by
|
27
|
+
# Dir::tmpdir provided by 'tmpdir.rb'.
|
28
|
+
# When $SAFE > 0 and the given tmpdir is tainted, it uses
|
29
|
+
# /tmp. (Note that ENV values are tainted by default)
|
30
|
+
def initialize(basename, tmpdir=Dir::tmpdir)
|
31
|
+
if $SAFE > 0 and tmpdir.tainted?
|
32
|
+
tmpdir = '/tmp'
|
33
|
+
end
|
34
|
+
|
35
|
+
lock = nil
|
36
|
+
n = failure = 0
|
37
|
+
|
38
|
+
begin
|
39
|
+
Thread.critical = true
|
40
|
+
|
41
|
+
begin
|
42
|
+
tmpname = File.join(tmpdir, make_tmpname(basename, n))
|
43
|
+
lock = tmpname + '.lock'
|
44
|
+
n += 1
|
45
|
+
end while @@cleanlist.include?(tmpname) or
|
46
|
+
File.exist?(lock) or File.exist?(tmpname)
|
47
|
+
|
48
|
+
Dir.mkdir(lock)
|
49
|
+
rescue
|
50
|
+
failure += 1
|
51
|
+
retry if failure < MAX_TRY
|
52
|
+
raise "cannot generate tempfile `%s'" % tmpname
|
53
|
+
ensure
|
54
|
+
Thread.critical = false
|
55
|
+
end
|
56
|
+
|
57
|
+
@data = [tmpname]
|
58
|
+
@clean_proc = Tempfile.callback(@data)
|
59
|
+
ObjectSpace.define_finalizer(self, @clean_proc)
|
60
|
+
|
61
|
+
@tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
62
|
+
@tmpname = tmpname
|
63
|
+
@@cleanlist << @tmpname
|
64
|
+
@data[1] = @tmpfile
|
65
|
+
@data[2] = @@cleanlist
|
66
|
+
|
67
|
+
super(@tmpfile)
|
68
|
+
|
69
|
+
# Now we have all the File/IO methods defined, you must not
|
70
|
+
# carelessly put bare puts(), etc. after this.
|
71
|
+
|
72
|
+
Dir.rmdir(lock)
|
73
|
+
end
|
74
|
+
|
75
|
+
def make_tmpname(basename, n)
|
76
|
+
case basename
|
77
|
+
when Array
|
78
|
+
prefix, suffix = *basename
|
79
|
+
else
|
80
|
+
prefix, suffix = basename, ''
|
81
|
+
end
|
82
|
+
|
83
|
+
t = Time.now.strftime("%Y%m%d")
|
84
|
+
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}"
|
85
|
+
end
|
86
|
+
private :make_tmpname
|
87
|
+
|
88
|
+
# Opens or reopens the file with mode "r+".
|
89
|
+
def open
|
90
|
+
@tmpfile.close if @tmpfile
|
91
|
+
@tmpfile = File.open(@tmpname, 'r+')
|
92
|
+
@data[1] = @tmpfile
|
93
|
+
__setobj__(@tmpfile)
|
94
|
+
end
|
95
|
+
|
96
|
+
def _close # :nodoc:
|
97
|
+
@tmpfile.close if @tmpfile
|
98
|
+
@tmpfile = nil
|
99
|
+
@data[1] = nil if @data
|
100
|
+
end
|
101
|
+
protected :_close
|
102
|
+
|
103
|
+
# Closes the file. If the optional flag is true, unlinks the file
|
104
|
+
# after closing.
|
105
|
+
#
|
106
|
+
# If you don't explicitly unlink the temporary file, the removal
|
107
|
+
# will be delayed until the object is finalized.
|
108
|
+
def close(unlink_now=false)
|
109
|
+
if unlink_now
|
110
|
+
close!
|
111
|
+
else
|
112
|
+
_close
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Closes and unlinks the file.
|
117
|
+
def close!
|
118
|
+
_close
|
119
|
+
@clean_proc.call
|
120
|
+
ObjectSpace.undefine_finalizer(self)
|
121
|
+
@data = @tmpname = nil
|
122
|
+
end
|
123
|
+
|
124
|
+
# Unlinks the file. On UNIX-like systems, it is often a good idea
|
125
|
+
# to unlink a temporary file immediately after creating and opening
|
126
|
+
# it, because it leaves other programs zero chance to access the
|
127
|
+
# file.
|
128
|
+
def unlink
|
129
|
+
# keep this order for thread safeness
|
130
|
+
begin
|
131
|
+
File.unlink(@tmpname) if File.exist?(@tmpname)
|
132
|
+
@@cleanlist.delete(@tmpname)
|
133
|
+
@data = @tmpname = nil
|
134
|
+
ObjectSpace.undefine_finalizer(self)
|
135
|
+
rescue Errno::EACCES
|
136
|
+
# may not be able to unlink on Windows; just ignore
|
137
|
+
end
|
138
|
+
end
|
139
|
+
alias delete unlink
|
140
|
+
|
141
|
+
# Returns the full path name of the temporary file.
|
142
|
+
def path
|
143
|
+
@tmpname
|
144
|
+
end
|
145
|
+
|
146
|
+
# Returns the size of the temporary file. As a side effect, the IO
|
147
|
+
# buffer is flushed before determining the size.
|
148
|
+
def size
|
149
|
+
if @tmpfile
|
150
|
+
@tmpfile.flush
|
151
|
+
@tmpfile.stat.size
|
152
|
+
else
|
153
|
+
0
|
154
|
+
end
|
155
|
+
end
|
156
|
+
alias length size
|
157
|
+
|
158
|
+
class << self
|
159
|
+
def callback(data) # :nodoc:
|
160
|
+
pid = $$
|
161
|
+
lambda {
|
162
|
+
if pid == $$
|
163
|
+
path, tmpfile, cleanlist = *data
|
164
|
+
|
165
|
+
print "removing ", path, "..." if $DEBUG
|
166
|
+
|
167
|
+
tmpfile.close if tmpfile
|
168
|
+
|
169
|
+
# keep this order for thread safeness
|
170
|
+
File.unlink(path) if File.exist?(path)
|
171
|
+
cleanlist.delete(path) if cleanlist
|
172
|
+
|
173
|
+
print "done\n" if $DEBUG
|
174
|
+
end
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
# If no block is given, this is a synonym for new().
|
179
|
+
#
|
180
|
+
# If a block is given, it will be passed tempfile as an argument,
|
181
|
+
# and the tempfile will automatically be closed when the block
|
182
|
+
# terminates. In this case, open() returns nil.
|
183
|
+
def open(*args)
|
184
|
+
tempfile = new(*args)
|
185
|
+
|
186
|
+
if block_given?
|
187
|
+
begin
|
188
|
+
yield(tempfile)
|
189
|
+
ensure
|
190
|
+
tempfile.close
|
191
|
+
end
|
192
|
+
|
193
|
+
nil
|
194
|
+
else
|
195
|
+
tempfile
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
if __FILE__ == $0
|
202
|
+
# $DEBUG = true
|
203
|
+
f = Tempfile.new("foo")
|
204
|
+
f.print("foo\n")
|
205
|
+
f.close
|
206
|
+
f.open
|
207
|
+
p f.gets # => "foo\n"
|
208
|
+
f.close!
|
209
|
+
end
|
data/lib/tempfile.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/tempfile"
|
data/rubysl-tempfile.gemspec
CHANGED
@@ -1,22 +1,24 @@
|
|
1
|
-
#
|
2
|
-
require
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/tempfile/version'
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-tempfile"
|
6
|
+
spec.version = RubySL::Tempfile::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library tempfile.}
|
10
|
+
spec.summary = %q{Ruby standard library tempfile.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-tempfile"
|
12
|
+
spec.license = "BSD"
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = RubySL::Tempfile::VERSION
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
17
18
|
|
18
|
-
|
19
|
+
spec.required_ruby_version = "~> 1.8.7"
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
24
|
end
|
data/spec/_close_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Tempfile#_close" do
|
5
|
+
before :each do
|
6
|
+
@tempfile = Tempfile.new("specs")
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
TempfileSpecs.cleanup @tempfile
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is protected" do
|
14
|
+
Tempfile.should have_protected_instance_method(:_close)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "closes self" do
|
18
|
+
@tempfile.send(:_close)
|
19
|
+
@tempfile.closed?.should be_true
|
20
|
+
end
|
21
|
+
end
|
data/spec/close_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Tempfile#close when passed no argument or [false]" do
|
5
|
+
before(:each) do
|
6
|
+
@tempfile = Tempfile.new("specs", tmp(""))
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
TempfileSpecs.cleanup(@tempfile)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "closes self" do
|
14
|
+
@tempfile.close
|
15
|
+
@tempfile.closed?.should be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Tempfile#close when passed [true]" do
|
20
|
+
before(:each) do
|
21
|
+
@tempfile = Tempfile.new("specs", tmp(""))
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
TempfileSpecs.cleanup(@tempfile)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "closes self" do
|
29
|
+
@tempfile.close(true)
|
30
|
+
@tempfile.closed?.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "unlinks self" do
|
34
|
+
path = @tempfile.path
|
35
|
+
@tempfile.close(true)
|
36
|
+
File.exists?(path).should be_false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Tempfile#close!" do
|
41
|
+
before(:each) do
|
42
|
+
@tempfile = Tempfile.new("specs", tmp(""))
|
43
|
+
end
|
44
|
+
|
45
|
+
after(:each) do
|
46
|
+
@tempfile.unlink if @tempfile.path
|
47
|
+
end
|
48
|
+
|
49
|
+
it "closes self" do
|
50
|
+
@tempfile.close!
|
51
|
+
@tempfile.closed?.should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "unlinks self" do
|
55
|
+
path = @tempfile.path
|
56
|
+
@tempfile.close!
|
57
|
+
File.exists?(path).should be_false
|
58
|
+
end
|
59
|
+
end
|
data/spec/delete_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Tempfile#initialize" do
|
5
|
+
before :each do
|
6
|
+
@tempfile = Tempfile.allocate
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
TempfileSpecs.cleanup @tempfile
|
11
|
+
end
|
12
|
+
|
13
|
+
it "opens a new tempfile with the passed name in the passed directory" do
|
14
|
+
@tempfile.send(:initialize, "basename", tmp(""))
|
15
|
+
File.exist?(@tempfile.path).should be_true
|
16
|
+
|
17
|
+
tmpdir = tmp("")
|
18
|
+
path = @tempfile.path
|
19
|
+
|
20
|
+
platform_is :windows do
|
21
|
+
# on Windows, both types of slashes are OK,
|
22
|
+
# but the tmp helper always uses '/'
|
23
|
+
path.gsub!('\\', '/')
|
24
|
+
end
|
25
|
+
|
26
|
+
path[0, tmpdir.length].should == tmpdir
|
27
|
+
path.should include("basename")
|
28
|
+
end
|
29
|
+
|
30
|
+
platform_is_not :windows do
|
31
|
+
it "sets the permisssions on the tempfile to 0600" do
|
32
|
+
@tempfile.send(:initialize, "basename", tmp(""))
|
33
|
+
File.stat(@tempfile.path).mode.should == 0100600
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/length_spec.rb
ADDED
data/spec/open_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Tempfile#open" do
|
5
|
+
before :each do
|
6
|
+
@tempfile = Tempfile.new("specs")
|
7
|
+
@tempfile.puts("Test!")
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
TempfileSpecs.cleanup @tempfile
|
12
|
+
end
|
13
|
+
|
14
|
+
it "reopens self" do
|
15
|
+
@tempfile.close
|
16
|
+
@tempfile.open
|
17
|
+
@tempfile.closed?.should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "reopens self in read and write mode and does not truncate" do
|
21
|
+
@tempfile.open
|
22
|
+
@tempfile.puts("Another Test!")
|
23
|
+
|
24
|
+
@tempfile.open
|
25
|
+
@tempfile.readline.should == "Another Test!\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "Tempfile.open" do
|
30
|
+
after :each do
|
31
|
+
TempfileSpecs.cleanup @tempfile
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a new, open Tempfile instance" do
|
35
|
+
@tempfile = Tempfile.open("specs")
|
36
|
+
# Delegation messes up .should be_an_instance_of(Tempfile)
|
37
|
+
@tempfile.instance_of?(Tempfile).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
ruby_version_is "1.8.7" do
|
41
|
+
it "is passed an array [base, suffix] as first argument" do
|
42
|
+
Tempfile.open(["specs", ".tt"]) { |tempfile| @tempfile = tempfile }
|
43
|
+
@tempfile.path.should =~ /specs.*\.tt$/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "Tempfile.open when passed a block" do
|
49
|
+
before :each do
|
50
|
+
ScratchPad.clear
|
51
|
+
end
|
52
|
+
|
53
|
+
after :each do
|
54
|
+
TempfileSpecs.cleanup @tempfile
|
55
|
+
end
|
56
|
+
|
57
|
+
it "yields a new, open Tempfile instance to the block" do
|
58
|
+
Tempfile.open("specs") do |tempfile|
|
59
|
+
@tempfile = tempfile
|
60
|
+
ScratchPad.record :yielded
|
61
|
+
|
62
|
+
# Delegation messes up .should be_an_instance_of(Tempfile)
|
63
|
+
tempfile.instance_of?(Tempfile).should be_true
|
64
|
+
tempfile.closed?.should be_false
|
65
|
+
end
|
66
|
+
|
67
|
+
ScratchPad.recorded.should == :yielded
|
68
|
+
end
|
69
|
+
|
70
|
+
ruby_version_is ""..."1.9" do
|
71
|
+
it "returns nil" do
|
72
|
+
value = Tempfile.open("specs") do |tempfile|
|
73
|
+
true
|
74
|
+
end
|
75
|
+
value.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
ruby_version_is "1.9" do
|
80
|
+
it "returns the value of the block" do
|
81
|
+
value = Tempfile.open("specs") do |tempfile|
|
82
|
+
"return"
|
83
|
+
end
|
84
|
+
value.should == "return"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "closes the yielded Tempfile after the block" do
|
89
|
+
Tempfile.open("specs") { |tempfile| @tempfile = tempfile }
|
90
|
+
@tempfile.closed?.should be_true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/spec/path_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../fixtures/common', __FILE__)
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe "Tempfile#path" do
|
5
|
+
before :each do
|
6
|
+
@tempfile = Tempfile.new("specs", tmp(""))
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
TempfileSpecs.cleanup @tempfile
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the path to the tempfile" do
|
14
|
+
tmpdir = tmp("")
|
15
|
+
path = @tempfile.path
|
16
|
+
|
17
|
+
platform_is :windows do
|
18
|
+
# on Windows, both types of slashes are OK,
|
19
|
+
# but the tmp helper always uses '/'
|
20
|
+
path.gsub!('\\', '/')
|
21
|
+
end
|
22
|
+
|
23
|
+
path[0, tmpdir.length].should == tmpdir
|
24
|
+
path.should include("specs")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
describe :tempfile_length, :shared => true do
|
2
|
+
before :each do
|
3
|
+
@tempfile = Tempfile.new("specs")
|
4
|
+
end
|
5
|
+
|
6
|
+
after :each do
|
7
|
+
TempfileSpecs.cleanup @tempfile
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the size of self" do
|
11
|
+
@tempfile.send(@method).should eql(0)
|
12
|
+
@tempfile.print("Test!")
|
13
|
+
@tempfile.send(@method).should eql(5)
|
14
|
+
end
|
15
|
+
|
16
|
+
ruby_version_is ''...'1.9.2' do
|
17
|
+
it "returns 0 when self is closed" do
|
18
|
+
@tempfile.print("Test!")
|
19
|
+
@tempfile.close
|
20
|
+
@tempfile.send(@method).should eql(0)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
ruby_version_is '1.9.2' do
|
25
|
+
it "returns the size of self even if self is closed" do
|
26
|
+
@tempfile.print("Test!")
|
27
|
+
@tempfile.close
|
28
|
+
@tempfile.send(@method).should eql(5)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe :tempfile_unlink, :shared => true do
|
2
|
+
before :each do
|
3
|
+
@tempfile = Tempfile.new("specs")
|
4
|
+
end
|
5
|
+
|
6
|
+
after :each do
|
7
|
+
TempfileSpecs.cleanup @tempfile
|
8
|
+
end
|
9
|
+
|
10
|
+
ruby_bug "", "1.8.6" do
|
11
|
+
it "unlinks self" do
|
12
|
+
@tempfile.close
|
13
|
+
path = @tempfile.path
|
14
|
+
@tempfile.send(@method)
|
15
|
+
File.exists?(path).should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/size_spec.rb
ADDED
data/spec/unlink_spec.rb
ADDED
metadata
CHANGED
@@ -1,118 +1,123 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-tempfile
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Brian Shirai
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2013-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
26
24
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
version: "1.0"
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
36
28
|
name: rake
|
37
|
-
|
38
|
-
|
39
|
-
none: false
|
40
|
-
requirements:
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 10
|
46
|
-
- 0
|
47
|
-
version: "10.0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: mspec
|
52
35
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
56
38
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
63
48
|
type: :development
|
64
|
-
|
65
|
-
|
66
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
description: Ruby standard library tempfile.
|
56
|
+
email:
|
67
57
|
- brixen@gmail.com
|
68
58
|
executables: []
|
69
|
-
|
70
59
|
extensions: []
|
71
|
-
|
72
60
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
61
|
+
files:
|
75
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
76
64
|
- Gemfile
|
77
65
|
- LICENSE
|
78
66
|
- README.md
|
79
67
|
- Rakefile
|
80
|
-
- lib/rubysl
|
81
|
-
- lib/rubysl
|
68
|
+
- lib/rubysl/tempfile.rb
|
69
|
+
- lib/rubysl/tempfile/tempfile.rb
|
70
|
+
- lib/rubysl/tempfile/version.rb
|
71
|
+
- lib/tempfile.rb
|
82
72
|
- rubysl-tempfile.gemspec
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
- spec/_close_spec.rb
|
74
|
+
- spec/callback_spec.rb
|
75
|
+
- spec/close_spec.rb
|
76
|
+
- spec/delete_spec.rb
|
77
|
+
- spec/fixtures/common.rb
|
78
|
+
- spec/initialize_spec.rb
|
79
|
+
- spec/length_spec.rb
|
80
|
+
- spec/open_spec.rb
|
81
|
+
- spec/path_spec.rb
|
82
|
+
- spec/shared/length.rb
|
83
|
+
- spec/shared/unlink.rb
|
84
|
+
- spec/size_spec.rb
|
85
|
+
- spec/unlink_spec.rb
|
86
|
+
homepage: https://github.com/rubysl/rubysl-tempfile
|
87
|
+
licenses:
|
88
|
+
- BSD
|
89
|
+
metadata: {}
|
86
90
|
post_install_message:
|
87
91
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
92
|
+
require_paths:
|
90
93
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
none: false
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
hash: 2002549777813010636
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.8.7
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
109
104
|
requirements: []
|
110
|
-
|
111
105
|
rubyforge_project:
|
112
|
-
rubygems_version:
|
106
|
+
rubygems_version: 2.0.7
|
113
107
|
signing_key:
|
114
|
-
specification_version:
|
115
|
-
summary: Ruby
|
116
|
-
test_files:
|
117
|
-
|
118
|
-
|
108
|
+
specification_version: 4
|
109
|
+
summary: Ruby standard library tempfile.
|
110
|
+
test_files:
|
111
|
+
- spec/_close_spec.rb
|
112
|
+
- spec/callback_spec.rb
|
113
|
+
- spec/close_spec.rb
|
114
|
+
- spec/delete_spec.rb
|
115
|
+
- spec/fixtures/common.rb
|
116
|
+
- spec/initialize_spec.rb
|
117
|
+
- spec/length_spec.rb
|
118
|
+
- spec/open_spec.rb
|
119
|
+
- spec/path_spec.rb
|
120
|
+
- spec/shared/length.rb
|
121
|
+
- spec/shared/unlink.rb
|
122
|
+
- spec/size_spec.rb
|
123
|
+
- spec/unlink_spec.rb
|