Created
September 27, 2011 13:35
-
-
Save floriankrueger/1245050 to your computer and use it in GitHub Desktop.
better db interaction tests with jasmine
This file contains hidden or 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
mongodb = require 'mongodb' | |
Buckets = require '../../models/buckets' | |
describe 'buckets', () -> | |
# suite wide db object | |
db = null | |
# db setup | |
beforeEach -> | |
Db = mongodb.Db | |
Connection = mongodb.Connection | |
Server = mongodb.Server | |
mongodb_host = process.env.MONGO_NODE_DRIVER_HOST || 'localhost' | |
mongodb_port = process.env.MONGO_NODE_DRIVER_PORT || Connection.DEFAULT_PORT | |
server = new Server mongodb_host, mongodb_port, {} | |
db = new Db 'bucket_app_test', server, | |
native_parser: true | |
db.open (err, db) -> | |
if err | |
throw err | |
waitsFor -> db.serverConfig.connected | |
# matchers | |
@addMatchers | |
toBeAnArray: () -> | |
return @actual instanceof Array | |
# db close | |
afterEach -> | |
db.close() | |
describe 'a buckets instance', () -> | |
buckets = null | |
UNLIMITED_USER = null | |
LIMITED_USER = null | |
beforeEach -> | |
# create buckets instance | |
buckets = Buckets.init db, 'buckets' | |
# users | |
UNLIMITED_USER = | |
_id: new db.bson_serializer.ObjectID '4e7cc3fb53a9715214d516e6' | |
name: 'unlimited_user' | |
email: '[email protected]' | |
limit: 0 | |
LIMITED_USER = | |
_id: new db.bson_serializer.ObjectID '4e7cc3fb53a9715214d516e7' | |
name: 'limited_user' | |
email: '[email protected]' | |
limit: 10240 # 10 MB | |
afterEach -> | |
# drop collection to avoid tests to interfere | |
buckets.collection.drop | |
it 'should have a collection property', () -> | |
expect(buckets.collection).not.toBeNull() | |
expect(buckets.collection).toBeDefined() | |
it 'should have an empty list at first', () -> | |
loaded = false | |
buckets.list UNLIMITED_USER, (err, info) -> | |
expect(err).toBeNull() | |
expect(info).toBeDefined() | |
expect(info.buckets).toBeDefined() | |
expect(info.number).toBeDefined() | |
expect(info.totalSize).toBeDefined() | |
expect(info.buckets).toBeAnArray() | |
expect(info.buckets.length).toEqual(0) | |
expect(info.number).toEqual(0) | |
expect(info.totalSize).toEqual(0) | |
loaded = true | |
waitsFor -> loaded |
ich hab das framework jetzt schon mehrfach gewechselt und werde jetzt dabei bleiben, sry ;) aber du kannst ja einen fork machen und es Henriette nennen :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Du solltest ein anderes Testframework nutzen ... Das hat nen schlechte Namen ;)