Permalink
Browse files

Makefile for running tests on a per-database level

  • Loading branch information...
1 parent 8d05670 commit 8896d3884016d398e5de10c1c2e236f09263300c @lancejpollard lancejpollard committed Aug 3, 2012
Showing with 89 additions and 89 deletions.
  1. +10 −0 Makefile
  2. +56 −61 test/cases/controller/paramsTest.coffee
  3. +18 −27 test/cases/issues/issue92Test.coffee
  4. +5 −1 test/server.coffee
View
@@ -0,0 +1,10 @@
+SRC = $(shell find test -name "*Test.coffee")
+STORES = memory mongodb
+
+test-all:
+ for i in $(STORES); do ./node_modules/mocha/bin/mocha $(SRC) --store $$i; done
+
+test:
+ ./node_modules/mocha/bin/mocha $(SRC) --store memory
+
+.PHONY: test test-all
@@ -1,64 +1,59 @@
# make sure params as strings get properly serialized (integration test)
unless Tower.isClient
- describeWith = (store) ->
- describe "Tower.Controller.Params (Tower.Store.#{store.className()})", ->
- beforeEach (done) ->
- App.Post.store(store)
-
- App.Post.create title: 'First Post', rating: 8, =>
- App.Post.create title: 'Second Post', rating: 7, done
-
- beforeEach (done) ->
- Tower.start(done)
-
- afterEach ->
- Tower.stop()
-
- describe '#index', ->
- test 'GET', (done) ->
- params = {}
-
- _.get '/posts', params: params, (response) ->
- posts = response.controller.get('posts')
- assert.equal 2, posts.length
- assert.deepEqual ['First Post', 'Second Post'], _.map posts, (i) -> i.get('title')
- done()
-
- test 'rating: 8', (done) ->
- params = conditions: JSON.stringify(rating: 8)
-
- _.get '/posts', params: params, (response) ->
- posts = response.controller.get('posts')
- assert.equal 1, posts.length
- done()
-
- test 'rating: >=: 7', (done) ->
- params = conditions: JSON.stringify(rating: '>=': 7)
-
- _.get '/posts', params: params, (response) ->
- posts = response.controller.get('posts')
- assert.equal 2, posts.length
- done()
-
- test 'sort: ["title", "DESC"]', (done) ->
- params = sort: ["title", "DESC"]
-
- _.get '/posts', params: params, (response) ->
- posts = response.controller.get('posts')
- assert.equal 2, posts.length
- assert.deepEqual ['Second Post', 'First Post'], _.map posts, (i) -> i.get('title')
- done()
-
- # test 'limit: 1', (done) ->
- # params = limit: 1
- #
- # _.post '/posts', params: params, (response) ->
- # posts = response.controller.get('posts')
- # assert.equal 1, posts.length
- # done()
-
- test 'date string is serialized to database'
- # params = user: birthdate: _(26).years().ago().toDate()
-
- describeWith(Tower.Store.Memory)
+ describe "Tower.Controller.Params", ->
+ beforeEach (done) ->
+ App.Post.create title: 'First Post', rating: 8, =>
+ App.Post.create title: 'Second Post', rating: 7, done
+
+ beforeEach (done) ->
+ Tower.start(done)
+
+ afterEach ->
+ Tower.stop()
+
+ describe '#index', ->
+ test 'GET', (done) ->
+ params = {}
+
+ _.get '/posts', params: params, (response) ->
+ posts = response.controller.get('posts')
+ assert.equal 2, posts.length
+ assert.deepEqual ['First Post', 'Second Post'], _.map posts, (i) -> i.get('title')
+ done()
+
+ test 'rating: 8', (done) ->
+ params = conditions: JSON.stringify(rating: 8)
+
+ _.get '/posts', params: params, (response) ->
+ posts = response.controller.get('posts')
+ assert.equal 1, posts.length
+ done()
+
+ test 'rating: >=: 7', (done) ->
+ params = conditions: JSON.stringify(rating: '>=': 7)
+
+ _.get '/posts', params: params, (response) ->
+ posts = response.controller.get('posts')
+ assert.equal 2, posts.length
+ done()
+
+ test 'sort: ["title", "DESC"]', (done) ->
+ params = sort: ["title", "DESC"]
+
+ _.get '/posts', params: params, (response) ->
+ posts = response.controller.get('posts')
+ assert.equal 2, posts.length
+ assert.deepEqual ['Second Post', 'First Post'], _.map posts, (i) -> i.get('title')
+ done()
+
+ # test 'limit: 1', (done) ->
+ # params = limit: 1
+ #
+ # _.post '/posts', params: params, (response) ->
+ # posts = response.controller.get('posts')
+ # assert.equal 1, posts.length
+ # done()
+
+ test 'date string is serialized to database'
+ # params = user: birthdate: _(26).years().ago().toDate()
@@ -1,37 +1,28 @@
attr = Tower.Model.Attribute
-describeWith = (store) ->
- describe "Testing Issue #92. (Tower.Store.#{store.className()})", ->
- issue = null
+describe "Testing Issue #92.", ->
+ issue = null
- beforeEach ->
- App.Issue92.store(store)
- issue = App.Issue92.build()
+ beforeEach ->
+ issue = App.Issue92.build()
- test 'test for changing boolean values', (done) ->
- assert.equal issue.get("enabled"), true, 'should be true 1'
+ test 'test for changing boolean values', (done) ->
+ assert.equal issue.get("enabled"), true, 'should be true 1'
- issue.set "enabled", false
- assert.equal issue.get("enabled"), false, 'should be false 2'
+ issue.set "enabled", false
+ assert.equal issue.get("enabled"), false, 'should be false 2'
- issue.save =>
- App.Issue92.find issue.get("id"), (error, issue) =>
- assert.equal issue.get("enabled"), false, 'should be false 3'
+ issue.save =>
+ App.Issue92.find issue.get("id"), (error, issue) =>
+ assert.equal issue.get("enabled"), false, 'should be false 3'
- issue.set "enabled", true
- assert.equal issue.get("enabled"), true, 'should be true 4'
+ issue.set "enabled", true
+ assert.equal issue.get("enabled"), true, 'should be true 4'
- # console.log issue.get('data')
+ # console.log issue.get('data')
- issue.save =>
- App.Issue92.find issue.get("id"), (error, issue) =>
- assert.equal issue.get("enabled"), true, 'should be true 5'
+ issue.save =>
+ App.Issue92.find issue.get("id"), (error, issue) =>
+ assert.equal issue.get("enabled"), true, 'should be true 5'
- done()
-
-describeWith(Tower.Store.Memory)
-
-if Tower.client
- describeWith(Tower.Store.Ajax)
-else
- describeWith(Tower.Store.Mongodb)
+ done()
View
@@ -3,6 +3,9 @@ File = require('pathfinder').File
# mocha $(find test -name "*attributesTest.coffee") --store mongodb
store = require('commander').option('--store [name]', 'Store to run tests against', 'memory').parse(process.argv).store
+
+console.log "Running tests with #{store}"
+
Tower.store = Tower.Store[_.camelize(store)]
global.chai = require 'chai'
@@ -39,7 +42,8 @@ beforeEach (done) ->
Tower.View.store().loadPaths = ["test/example/app/views"]
Tower.Application.instance().initialize ->
- Tower.Store.Mongodb.clean(done)
+ Tower.store.clean =>
+ Tower.Store.Mongodb.clean(done)
after (done) ->
return done()

0 comments on commit 8896d38

Please sign in to comment.