Skip to content

Commit

Permalink
Added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricemach committed Aug 7, 2011
1 parent 3c5114e commit 9a07f55
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/defs.coffee
@@ -0,0 +1,38 @@
zappa = require('./support/tester') require('../src/zappa')

module.exports =
foo: ->
t = zappa ->
def foo: 'bar'
get '/': -> foo

t.get '/', 'bar'

sum: ->
t = zappa ->
def sum: (a, b) -> a + b
get '/': -> String(sum 1, 2)

t.get '/', '3'

byvalue: ->
t = zappa ->
def counter: 0
get '/': ->
counter++
String(counter)

t.get '/', '1'
t.get '/', '1'
t.get '/', '1'

byref: ->
t = zappa ->
def foo: {counter: 0}
get '/': ->
foo.counter++
String(foo.counter)

t.get '/', '3'
t.get '/', '2'
t.get '/', '1'
14 changes: 14 additions & 0 deletions tests/helpers.coffee
@@ -0,0 +1,14 @@
zappa = require('./support/tester') require('../src/zappa')

module.exports =
request: ->
t = zappa ->
helper role: (name) ->
if request?
redirect '/login' unless @user.role is name

get '/': ->
@user = role: 'comonner'
role 'lord'

t.response {url: '/'}, {status: 302, headers: {Location: /\/login$/}}
2 changes: 2 additions & 0 deletions tests/middleware.coffee
Expand Up @@ -4,8 +4,10 @@ module.exports =
'Middleware with vanilla express API': ->
t = zappa {__dirname}, ->
app.use express.static(__dirname + '/public')
app.use express.responseTime()

t.get '/foo.txt', 'bar'
t.response {url: '/'}, {headers: {'X-Response-Time': /\d+ms/}}

'Middleware with `use`': ->
t = zappa {__dirname}, ->
Expand Down
4 changes: 4 additions & 0 deletions tests/routes.coffee
Expand Up @@ -6,10 +6,14 @@ module.exports =
get '/string': 'string'
get '/return': -> 'return'
get '/send': -> send 'send'
get /\/regex$/, 'regex'
get /\/regex_function$/, -> 'regex function'

t.get '/string', 'string'
t.get '/return', 'return'
t.get '/send', 'send'
t.get '/regex', 'regex'
t.get '/regex_function', 'regex function'

verbs: ->
t = zappa ->
Expand Down

0 comments on commit 9a07f55

Please sign in to comment.