Forked from adomokos/mocha_sample_project_install.sh
Created
February 19, 2012 19:17
-
-
Save roblevintennis/1865261 to your computer and use it in GitHub Desktop.
Set up sample project with mocha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function create_dir { | |
if [ ! -d $1 ]; | |
then | |
mkdir $1 | |
fi | |
} | |
echo "create the src directory..." | |
create_dir src | |
echo "create the test directory..." | |
create_dir test | |
echo "write the package.json file..." | |
echo '{ | |
"name": "sample_project", | |
"version": "0.0.1", | |
"engines": { | |
"node": "0.6.6" | |
}, | |
"scripts": {"test": "./node_modules/mocha/bin/mocha"}, | |
"dependencies":{ | |
"mocha": "latest", | |
"should": "latest", | |
"sinon": "latest" | |
} | |
}' > package.json | |
echo "install npm packages..." | |
npm install | |
echo "create a sample spec file..." | |
echo "var should = require('should'); | |
var Person = require(__dirname + '/../src/person'); | |
describe('Person', function() { | |
it('should be able to say hello', function() { | |
var Person = global.theApp.Person(); | |
var personInstance = new Person(); | |
var message = personInstance.sayHelloTo('adomokos'); | |
message.should.equal('Hello, adomokos!'); | |
}); | |
});" > test/person_spec.js | |
echo "create a sample src file..." | |
echo "global.theApp = {}; | |
global.theApp.Person = function() { | |
var Person = function() { | |
this.sayHelloTo = function(anotherPerson) { | |
return 'Hello, ' + anotherPerson + '!'; | |
}; | |
}; | |
return Person; | |
};" > src/person.js | |
echo "run the spec with mocha..." | |
node_modules/mocha/bin/mocha | |
echo "run the spec with list reporter..." | |
node_modules/mocha/bin/mocha -R list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment