diff --git a/tests/index.js b/tests/index.js index db38549..beb517f 100644 --- a/tests/index.js +++ b/tests/index.js @@ -36,7 +36,6 @@ require('./spec/fs.truncate.spec'); require('./spec/fs.ftruncate.spec'); require('./spec/fs.utimes.spec'); require('./spec/fs.xattr.spec'); -require('./spec/fs.stats.spec'); require('./spec/path-resolution.spec'); require('./spec/trailing-slashes.spec'); require('./spec/times.spec'); diff --git a/tests/spec/fs.stat.spec.js b/tests/spec/fs.stat.spec.js index b14d109..5b95d39 100644 --- a/tests/spec/fs.stat.spec.js +++ b/tests/spec/fs.stat.spec.js @@ -2,6 +2,7 @@ var util = require('../lib/test-utils.js'); var chai = require('chai'); chai.use(require('chai-datetime')); var expect = chai.expect; +var Path = require('../../src').Path; describe('fs.stat', function() { beforeEach(util.setup); @@ -215,6 +216,291 @@ describe('fs.stat', function() { }); }); }); + + describe('fs.stats', function() { + describe('#isFile()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFile).to.be.a('function'); + done(); + }); + }); + + it('should return true if stats are for file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.fstat(fd, function(error, stats) { + expect(error).not.to.exist; + expect(stats.isFile()).to.be.true; + fs.close(fd, done); + }); + }); + }); + + it('should return false if stats are for directory', function(done) { + var fs = util.fs(); + + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFile()).to.be.false; + done(); + }); + }); + + it('should return false if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + + fs.close(fd, function(error) { + if(error) throw error; + + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + fs.lstat('/myfilelink', function(error, stats) { + expect(error).not.to.exist; + expect(stats.isFile()).to.be.false; + done(); + }); + }); + }); + }); + }); + }); + + describe('#isDirectory()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isDirectory).to.be.a('function'); + done(); + }); + }); + + it('should return false if stats are for file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.fstat(fd, function(error, stats) { + expect(error).not.to.exist; + expect(stats.isDirectory()).to.be.false; + fs.close(fd, done); + }); + }); + }); + + it('should return true if stats are for directory', function(done) { + var fs = util.fs(); + + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isDirectory()).to.be.true; + done(); + }); + }); + + it('should return false if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.close(fd, function(error) { + if(error) throw error; + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + fs.lstat('/myfilelink', function(error, stats) { + expect(stats.isDirectory()).to.be.false; + done(); + }); + }); + }); + }); + }); + }); + + describe('#isBlockDevice()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isBlockDevice).to.be.a('function'); + done(); + }); + }); + + it('should return false', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isBlockDevice()).to.be.false; + done(); + }); + }); + }); + + describe('#isCharacterDevice()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isCharacterDevice).to.be.a('function'); + done(); + }); + }); + + it('should return false', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isCharacterDevice()).to.be.false; + done(); + }); + }); + }); + + describe('#isSymbolicLink()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSymbolicLink).to.be.a('function'); + done(); + }); + }); + + it('should return false if stats are for file', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.fstat(fd, function(error, stats) { + expect(error).not.to.exist; + expect(stats.isSymbolicLink()).to.be.false; + fs.close(fd, done); + }); + }); + }); + + it('should return false if stats are for directory', function(done) { + var fs = util.fs(); + + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSymbolicLink()).to.be.false; + done(); + }); + }); + + it('should return true if stats are for symbolic link', function(done) { + var fs = util.fs(); + + fs.open('/myfile', 'w+', function(error, fd) { + if(error) throw error; + fs.close(fd, function(error) { + if(error) throw error; + fs.symlink('/myfile', '/myfilelink', function(error) { + if(error) throw error; + fs.lstat('/myfilelink', function(error, stats) { + expect(stats.isSymbolicLink()).to.be.true; + done(); + }); + }); + }); + }); + }); + }); + + describe('#isFIFO()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFIFO).to.be.a('function'); + done(); + }); + }); + + it('should return false', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isFIFO()).to.be.false; + done(); + }); + }); + }); + + describe('#isSocket()', function() { + + it('should be a function', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSocket).to.be.a('function'); + done(); + }); + }); + + it('should return false', function(done) { + var fs = util.fs(); + fs.stat('/', function(error, stats) { + if(error) throw error; + expect(stats.isSocket()).to.be.false; + done(); + }); + }); + }); + + describe('generated name property', function() { + + it('should correct return name for a file', function(done) { + var fs = util.fs(); + var filepath = '/a'; + + fs.writeFile(filepath, 'data', function(err) { + if(err) throw err; + + fs.stat(filepath, function(err, stats) { + if(err) throw err; + + expect(stats.name).to.equal(Path.basename(filepath)); + done(); + }); + }); + }); + + it('should correct return name for an fd', function(done) { + var fs = util.fs(); + var filepath = '/a'; + + fs.open(filepath, 'w', function(err, fd) { + if(err) throw err; + + fs.fstat(fd, function(err, stats) { + if(err) throw err; + + expect(stats.name).to.equal(Path.basename(filepath)); + fs.close(fd, done); + }); + }); + }); + }); + }); + }); /** diff --git a/tests/spec/fs.stats.spec.js b/tests/spec/fs.stats.spec.js deleted file mode 100644 index 79e7fb7..0000000 --- a/tests/spec/fs.stats.spec.js +++ /dev/null @@ -1,303 +0,0 @@ -var Path = require('../../src').Path; -var util = require('../lib/test-utils.js'); -var expect = require('chai').expect; - -describe('fs.stats', function() { - describe('#isFile()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFile).to.be.a('function'); - done(); - }); - }); - - it('should return true if stats are for file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.fstat(fd, function(error, stats) { - expect(error).not.to.exist; - expect(stats.isFile()).to.be.true; - fs.close(fd, done); - }); - }); - }); - - it('should return false if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFile()).to.be.false; - done(); - }); - }); - - it('should return false if stats are for symbolic link', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - - fs.close(fd, function(error) { - if(error) throw error; - - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(error).not.to.exist; - expect(stats.isFile()).to.be.false; - done(); - }); - }); - }); - }); - }); - }); - - describe('#isDirectory()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isDirectory).to.be.a('function'); - done(); - }); - }); - - it('should return false if stats are for file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.fstat(fd, function(error, stats) { - expect(error).not.to.exist; - expect(stats.isDirectory()).to.be.false; - fs.close(fd, done); - }); - }); - }); - - it('should return true if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isDirectory()).to.be.true; - done(); - }); - }); - - it('should return false if stats are for symbolic link', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.close(fd, function(error) { - if(error) throw error; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(stats.isDirectory()).to.be.false; - done(); - }); - }); - }); - }); - }); - }); - - describe('#isBlockDevice()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isBlockDevice).to.be.a('function'); - done(); - }); - }); - - it('should return false', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isBlockDevice()).to.be.false; - done(); - }); - }); - }); - - describe('#isCharacterDevice()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isCharacterDevice).to.be.a('function'); - done(); - }); - }); - - it('should return false', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isCharacterDevice()).to.be.false; - done(); - }); - }); - }); - - describe('#isSymbolicLink()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSymbolicLink).to.be.a('function'); - done(); - }); - }); - - it('should return false if stats are for file', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.fstat(fd, function(error, stats) { - expect(error).not.to.exist; - expect(stats.isSymbolicLink()).to.be.false; - fs.close(fd, done); - }); - }); - }); - - it('should return false if stats are for directory', function(done) { - var fs = util.fs(); - - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSymbolicLink()).to.be.false; - done(); - }); - }); - - it('should return true if stats are for symbolic link', function(done) { - var fs = util.fs(); - - fs.open('/myfile', 'w+', function(error, fd) { - if(error) throw error; - fs.close(fd, function(error) { - if(error) throw error; - fs.symlink('/myfile', '/myfilelink', function(error) { - if(error) throw error; - fs.lstat('/myfilelink', function(error, stats) { - expect(stats.isSymbolicLink()).to.be.true; - done(); - }); - }); - }); - }); - }); - }); - - describe('#isFIFO()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFIFO).to.be.a('function'); - done(); - }); - }); - - it('should return false', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isFIFO()).to.be.false; - done(); - }); - }); - }); - - describe('#isSocket()', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should be a function', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSocket).to.be.a('function'); - done(); - }); - }); - - it('should return false', function(done) { - var fs = util.fs(); - fs.stat('/', function(error, stats) { - if(error) throw error; - expect(stats.isSocket()).to.be.false; - done(); - }); - }); - }); - - describe('generated name property', function() { - beforeEach(util.setup); - afterEach(util.cleanup); - - it('should correct return name for a file', function(done) { - var fs = util.fs(); - var filepath = '/a'; - - fs.writeFile(filepath, 'data', function(err) { - if(err) throw err; - - fs.stat(filepath, function(err, stats) { - if(err) throw err; - - expect(stats.name).to.equal(Path.basename(filepath)); - done(); - }); - }); - }); - - it('should correct return name for an fd', function(done) { - var fs = util.fs(); - var filepath = '/a'; - - fs.open(filepath, 'w', function(err, fd) { - if(err) throw err; - - fs.fstat(fd, function(err, stats) { - if(err) throw err; - - expect(stats.name).to.equal(Path.basename(filepath)); - fs.close(fd, done); - }); - }); - }); - }); -});