filer/tests/spec/fs.rename.spec.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["Filer", "util"], function(Filer, util) {
2013-11-27 17:18:09 +00:00
describe('fs.rename', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2013-11-27 17:18:09 +00:00
it('should be a function', function() {
var fs = util.fs();
expect(fs.rename).to.be.a('function');
2013-11-27 17:18:09 +00:00
});
it('should rename an existing file', function(done) {
2013-11-27 17:18:09 +00:00
var complete1 = false;
var complete2 = false;
var fs = util.fs();
function maybeDone() {
if(complete1 && complete2) {
done();
}
}
2013-11-27 17:18:09 +00:00
fs.open('/myfile', 'w+', function(error, fd) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.rename('/myfile', '/myotherfile', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
2013-11-27 17:18:09 +00:00
complete1 = true;
maybeDone();
2013-11-27 17:18:09 +00:00
});
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(1);
2013-11-27 17:18:09 +00:00
complete2 = true;
maybeDone();
2013-11-27 17:18:09 +00:00
});
});
});
});
});
});
});