Permalink
Browse files

Added chmod and init tests

  • Loading branch information...
1 parent ef37dc9 commit ec26f559ec540501b0f04b469ad777a7e69024ad @filipediasf filipediasf committed Jan 5, 2013
Showing with 208 additions and 8 deletions.
  1. +173 −5 test/tasks/chmod.js
  2. +35 −3 test/tasks/init.js
View
@@ -1,11 +1,179 @@
-var expect = require('expect.js')
+var expect = require('expect.js'),
+ isFile = require('../helpers/util/is-file'),
+ isDir = require('../helpers/util/is-dir'),
+ fs = require('fs')
;
module.exports = function (automaton) {
describe('chmod', function () {
- it.skip('should change mode of files');
- it.skip('should accept a file or an array of files');
- it.skip('should accept minimatch patterns');
- it.skip('should pass over the glob options');
+ it('should change mode of files', function (done) {
+
+ var dir = __dirname + '/../tmp/chmod/',
+ file = 'file.js',
+ expectedMode = process.platform === 'win32' ? 16822 : 16877;
+
+ // create dir
+ fs.mkdirSync(dir, parseInt('0777', 8), function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isDir(dir)).to.be(true);
+ });
+
+ // create file
+ fs.writeFileSync(dir + file, 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(dir + file)).to.be(true);
+ });
+
+
+ automaton.run('chmod', {
+ files: dir + file,
+ mode: '0755'
+ }, function (err) {
+ if (err) {
+ done(err);
+ }
+
+ expect(fs.statSync(dir + file).mode === expectedMode).to.be(true);
+ done();
+ });
+ });
+
+ it('should accept a file or an array of files', function (done) {
+ var dir = __dirname + '/../tmp/chmod/',
+ file1 = 'file1.js',
+ file2 = 'file2.js',
+ files = [],
+ expectedMode = process.platform === 'win32' ? 16822 : 16877;
+
+ files.push(dir + file1);
+ files.push(dir + file2);
+
+ // create dir
+ fs.mkdirSync(dir, parseInt('0777', 8), function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isDir(dir)).to.be(true);
+ });
+
+ // create file1
+ fs.writeFileSync(files[0], 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(files[0])).to.be(true);
+ });
+
+ // create file2
+ fs.writeFileSync(files[1], 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(files[1])).to.be(true);
+ });
+
+
+ automaton.run('chmod', {
+ files: files,
+ mode: '0755'
+ }, function (err) {
+ if (err) {
+ done(err);
+ }
+
+ expect(fs.statSync(files[0]).mode === expectedMode).to.be(true);
+ expect(fs.statSync(files[1]).mode === expectedMode).to.be(true);
+
+ done();
+ });
+ });
+
+ it('should accept minimatch patterns', function (done) {
+ var dir = __dirname + '/../tmp/chmod/',
+ file1 = 'file1.js',
+ file2 = 'file2.js',
+ files = [],
+ expectedMode = process.platform === 'win32' ? 16822 : 16877;
+
+ files.push(dir + file1);
+ files.push(dir + file2);
+
+ // create dir
+ fs.mkdirSync(dir, parseInt('0777', 8), function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isDir(dir)).to.be(true);
+ });
+
+ // create file1
+ fs.writeFileSync(files[0], 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(files[0])).to.be(true);
+ });
+
+ // create file2
+ fs.writeFileSync(files[1], 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(files[1])).to.be(true);
+ });
+
+
+ automaton.run('chmod', {
+ files: dir + '*.js',
+ mode: '0755'
+ }, function (err) {
+ if (err) {
+ done(err);
+ }
+
+ expect(fs.statSync(files[0]).mode === expectedMode).to.be(true);
+ expect(fs.statSync(files[1]).mode === expectedMode).to.be(true);
+
+ done();
+ });
+ });
+
+ it('should pass over the glob options', function (done) {
+ var dir = __dirname + '/../tmp/chmod/',
+ file = '.file.js',
+ expectedMode = process.platform === 33188;
+
+ // create dir
+ fs.mkdirSync(dir, parseInt('0777', 8), function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isDir(dir)).to.be(true);
+ });
+
+ // create file
+ fs.writeFileSync(dir + file, 'dummy', 'utf8', function (err) {
+ if (err) {
+ return done(err);
+ }
+ expect(isFile(dir + file)).to.be(true);
+ });
+
+ automaton.run('chmod', {
+ files: dir + '*.js',
+ mode: '0755',
+ dot: false
+ }, function (err) {
+ console.log(err);
+
+
+ expect(fs.statSync(dir + file).mode === expectedMode).to.be(true);
+ done();
+ });
+ });
});
};
View
@@ -1,5 +1,7 @@
var expect = require('expect.js'),
- isFile = require('../helpers/util/is-file')
+ isFile = require('../helpers/util/is-file'),
+ isDir = require('../helpers/util/is-dir'),
+ fs = require('fs')
;
module.exports = function (automaton) {
@@ -38,8 +40,38 @@ module.exports = function (automaton) {
});
});
- it.skip('should throw an error if the autofile already exists', function () {
- // test with dst and withouy dstß
+ it('should throw an error if the autofile already exists', function (done) {
+
+ var dir = __dirname + '/../tmp/init/',
+ file = 'autofile_exists.js';
+
+ // create dir
+ fs.mkdirSync(dir, parseInt('0777', 8), function (err) {
+
+ if (err) {
+ return done(err);
+ }
+
+ expect(isDir(dir)).to.be(true);
+ });
+
+ // create file
+ fs.writeFileSync(dir + file, 'dummy', 'utf8', function (err) {
+
+ if (err) {
+ return done(err);
+ }
+
+ expect(isFile(dir + file)).to.be(true);
+ });
+
+ automaton.run('init', {
+ name: file,
+ dst: dir
+ }, function (err) {
+ expect(err !== null).to.be(true);
+ done();
+ });
});
});
};

0 comments on commit ec26f55

Please sign in to comment.