|
22 | 22 | @tempfile.path.should_not == "#{Dir.tmpdir}/" |
23 | 23 | end |
24 | 24 |
|
25 | | - it "returns a writable, readable file" do |
| 25 | + it "returns file in w+ mode" do |
26 | 26 | @tempfile = Tempfile.create |
27 | | - File.writable?(@tempfile.path).should be_true |
28 | 27 | @tempfile << "Test!\nMore test!" |
29 | | - @tempfile.seek(0) |
30 | | - @tempfile.gets.should == "Test!\n" |
| 28 | + @tempfile.rewind |
| 29 | + @tempfile.read.should == "Test!\nMore test!" |
| 30 | + |
| 31 | + # Not "a+" mode, which would write at the end of the file. |
| 32 | + @tempfile.rewind |
| 33 | + @tempfile.print "Trust" |
| 34 | + @tempfile.rewind |
| 35 | + @tempfile.read.should == "Trust\nMore test!" |
31 | 36 | end |
32 | 37 |
|
33 | 38 | platform_is_not :windows do |
34 | | - it "returns a private file" do |
| 39 | + it "returns a private, readable and writable file" do |
35 | 40 | @tempfile = Tempfile.create |
36 | | - @tempfile.stat.mode.to_s(8).should.end_with?("600") |
| 41 | + stat = @tempfile.stat |
| 42 | + stat.should.readable? |
| 43 | + stat.should.writable? |
| 44 | + stat.should_not.executable? |
| 45 | + stat.should_not.world_readable? |
| 46 | + stat.should_not.world_writable? |
37 | 47 | end |
38 | 48 | end |
39 | 49 |
|
40 | 50 | platform_is :windows do |
41 | | - it "returns a public file" do |
| 51 | + it "returns a public, readable and writable file" do |
42 | 52 | @tempfile = Tempfile.create |
43 | | - @tempfile.stat.mode.to_s(8).should.end_with?("666") |
| 53 | + stat = @tempfile.stat |
| 54 | + stat.should.readable? |
| 55 | + stat.should.writable? |
| 56 | + stat.should_not.executable? |
| 57 | + stat.should.world_readable? |
| 58 | + stat.should.world_writable? |
44 | 59 | end |
45 | 60 | end |
46 | 61 |
|
47 | 62 | context "when called with a block" do |
48 | 63 | it "returns the value of the block" do |
49 | 64 | value = Tempfile.create do |tempfile| |
50 | 65 | tempfile << "Test!" |
51 | | - @tempfile = tempfile |
52 | 66 | "return" |
53 | 67 | end |
54 | 68 | value.should == "return" |
|
58 | 72 | Tempfile.create do |tempfile| |
59 | 73 | @tempfile = tempfile |
60 | 74 | @tempfile.should_not.closed? |
61 | | - File.file?(@tempfile.path).should be_true |
| 75 | + File.exist?(@tempfile.path).should be_true |
62 | 76 | end |
63 | 77 |
|
64 | 78 | @tempfile.should.closed? |
65 | | - File.file?(@tempfile.path).should be_false |
| 79 | + File.exist?(@tempfile.path).should be_false |
66 | 80 | end |
67 | 81 | end |
68 | 82 |
|
|
73 | 87 | @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec" |
74 | 88 | end |
75 | 89 |
|
| 90 | + it "uses an array of one String as a prefix for the filename" do |
| 91 | + @tempfile = Tempfile.create(["create_spec"]) |
| 92 | + @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") |
| 93 | + @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec" |
| 94 | + end |
| 95 | + |
76 | 96 | it "uses an array of two Strings as a prefix and suffix for the filename" do |
77 | 97 | @tempfile = Tempfile.create(["create_spec", ".temp"]) |
78 | 98 | @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") |
79 | 99 | @tempfile.path.should.end_with?(".temp") |
80 | 100 | end |
81 | 101 |
|
82 | | - it "ignores more than two elements in the array" do |
| 102 | + it "ignores excessive array elements after the first two" do |
83 | 103 | @tempfile = Tempfile.create(["create_spec", ".temp", :".txt"]) |
84 | 104 | @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec") |
85 | 105 | @tempfile.path.should.end_with?(".temp") |
86 | 106 | end |
87 | 107 |
|
88 | 108 | it "raises ArgumentError if passed something else than a String or an array of Strings" do |
89 | | - -> { Tempfile.create(:temp) }.should raise_error(ArgumentError, "unexpected prefix: :temp") |
| 109 | + -> { Tempfile.create(:create_spec) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec") |
| 110 | + -> { Tempfile.create([:create_spec]) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec") |
90 | 111 | -> { Tempfile.create(["create_spec", :temp]) }.should raise_error(ArgumentError, "unexpected suffix: :temp") |
| 112 | + |
91 | 113 | end |
92 | 114 | end |
93 | 115 |
|
|
0 commit comments