Skip to content

Commit

Permalink
added protocol() and url()
Browse files Browse the repository at this point in the history
  • Loading branch information
dmamills committed Jan 25, 2015
1 parent a39082f commit 291464f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/internet.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ var internet = {
return result;
},

protocol: function () {
var protocols = ['http','https'];
return faker.random.array_element(protocols);
},

url: function () {
return faker.internet.protocol() + '://' + faker.internet.domainName();
},

domainName: function () {
return faker.internet.domainWord() + "." + faker.internet.domainSuffix();
},
Expand Down
38 changes: 38 additions & 0 deletions test/internet.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ describe("internet.js", function () {
});
});

describe('protocol()', function () {
it('returns a valid protocol', function () {
var protocol = faker.internet.protocol();
assert.ok(protocol);
});

it('should occasionally return http', function () {
sinon.stub(faker.random, 'number').returns(0);
var protocol = faker.internet.protocol();
assert.ok(protocol);
assert.strictEqual(protocol, 'http');

faker.random.number.restore();
});

it('should occasionally return https', function () {
sinon.stub(faker.random, 'number').returns(1);
var protocol = faker.internet.protocol();
assert.ok(protocol);
assert.strictEqual(protocol, 'https');

faker.random.number.restore();
});
});

describe('url()', function () {
it('returns a valid url', function () {
sinon.stub(faker.internet,'protocol').returns('http');
sinon.stub(faker.internet, 'domainWord').returns('bar');
sinon.stub(faker.internet, 'domainSuffix').returns('net');

var url = faker.internet.url();

assert.ok(url);
assert.strictEqual(url,'http://bar.net');
});
});

describe("ip()", function () {
it("returns a random IP address with four parts", function () {
var ip = faker.internet.ip();
Expand Down

0 comments on commit 291464f

Please sign in to comment.