Permalink
Browse files

Add tests

  • Loading branch information...
1 parent e9d295e commit 6d8aa329147988e4e5eec30b7bd2f3769ebd14b4 @EtienneLem committed Jul 8, 2012
Showing with 141 additions and 1 deletion.
  1. +17 −0 Cakefile
  2. +9 −1 package.json
  3. +20 −0 test/helpers.coffee
  4. +4 −0 test/mocha.opts
  5. +27 −0 test/option_parser.coffee
  6. +64 −0 test/skeleton.coffee
View
@@ -0,0 +1,17 @@
+{spawn, exec} = require 'child_process'
+
+task 'test', 'run tests', ->
+ shell 'NODE_ENV=test ./node_modules/.bin/mocha'
+
+###
+* Execute a shell command
+
+* @param {String} command
+* @param {Function} callback
+###
+
+shell = (command, callback=null) ->
+ exec command, (err, stdout, stderr) ->
+ console.log trimStdout if trimStdout = stdout.trim()
+ console.log stderr.trim() if err
+ callback() if callback
View
@@ -13,6 +13,14 @@
"mkdirp": "0.3.x",
"colors": "0.6.x"
},
+ "devDependencies": {
+ "should": "0.6.x",
+ "mocha": "1.3.x",
+ "rimraf": "2.0.x"
+ },
"keywords": ["skeleton", "express", "structure"],
- "bin": { "skeleton": "./bin/skeleton" }
+ "bin": { "skeleton": "./bin/skeleton" },
+ "scripts": {
+ "test": "cake test"
+ }
}
View
@@ -0,0 +1,20 @@
+require "#{__dirname}/../lib/skeleton/helpers"
+
+describe 'helpers', ->
+ describe 'Array', ->
+ describe '#last()', ->
+ it 'should last item of an array', ->
+ ['a', 'b', 'c'].last().should.equal 'c'
+
+ describe '#clone()', ->
+ it 'should make of copy of an array', ->
+ a = [1,2,3]
+ b = a
+ c = a.clone()
+
+ a.should.equal b
+ a.should.not.equal c
+
+ c[0].should.equal 1
+ c[1].should.equal 2
+ c[2].should.equal 3
View
@@ -0,0 +1,4 @@
+--compilers coffee:coffee-script
+--reporter spec
+--require should
+--colors
@@ -0,0 +1,27 @@
+Skeleton = require "#{__dirname}/../lib/skeleton"
+OptionParser = require "#{__dirname}/../lib/skeleton/option_parser"
+assert = require 'assert'
+
+describe 'OptionParser', ->
+ it 'finds and returns the name of the app', ->
+ args = ['--force', 'myapp1', '--css', 'less']
+ options = new OptionParser(args, Skeleton.OPTIONS)
+ options.appName.should.equal 'myapp1'
+
+ args = ['myapp2']
+ options = new OptionParser(args, Skeleton.OPTIONS)
+ options.appName.should.equal 'myapp2'
+
+ args = ['--directory', '~/Desktop', 'myapp3']
+ options = new OptionParser(args, Skeleton.OPTIONS)
+ options.appName.should.equal 'myapp3'
+
+ it 'should throw an error if flag value is not accepted', ->
+ args = ['--css', 'banana']
+ assert.throws ->
+ new OptionParser(args, Skeleton.OPTIONS)
+
+ it 'should remove an argument when it is parsed', ->
+ args = ['--js', 'coffee', '--css', 'stylus']
+ options = new OptionParser(args, Skeleton.OPTIONS)
+ args.length.should.equal 0
View
@@ -0,0 +1,64 @@
+Skeleton = require "#{__dirname}/../lib/skeleton"
+OptionParser = require "#{__dirname}/../lib/skeleton/option_parser"
+
+fs = require 'fs'
+assert = require 'assert'
+rimraf = require 'rimraf'
+
+describe 'skeleton', ->
+ appName = 'myapp'
+ dir = "./test"
+ path = "#{dir}/#{appName}"
+ defaultArgs = ['myapp', '--directory', dir, '--nolog']
+
+ describe 'generator', ->
+ afterEach ->
+ if fs.existsSync path
+ rimraf.sync path
+
+ it 'creates a folder', (done) ->
+ new Skeleton defaultArgs.clone(), ->
+ fs.existsSync(path).should.equal true
+ done()
+
+ describe 'template engine', ->
+ it 'uses ejs (default)', (done) ->
+ new Skeleton defaultArgs.clone(), ->
+ fs.existsSync("#{path}/app/views/index.ejs").should.equal true
+ done()
+
+ it 'uses jade', (done) ->
+ new Skeleton defaultArgs.clone().concat(['--renderer', 'jade']), ->
+ fs.existsSync("#{path}/app/views/index.jade").should.equal true
+ done()
+
+ it 'uses haml (TODO)'
+
+ describe 'css engine', ->
+ it 'uses stylus (default)', (done) ->
+ new Skeleton defaultArgs.clone(), ->
+ fs.existsSync("#{path}/app/assets/css/styles.styl").should.equal true
+ done()
+
+ it 'uses less', (done) ->
+ new Skeleton defaultArgs.clone().concat(['--css', 'less']), ->
+ fs.existsSync("#{path}/app/assets/css/styles.less").should.equal true
+ done()
+
+ it 'uses sass (TODO)'
+
+ it 'uses css', (done) ->
+ new Skeleton defaultArgs.clone().concat(['--css', 'css']), ->
+ fs.existsSync("#{path}/app/assets/css/styles.css").should.equal true
+ done()
+
+ describe 'js engine', ->
+ it 'uses coffeescript (default)', (done) ->
+ new Skeleton defaultArgs.clone(), ->
+ fs.existsSync("#{path}/app/assets/js/scripts.coffee").should.equal true
+ done()
+
+ it 'uses javascript', (done) ->
+ new Skeleton defaultArgs.clone().concat(['--js', 'js']), ->
+ fs.existsSync("#{path}/app/assets/js/scripts.js").should.equal true
+ done()

0 comments on commit 6d8aa32

Please sign in to comment.