diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-28 14:47:34 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-28 14:47:34 +0100 |
commit | 4aa66338fce505566a2fe6ba6aee79ddf3f656a2 (patch) | |
tree | ffce4b558735f6a41228542f8c36e3a6ba1e562d /test | |
parent | 8cda844ef12cf87525024348c104413def02ed7f (diff) | |
download | gitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.zip gitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.tar.gz gitbook-4aa66338fce505566a2fe6ba6aee79ddf3f656a2.tar.bz2 |
Add init command
Diffstat (limited to 'test')
-rw-r--r-- | test/all.js | 3 | ||||
-rw-r--r-- | test/assertions.js | 19 | ||||
-rw-r--r-- | test/init.js | 57 |
3 files changed, 76 insertions, 3 deletions
diff --git a/test/all.js b/test/all.js index 9c82c91..67b1661 100644 --- a/test/all.js +++ b/test/all.js @@ -25,3 +25,6 @@ require('./assets-inliner'); require('./output-json'); require('./output-website'); require('./output-ebook'); + +// Misc +require('./init'); diff --git a/test/assertions.js b/test/assertions.js index 56da249..f96fdc1 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -1,18 +1,31 @@ var fs = require('fs'); +var path = require('path'); var _ = require('lodash'); var cheerio = require('cheerio'); var should = require('should'); // Assertions to test if an Output has generated a file should.Assertion.add('file', function(file, description) { + var rootFolder; + if (_.isFunction(this.obj.root)) { + rootFolder = this.obj.root(); + } else { + rootFolder = this.obj; + } + this.params = { - actual: this.obj.root(), + actual: rootFolder, operator: 'have file ' + file, message: description }; - this.obj.should.have.property('resolve').which.is.a.Function; - this.assert(fs.existsSync(this.obj.resolve(file))); + if (_.isFunction(this.obj.resolve)) { + file = this.obj.resolve(file); + } else { + file = path.resolve(rootFolder, file); + } + + this.assert(fs.existsSync(file)); }); should.Assertion.add('html', function(rules, description) { diff --git a/test/init.js b/test/init.js new file mode 100644 index 0000000..e1e8a4a --- /dev/null +++ b/test/init.js @@ -0,0 +1,57 @@ +var Book = require('../lib/book'); +var mock = require('./mock'); + +describe('Init', function() { + + it('should create file according to summary', function() { + return mock.setupFS({ + 'SUMMARY.md': '# Summary\n\n' + + '* [Hello](hello.md)\n' + + '* [Hello 2](hello 2.md)\n' + }) + .then(function(rootFolder) { + return Book.init(mock.fs, rootFolder, { + log: function() {} + }) + .then(function() { + rootFolder.should.have.file('SUMMARY.md'); + rootFolder.should.have.file('README.md'); + rootFolder.should.have.file('hello.md'); + rootFolder.should.have.file('hello 2.md'); + }); + }) + }); + + it('should create file subfolder', function() { + return mock.setupFS({ + 'SUMMARY.md': '# Summary\n\n' + + '* [Hello](test/hello.md)\n' + + '* [Hello 2](test/test2/world.md)\n' + }) + .then(function(rootFolder) { + return Book.init(mock.fs, rootFolder, { + log: function() {} + }) + .then(function() { + rootFolder.should.have.file('README.md'); + rootFolder.should.have.file('SUMMARY.md'); + rootFolder.should.have.file('test/hello.md'); + rootFolder.should.have.file('test/test2/world.md'); + }); + }) + }); + + it('should create SUMMARY if non-existant', function() { + return mock.setupFS({}) + .then(function(rootFolder) { + return Book.init(mock.fs, rootFolder, { + log: function() {} + }) + .then(function() { + rootFolder.should.have.file('SUMMARY.md'); + rootFolder.should.have.file('README.md'); + }); + }) + }); + +}); |