07bf393f34261164063b860c4bb4f54fdded7f0d.svn-base
3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Temporary - The lord of tmp.
*
* Author: Veselin Todorov <hi@vesln.com>
* Licensed under the MIT License.
*/
/**
* Dependencies.
*/
var path = require('path');
var fs = require('fs');
var existsSync = fs.existsSync || path.existsSync;
var Tempfile = require('../lib/file');
var sinon = require('sinon');
var should = require('chai').should();
describe('Tempfile', function() {
it('should create file', function() {
var tmp = new Tempfile('foo');
existsSync(tmp.path).should.be.ok;
});
describe('readFile', function() {
it('should call fs.readfile', function() {
sinon.spy(fs, 'readFile');
var tmp = new Tempfile;
tmp.readFile();
fs.readFile.getCall(0).args[0].should.eql(tmp.path);
fs.readFile.restore();
});
});
describe('readFileSync', function() {
it('should call fs.readfileSync', function() {
sinon.spy(fs, 'readFileSync');
var tmp = new Tempfile;
tmp.readFileSync();
fs.readFileSync.getCall(0).args[0].should.eql(tmp.path);
fs.readFileSync.restore();
});
});
describe('writeFile', function() {
it('should call fs.readfile', function() {
sinon.spy(fs, 'writeFile');
var tmp = new Tempfile;
tmp.writeFile();
fs.writeFile.getCall(0).args[0].should.eql(tmp.path);
fs.writeFile.restore();
});
});
describe('writeFileSync', function() {
it('should call fs.writeFileSync', function() {
sinon.spy(fs, 'writeFileSync');
var tmp = new Tempfile;
tmp.writeFileSync();
fs.writeFileSync.getCall(0).args[0].should.eql(tmp.path);
fs.writeFileSync.restore();
});
});
describe('open', function() {
it('should call fs.open', function() {
sinon.spy(fs, 'open');
var tmp = new Tempfile;
tmp.open('r');
fs.open.getCall(0).args[0].should.eql(tmp.path);
fs.open.restore();
});
});
describe('openSync', function() {
it('should call fs.openSync', function() {
sinon.spy(fs, 'openSync');
var tmp = new Tempfile;
tmp.openSync('r');
fs.openSync.getCall(0).args[0].should.eql(tmp.path);
fs.openSync.restore();
});
});
describe('close', function() {
it('should call fs.close', function() {
sinon.spy(fs, 'close');
var tmp = new Tempfile;
var fd = tmp.openSync('r');
tmp.close(fd);
fs.close.getCall(0).args[0].should.eql(fd);
fs.close.restore();
});
});
describe('closeSync', function() {
it('should call fs.closeSync', function() {
sinon.spy(fs, 'closeSync');
var tmp = new Tempfile;
var fd = tmp.openSync('r');
tmp.closeSync(fd);
fs.closeSync.getCall(0).args[0].should.eql(fd);
fs.closeSync.restore();
});
});
describe('unlink', function() {
it('should call fs.unlink', function() {
sinon.spy(fs, 'unlink');
var tmp = new Tempfile;
tmp.unlink();
fs.unlink.getCall(0).args[0].should.eql(tmp.path);
fs.unlink.restore();
});
});
describe('unlinkSync', function() {
it('should call fs.readfileSync', function() {
sinon.spy(fs, 'unlinkSync');
var tmp = new Tempfile;
tmp.unlinkSync();
fs.unlinkSync.getCall(0).args[0].should.eql(tmp.path);
fs.unlinkSync.restore();
});
});
});