Skip to content

Instantly share code, notes, and snippets.

@maiko-ampersand
Created May 4, 2013 07:40
Show Gist options
  • Save maiko-ampersand/5516679 to your computer and use it in GitHub Desktop.
Save maiko-ampersand/5516679 to your computer and use it in GitHub Desktop.
grunt+jasmineな環境作成手順 ref: http://qiita.com/items/0811f788accd3651e04a
sudo npm install -g grunt-cli
Completed in 2.249s at Sat May 04 2013 16:33:33 GMT+0900 (JST) - Waiting...OK
>> File "src/js/sample.js" changed.
Running "jasmine:test" (jasmine) task
Testing jasmine specs via phantom
.
1 spec in 0.002s.
>> 0 failures
Done, without errors.
sudo npm install grunt --save-dev
sudo npm install grunt-contrib-watch --save-dev
sudo npm install grunt-contrib-jasmine --save-dev
Gruntfile.js
package.json
node_modules(自動作成されたフォルダ)
spec(任意作成したフォルダ・テストケースのjsを入れる)
src(任意作成したフォルダ・開発物を入れる)
└js(jsを入れる)
module.exports = function(grunt) {
grunt.initConfig({
watch: {
// src/jsフォルダ以下のjs拡張子ファイルを対象に監視
files: ['src/js/*.js'],
// 変更があったらタスクjasmineを実行
tasks: ['jasmine']
},
jasmine: {
// プロパティ名はテストケース名
sample: {
// このテストケースでテストするファイルの指定
src: 'src/js/sample.js',
options: {
// テストケース
specs: 'spec/*Spec.js',
// ヘルパー
helpers: 'spec/*Helper.js'
}
}
}
});
// gruntでjasmineを使う
grunt.loadNpmTasks('grunt-contrib-jasmine');
// 変更したファイルを監視するためのwatch
grunt.loadNpmTasks('grunt-contrib-watch');
};
{
"name": "practis",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.4.0",
"grunt-contrib-jasmine": "~0.4.2"
}
}
var sample = {};
sample.test = function(param){
return {say : function(){return 'say ' + param}}
}
describe("test case name", function() {
var foo;
beforeEach(function() {
foo = sample.test('hallo');
});
it("should say", function (){
var say = foo.say('hallo');
expect(say).toEqual("say hallo");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment