UNPKG

1.18 kBtext/coffeescriptView Raw
1client = require('./client')
2server = require('connect').createServer()
3assert = require('assert')
4
5errors = require '../lib/errors'
6
7server.use require('../lib/lazorse').app ->
8 @route '/frob/{foozle}/{whatsit}':
9 GET: -> @error "teapot"
10 shortName: "frob"
11 examples: [
12 {
13 method: 'GET'
14 vars: {foozle: 'hem', whatsit: 'haw'}
15 }
16 {
17 method: 'GET'
18 vars: {foozle: 'ni', whatsit: 'cate'}
19 body: {
20 thing: 'is'
21 }
22 }
23 ]
24
25
26describe "An app with examples", ->
27 before (start) ->
28 server.listen 0, 'localhost', ->
29 client.usePort server.address().port
30 start()
31
32 after -> server.close()
33
34 it 'has a link to /frob/examples in the index', (done) ->
35 client.GET '/', (res, resources) ->
36 assert.equal res.statusCode, 200
37 assert.equal resources[0].examples, '/examples/frob'
38 done()
39
40 it 'returns expanded paths in the examples', (done) ->
41 client.GET '/examples/frob', (res, examples) ->
42 assert.deepEqual examples, [
43 {method: 'GET', path: '/frob/hem/haw'}
44 {method: 'GET', path: '/frob/ni/cate', body: {thing: 'is'}}
45 ]
46 done()