Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 14, 2012
1 parent 1f668f0 commit 2804861
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -22,7 +22,8 @@
"mime": "1.2.5",
"emitter-component": "0.0.6",
"methods": "0.0.1",
"cookiejar": "1.3.0"
"cookiejar": "1.3.0",
"better-assert": "~0.1.0"
},
"devDependencies": {
"express": "3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion test/node/agency.js
Expand Up @@ -141,7 +141,7 @@ describe('request', function() {
should.not.exist(err);
res.should.have.status(302);
res.redirects.should.eql([]);
res.header.location.should.equal('//localhost:4000/dashboard');
res.header.location.should.equal('/dashboard');
done();
});
});
Expand Down
54 changes: 27 additions & 27 deletions test/node/basic.js
@@ -1,8 +1,8 @@

var EventEmitter = require('events').EventEmitter
, request = require('../../')
, request = require('../..')
, express = require('express')
, assert = require('assert')
, assert = require('better-assert')
, app = express()
, url = require('url');

Expand Down Expand Up @@ -50,13 +50,13 @@ app.get('/custom', function(req, res){
res.send('custom stuff');
});

app.listen(3000);
app.listen(5000);

describe('request', function(){
describe('with an object', function(){
it('should format the url', function(done){
request
.get(url.parse('http://localhost:3000/login'))
.get(url.parse('http://localhost:5000/login'))
.end(function(res){
assert(res.ok);
done();
Expand All @@ -67,7 +67,7 @@ describe('request', function(){
describe('with a callback', function(){
it('should invoke .end()', function(done){
request
.get('localhost:3000/login', function(res){
.get('localhost:5000/login', function(res){
assert(res.status == 200);
done();
})
Expand All @@ -77,7 +77,7 @@ describe('request', function(){
describe('without a schema', function(){
it('should default to http', function(done){
request
.get('localhost:3000/login')
.get('localhost:5000/login')
.end(function(res){
assert(res.status == 200);
done();
Expand All @@ -88,7 +88,7 @@ describe('request', function(){
describe('.end()', function(){
it('should issue a request', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
assert(res.status == 200);
done();
Expand All @@ -99,7 +99,7 @@ describe('request', function(){
describe('res.header', function(){
it('should be an object', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
assert('Express' == res.header['x-powered-by']);
done();
Expand All @@ -110,7 +110,7 @@ describe('request', function(){
describe('res.charset', function(){
it('should be set when present', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
res.charset.should.equal('utf-8');
done();
Expand All @@ -121,7 +121,7 @@ describe('request', function(){
describe('res.statusType', function(){
it('should provide the first digit', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
assert(200 == res.status);
assert(2 == res.statusType);
Expand All @@ -133,7 +133,7 @@ describe('request', function(){
describe('res.type', function(){
it('should provide the mime-type void of params', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
res.type.should.equal('text/html');
res.charset.should.equal('utf-8');
Expand All @@ -145,7 +145,7 @@ describe('request', function(){
describe('res.links', function(){
it('should default to an empty object', function(done){
request
.get('http://localhost:3000/login')
.get('http://localhost:5000/login')
.end(function(res){
res.links.should.eql({});
done();
Expand All @@ -154,7 +154,7 @@ describe('request', function(){

it('should parse the Link header field', function(done){
request
.get('http://localhost:3000/links')
.get('http://localhost:5000/links')
.end(function(res){
res.links.next.should.equal('https://api.github.com/repos/visionmedia/mocha/issues?page=2');
done();
Expand All @@ -165,7 +165,7 @@ describe('request', function(){
describe('req.set(field, val)', function(){
it('should set the header field', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.set('X-Foo', 'bar')
.set('X-Bar', 'baz')
.end(function(res){
Expand All @@ -179,7 +179,7 @@ describe('request', function(){
describe('req.set(obj)', function(){
it('should set the header fields', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.set({ 'X-Foo': 'bar', 'X-Bar': 'baz' })
.end(function(res){
assert('bar' == res.header['x-foo']);
Expand All @@ -192,7 +192,7 @@ describe('request', function(){
describe('req.type(str)', function(){
it('should set the Content-Type', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('text/x-foo')
.end(function(res){
res.header['content-type'].should.equal('text/x-foo');
Expand All @@ -202,7 +202,7 @@ describe('request', function(){

it('should map "json"', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('json')
.end(function(res){
res.should.be.json;
Expand All @@ -212,7 +212,7 @@ describe('request', function(){

it('should map "html"', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('html')
.end(function(res){
res.header['content-type'].should.equal('text/html');
Expand All @@ -223,7 +223,7 @@ describe('request', function(){

describe('req.write(str)', function(){
it('should write the given data', function(done){
var req = request.post('http://localhost:3000/echo');
var req = request.post('http://localhost:5000/echo');
req.set('Content-Type', 'application/json');
req.write('{"name"').should.be.a('boolean');
req.write(':"tobi"}').should.be.a('boolean');
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('request', function(){
};

request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.send('{"name":"tobi"}')
.pipe(stream);
})
Expand All @@ -260,7 +260,7 @@ describe('request', function(){
describe('req.send(str)', function(){
it('should write the string', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('json')
.send('{"name":"tobi"}')
.end(function(res){
Expand All @@ -273,7 +273,7 @@ describe('request', function(){
describe('req.send(Object)', function(){
it('should default to json', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.send({ name: 'tobi' })
.end(function(res){
res.should.be.json
Expand All @@ -285,7 +285,7 @@ describe('request', function(){
describe('when called several times', function(){
it('should merge the objects', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.send({ name: 'tobi' })
.send({ age: 1 })
.end(function(res){
Expand All @@ -301,7 +301,7 @@ describe('request', function(){
describe('.end(fn)', function(){
it('should check arity', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.send({ name: 'tobi' })
.end(function(err, res){
assert(null == err);
Expand All @@ -314,7 +314,7 @@ describe('request', function(){
describe('.buffer()', function(){
it('should enable buffering', function(done){
request
.get('http://localhost:3000/custom')
.get('http://localhost:5000/custom')
.buffer()
.end(function(err, res){
assert(null == err);
Expand All @@ -328,7 +328,7 @@ describe('request', function(){
describe('.buffer(false)', function(){
it('should disable buffering', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('application/x-dog')
.send('hello this is dog')
.buffer(false)
Expand All @@ -350,7 +350,7 @@ describe('request', function(){
describe('with a content type other than application/json or text/*', function(){
it('should disable buffering', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:5000/echo')
.type('application/x-dog')
.send('hello this is dog')
.end(function(err, res){
Expand Down
4 changes: 2 additions & 2 deletions test/node/form.js
@@ -1,7 +1,7 @@

var request = require('../../')
, express = require('express')
, assert = require('assert')
, assert = require('better-assert')
, app = express();

app.post('/echo', function(req, res){
Expand All @@ -20,7 +20,7 @@ describe('req.send(Object) as "form"', function(){
describe('with req.type() set to form', function(){
it('should send x-www-form-urlencoded data', function(done){
request
.post('http://localhost:3000/echo')
.post('http://localhost:3002/echo')
.type('form')
.send({ name: 'tobi' })
.end(function(res){
Expand Down
12 changes: 6 additions & 6 deletions test/node/redirects.js
Expand Up @@ -49,9 +49,9 @@ describe('request', function(){
})
.end(function(res){
var arr = [];
arr.push('//localhost:3003/movies');
arr.push('//localhost:3003/movies/all');
arr.push('//localhost:3003/movies/all/0');
arr.push('/movies');
arr.push('/movies/all');
arr.push('/movies/all/0');
redirects.should.eql(arr);
res.text.should.equal('first movie page');
done();
Expand Down Expand Up @@ -90,8 +90,8 @@ describe('request', function(){
.end(function(res){
var arr = [];
assert(res.redirect, 'res.redirect');
arr.push('//localhost:3003/movies');
arr.push('//localhost:3003/movies/all');
arr.push('/movies');
arr.push('/movies/all');
redirects.should.eql(arr);
res.text.should.match(/Moved Temporarily/);
done();
Expand All @@ -112,7 +112,7 @@ describe('request', function(){
})
.end(function(res){
var arr = [];
arr.push('//localhost:3003/movies/all/0');
arr.push('/movies/all/0');
redirects.should.eql(arr);
res.text.should.equal('first movie page');
done();
Expand Down

0 comments on commit 2804861

Please sign in to comment.