null+****@clear*****
null+****@clear*****
2012年 5月 22日 (火) 18:19:23 JST
Yoji SHIDARA 2012-05-22 18:19:23 +0900 (Tue, 22 May 2012) New Revision: f701960736ea6a6cd112eb2fa3be0c826428c264 Log: use mocha and should instead of expresso Modified files: package.json test/database.test.coffee Modified: package.json (+3 -2) =================================================================== --- package.json 2012-05-22 11:06:51 +0900 (888cb24) +++ package.json 2012-05-22 18:19:23 +0900 (ca8e983) @@ -14,13 +14,14 @@ }, "devDependencies": { "coffee-script":"", - "expresso":"" + "mocha":"", + "should":"" }, "dependencies": { "msgpack2":"" }, "scripts": { - "test": "expresso", + "test": "./node_modules/.bin/mocha --reporter list -r should --compilers coffee:coffee-script", "watch": "coffee -c -w -o lib src", "install": "node-gyp rebuild" }, Modified: test/database.test.coffee (+28 -26) =================================================================== --- test/database.test.coffee 2012-05-22 11:06:51 +0900 (05a9dee) +++ test/database.test.coffee 2012-05-22 18:19:23 +0900 (e1c4f2c) @@ -1,5 +1,6 @@ nroonga = require('../lib/nroonga') fs = require('fs') +should = require('should') temporaryDatabase = (callback) -> tempdir = 'test/tmp' @@ -55,47 +56,48 @@ withTestDatabase = (callback) -> callback(db) -module.exports = - 'get groonga status by Database#commandSync': (beforeExit, assert) -> - db = new nroonga.Database() - status = db.commandSync('status') - assert.isDefined status.version +describe 'nroonga.Database', -> + db = new nroonga.Database() - 'get groonga status by Database#command': (beforeExit, assert) -> - db = new nroonga.Database() - status = null - db.command 'status', (error, data) -> - status = data + describe '#commandSync', -> + status = db.commandSync('status') + it 'should return groonga result', -> + should.exist(status.version) - beforeExit -> - assert.isDefined status.version + describe '#command', -> + it 'should return nroonga', (done) -> + db.command 'status', (error, data) -> + throw error if error + should.exist(data.version) + done() - 'open database whose name is not string': (beforeExit, assert) -> - errorThrown = null - try +describe 'database whose name is not string', -> + it 'should throw an exception', -> + (-> new nroonga.Database(1) - catch error - errorThrown = error - - beforeExit -> - assert.ok(errorThrown, 'No error thrown') + ).should.throw() - 'create table and store data': (beforeExit, assert) -> +describe 'database with data stored', -> + it 'should select records', (done) -> withTestDatabase (db) -> - assert.equal 3, db.commandSync('select', table: 'Site')[0][0][0] + matched = db.commandSync('select', table: 'Site') + matched[0][0][0].should.equal(3) + done() - 'search data': (beforeExit, assert) -> + it 'should search by query', (done) -> withTestDatabase (db) -> matched = db.commandSync 'select', table: 'Site' match_columns: 'title' query: 'ruby' - assert.equal 1, matched[0][0][0] + matched[0][0][0].should.equal(1) + done() - 'query including space': (beforeExit, assert) -> + it 'should search by query including space', (done) -> withTestDatabase (db) -> matched = db.commandSync 'select', table: 'Site' match_columns: 'title' query: 'search ranguba' - assert.equal 1, matched[0][0][0] + matched[0][0][0].should.equal(1) + done()