Skip to content

Commit

Permalink
Fixed specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed Apr 15, 2015
1 parent e9764a5 commit 86bf189
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
5 changes: 2 additions & 3 deletions test/decoder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ var should = require('should'),
describe('character encoding', function() {

var url;
this.timeout(5000);

describe('test A', function() {

this.timeout(5000);

before(function() {
url = 'http://www.huanqiukexue.com/html/newgc/2014/1215/25011.html';
})
Expand Down Expand Up @@ -40,7 +39,7 @@ describe('character encoding', function() {
resp.body.indexOf('柳博米尔斯基').should.not.eql(-1);
done();
})

})

})
Expand Down
18 changes: 9 additions & 9 deletions test/errors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,31 @@ describe('errors', function(){
})

it('emits end event once, with error', function(done) {
var called = 0,
var callcount = 0,
stream = needle.get(url);

stream.on('end', function(err) {
called++;
callcount++;
})

setTimeout(function() {
called.should.equal(1);
callcount.should.equal(1);
done();
}, 50)
}, 200)
})

it('error should be ENOTFOUND or EADDRINFO', function(done){
var error,
it('error should be ENOTFOUND or EADDRINFO', function(done) {
var errorific,
stream = needle.get(url);

stream.on('end', function(err) {
error = err;
errorific = err;
})

setTimeout(function() {
error.code.should.match(/ENOTFOUND|EADDRINFO/)
errorific.code.should.match(/ENOTFOUND|EADDRINFO/)
done();
}, 50)
}, 200)
})

it('does not emit a readable event', function(done){
Expand Down
17 changes: 9 additions & 8 deletions test/redirect_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('redirects', function() {
var other_protocol = protocol == 'http' ? 'https' : 'http';

var opts, // each test will modify this
url = protocol + '://localhost:' + ports[protocol] + '/hello';
host = '127.0.0.1',
url = protocol + '://' + host + ':' + ports[protocol] + '/hello';

function send_request(opts, cb) {
opts.rejectUnauthorized = false;
Expand Down Expand Up @@ -161,14 +162,14 @@ describe('redirects', function() {

describe('and redirected to same path on another host, same protocol', function() {
before(function() {
location = url.replace('localhost', hostname);
location = url.replace(host, hostname);
})
it('follows redirect', followed_same_protocol);
})

describe('and redirected to same path on another host, different protocol', function() {
before(function() {
location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
})
it('follows redirect', followed_other_protocol);
})
Expand Down Expand Up @@ -277,7 +278,7 @@ describe('redirects', function() {

it('sets Referer header when following redirect', function(done) {
send_request(opts, function(err, resp) {
spies.http.args[0][0].headers['Referer'].should.eql("http://localhost:8888/hello");
spies.http.args[0][0].headers['Referer'].should.eql("http://" + host + ":8888/hello");
// spies.http.args[0][3].should.eql({ foo: 'bar'});
done();
})
Expand Down Expand Up @@ -323,7 +324,7 @@ describe('redirects', function() {
// by default it will follow other protocols
describe('and redirected to same path on another domain, same protocol', function() {
before(function() {
location = url.replace('localhost', hostname);
location = url.replace(host, hostname);
})
it('follows redirect', followed_same_protocol);
})
Expand All @@ -339,7 +340,7 @@ describe('redirects', function() {
// by default it will follow other protocols
describe('and redirected to same path on another domain, same protocol', function() {
before(function() {
location = url.replace('localhost', hostname);
location = url.replace(host, hostname);
})

it('does not follow redirect', not_followed);
Expand All @@ -356,7 +357,7 @@ describe('redirects', function() {
// by default it will follow other hosts
describe('and redirected to same path on another domain, different protocol', function() {
before(function() {
location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
})
it('follows redirect', followed_other_protocol);
})
Expand All @@ -372,7 +373,7 @@ describe('redirects', function() {
// by default it will follow other hosts
describe('and redirected to same path on another domain, different protocol', function() {
before(function() {
location = url.replace('localhost', hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
location = url.replace(host, hostname).replace(protocol, other_protocol).replace(ports[protocol], ports[other_protocol]);
})
it('does not follow redirect', not_followed);
})
Expand Down

0 comments on commit 86bf189

Please sign in to comment.