1 | client = require('./client')
|
2 | server = require('connect').createServer()
|
3 | assert = require('assert')
|
4 |
|
5 | errors = require '../lib/errors'
|
6 |
|
7 | server.use require('../lib/lazorse').app ->
|
8 | @resource '/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 |
|
26 | describe "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 | resource = null
|
38 | resources.some (r) -> r.shortName is 'frob' and resource = r
|
39 | assert.equal resource?.examples, '/examples/frob'
|
40 | done()
|
41 |
|
42 | it 'returns expanded paths in the examples', (done) ->
|
43 | client.GET '/examples/frob', (res, examples) ->
|
44 | assert.deepEqual examples, [
|
45 | {method: 'GET', path: '/frob/hem/haw'}
|
46 | {method: 'GET', path: '/frob/ni/cate', body: {thing: 'is'}}
|
47 | ]
|
48 | done()
|