diff options
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'); + }); + }) + }); + +}); |