From f4c8bdad2746c2187fce51a8f59e5bd875fc12b4 Mon Sep 17 00:00:00 2001 From: Kyle MacDonald Date: Wed, 26 Mar 2014 16:03:45 -0400 Subject: [PATCH] add additional test coverage --- lib/api/init.coffee | 5 ++++- test/fixtures/no-init/root/index.html | 1 - test/fixtures/no-root/.gitkeep | 0 test/mocha.opts | 2 +- test/test.coffee | 24 ++++++++++++++++++------ 5 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 test/fixtures/no-init/root/index.html create mode 100644 test/fixtures/no-root/.gitkeep diff --git a/lib/api/init.coffee b/lib/api/init.coffee index 3180798..b54c599 100644 --- a/lib/api/init.coffee +++ b/lib/api/init.coffee @@ -82,7 +82,10 @@ class Init extends Base .catch(-> return W.resolve()) copy_template = -> - nodefn.call(ncp, path.join(@sprout_path, 'root'), @target) + root_path = path.join(@sprout_path, 'root') + if not fs.existsSync(root_path) + return W.reject('template does not contain root directory') + nodefn.call(ncp, root_path, @target) replace_ejs = -> nodefn.call(readdirp, { root: @target }) diff --git a/test/fixtures/no-init/root/index.html b/test/fixtures/no-init/root/index.html deleted file mode 100644 index 95fd4a5..0000000 --- a/test/fixtures/no-init/root/index.html +++ /dev/null @@ -1 +0,0 @@ -

no init file: <%= foo %>

diff --git a/test/fixtures/no-root/.gitkeep b/test/fixtures/no-root/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/mocha.opts b/test/mocha.opts index d2e47df..8d6105c 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,3 @@ --reporter spec --compilers coffee:coffee-script/register ---timeout 5000 +--timeout 10000 diff --git a/test/test.coffee b/test/test.coffee index daf50f1..87611e5 100644 --- a/test/test.coffee +++ b/test/test.coffee @@ -53,6 +53,13 @@ describe 'js api', -> .then(-> sprout.remove('foobar')) .done((-> done()), done) + it '[add] errors when a local template is added but doesn\'t actually exist', (done) -> + sprout.add(name: 'foobar', template: path.join(_path, 'not-there')) + .catch((err) -> + should.exist(err) + err.should.match /there is no sprout template located at/ + ).done((-> done()), done) + it '[list] lists available templates', (done) -> start = sprout.list().length sprout.add(name: 'foobar', template: test_template_path, options: {foo: 'bar'}) @@ -157,6 +164,15 @@ describe 'js api', -> .then(-> sprout.remove('foobar-5')) .done((-> done()), done) + it '[init] errors when template does not have `root` directory', (done) -> + test_template = path.join(_path, 'no-root') + sprout.add(name: 'foobar-6', template: test_template) + .then(-> sprout.init(name: 'foobar-6', path: test_path)) + .catch((err) -> + should.exist(err) + err.should.match /template does not contain root directory/ + ).done((-> done()), done) + describe 'cli', -> it '[add] errors when no args provided', -> @@ -218,11 +234,7 @@ describe 'cli', -> rm('-rf', test_path) rmcmd = @exec("#{@$} remove foobar") + # these tests require a better way of responding to the command-line + # prompts. they will remain stubbed for ref until a new solution is found it '[init] creates a project with multiple inquirer inputs' it '[init] errors when prompt entry doesn\'t pass validation' - it '[init] errors when template does not have `root` directory' - it '[init] errors when template does not have `init.coffee` in root dir' - it '[init] errors when template has malformed `init.coffee`' - it '[init] errors when template does not have and `init.coffee` in root dir' - it '[init] does not error when ejs has a key not present in @config_values' - it '[add] errors when a local template is added but doesn\'t actually exist'