Skip to content

Commit

Permalink
convert tests to coffeescript
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Aug 30, 2010
1 parent 38ba57e commit 49f93ad
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 210 deletions.
30 changes: 30 additions & 0 deletions test/get_test.coffee
@@ -0,0 +1,30 @@
ScopedClient = require '../lib'
http = require 'http'
assert = require 'assert'
called = 0

server = http.createServer (req, res) ->
res.writeHead 200, 'Content-Type': 'text/plain'
res.end "#{req.method} #{req.url} -- hello #{req.headers['accept']}"

server.listen 9999

server.on 'listening', ->
client = ScopedClient.create 'http://localhost:9999',
headers:
accept: 'text/plain'

client.get() (err, resp, body) ->
called++
assert.equal 200, resp.statusCode
assert.equal 'text/plain', resp.headers['content-type']
assert.equal 'GET / -- hello text/plain', body
client.path('/a').query('b', '1').get() (err, resp, body) ->
called++
assert.equal 200, resp.statusCode
assert.equal 'text/plain', resp.headers['content-type']
assert.equal 'GET /a?b=1 -- hello text/plain', body
server.close()

process.on 'exit', ->
assert.equal 2, called
38 changes: 38 additions & 0 deletions test/post_test.coffee
@@ -0,0 +1,38 @@
ScopedClient = require '../lib'
http = require 'http'
assert = require 'assert'
called = 0

server = http.createServer (req, res) ->
body = ''
req.on 'data', (chunk) ->
body += chunk

req.on 'end', ->
res.writeHead 200, 'Content-Type': 'text/plain'
res.end "#{req.method} hello: #{body}"

server.listen 9999

server.on 'listening', ->
client = ScopedClient.create 'http://localhost:9999'
client.post((err, req) ->
called++
req.write 'boo', 'ascii'
req.write 'ya', 'ascii'
) (err, resp, body) ->
called++
assert.equal 200, resp.statusCode
assert.equal 'text/plain', resp.headers['content-type']
assert.equal 'POST hello: booya', body

client.post((err, req) ->
req.on 'response', (resp) ->
resp.on 'end', ->
# opportunity to stream response differently
called++
server.close()
)()

process.on 'exit', ->
assert.equal 3, called
47 changes: 47 additions & 0 deletions test/request_test.coffee
@@ -0,0 +1,47 @@
ScopedClient = require('../lib')
http = require('http')
assert = require('assert')
called = 0
curr = null
ua = null

server = http.createServer (req, res) ->
body = ''
req.on 'data', (chunk) ->
body += chunk

req.on 'end', ->
curr = req.method
ua = req.headers['user-agent']
respBody = "#{curr} hello: #{body} #{ua}"
res.writeHead 200,
'content-type': 'text/plain',
'content-length': respBody.length

res.write respBody if curr != 'HEAD'
res.end()

server.listen 9999

server.addListener 'listening', ->
client = ScopedClient.create('http://localhost:9999')
.headers({'user-agent':'bob'})
client.del() (err, resp, body) ->
called++
assert.equal 'DELETE', curr
assert.equal 'bob', ua
assert.equal "DELETE hello: bob", body
client
.header('user-agent', 'fred')
.put('yea') (err, resp, body) ->
called++
assert.equal 'PUT', curr
assert.equal 'fred', ua
assert.equal "PUT hello: yea fred", body
client.head() (err, resp, body) ->
called++
assert.equal 'HEAD', curr
server.close()

process.on 'exit', ->
assert.equal 3, called
34 changes: 0 additions & 34 deletions test/scoped_get_test.js

This file was deleted.

46 changes: 0 additions & 46 deletions test/scoped_post_test.js

This file was deleted.

52 changes: 0 additions & 52 deletions test/scoped_request_test.js

This file was deleted.

78 changes: 0 additions & 78 deletions test/scoped_url_test.js

This file was deleted.

0 comments on commit 49f93ad

Please sign in to comment.