Skip to content

Commit

Permalink
100% coverage on company.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Jan 6, 2013
1 parent bb60206 commit 8bd901a
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 14 deletions.
12 changes: 9 additions & 3 deletions lib/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ exports.companyName = function (format) {
}
};

exports.suffixes = ["Inc", "and Sons", "LLC", "Group", "and Daughters"];

exports.companySuffix = function () {
return Helpers.randomize(["Inc", "and Sons", "LLC", "Group", "and Daughters"]);
return Helpers.randomize(this.suffixes);
};

exports.catchPhrase = function () {
return Helpers.randomize(definitions.catch_phrase_adjective()) + " " + Helpers.randomize(definitions.catch_phrase_descriptor()) + " " + Helpers.randomize(definitions.catch_phrase_noun());
return Helpers.randomize(definitions.catch_phrase_adjective()) + " " +
Helpers.randomize(definitions.catch_phrase_descriptor()) + " " +
Helpers.randomize(definitions.catch_phrase_noun());
};

exports.bs = function () {
return Helpers.randomize(definitions.bs_adjective()) + " " + Helpers.randomize(definitions.bs_buzz()) + " " + Helpers.randomize(definitions.bs_noun());
return Helpers.randomize(definitions.bs_adjective()) + " " +
Helpers.randomize(definitions.bs_buzz()) + " " +
Helpers.randomize(definitions.bs_noun());
};
107 changes: 107 additions & 0 deletions test/company.unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
var assert = require('assert');
var sinon = require('sinon');
var Faker = require('../index');

describe("company.js", function () {
describe("companyName()", function () {
it("lets you specify the type of name to return", function () {
sinon.spy(Faker.Helpers, 'randomNumber');
var name = Faker.Company.companyName(1);

assert.ok(name.match(/-/));

assert.ok(!Faker.Helpers.randomNumber.called);
Faker.Helpers.randomNumber.restore();
});
it("sometimes returns three last names", function () {
sinon.spy(Faker.definitions, 'last_name');
sinon.stub(Faker.Helpers, 'randomNumber').returns(2);
var name = Faker.Company.companyName();
var parts = name.split(' ');

assert.strictEqual(parts.length, 3);
assert.ok(Faker.definitions.last_name.calledThrice);

Faker.Helpers.randomNumber.restore();
Faker.definitions.last_name.restore();
});

it("sometimes returns two last names separated by a hyphen", function () {
sinon.spy(Faker.definitions, 'last_name');
sinon.stub(Faker.Helpers, 'randomNumber').returns(1);
var name = Faker.Company.companyName();
var parts = name.split('-');

assert.strictEqual(parts.length, 2);
assert.ok(Faker.definitions.last_name.calledTwice);

Faker.Helpers.randomNumber.restore();
Faker.definitions.last_name.restore();
});

it("sometimes returns a last name with a company suffix", function () {
sinon.spy(Faker.Company, 'companySuffix');
sinon.spy(Faker.definitions, 'last_name');
sinon.stub(Faker.Helpers, 'randomNumber').returns(0);
var name = Faker.Company.companyName();
var parts = name.split(' ');

assert.ok(parts.length >= 2);
assert.ok(Faker.definitions.last_name.calledOnce);
assert.ok(Faker.Company.companySuffix.calledOnce);

Faker.Helpers.randomNumber.restore();
Faker.definitions.last_name.restore();
Faker.Company.companySuffix.restore();
});
});

describe("companySuffix()", function () {
it("returns random value from company.suffixes array", function () {
var suffix = Faker.Company.companySuffix();
assert.ok(Faker.Company.suffixes.indexOf(suffix) !== -1);
});
});

describe("catchPhrase()", function () {
it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
sinon.spy(Faker.Helpers, 'randomize');
sinon.spy(Faker.definitions, 'catch_phrase_adjective');
sinon.spy(Faker.definitions, 'catch_phrase_descriptor');
sinon.spy(Faker.definitions, 'catch_phrase_noun');
var phrase = Faker.Company.catchPhrase();

assert.ok(phrase.split(' ').length >= 3);
assert.ok(Faker.Helpers.randomize.calledThrice);
assert.ok(Faker.definitions.catch_phrase_adjective.calledOnce);
assert.ok(Faker.definitions.catch_phrase_descriptor.calledOnce);
assert.ok(Faker.definitions.catch_phrase_noun.calledOnce);

Faker.Helpers.randomize.restore();
Faker.definitions.catch_phrase_adjective.restore();
Faker.definitions.catch_phrase_descriptor.restore();
Faker.definitions.catch_phrase_noun.restore();
});
});

describe("bs()", function () {
it("returns phrase comprising of a BS adjective, buzz, and noun", function () {
sinon.spy(Faker.Helpers, 'randomize');
sinon.spy(Faker.definitions, 'bs_adjective');
sinon.spy(Faker.definitions, 'bs_buzz');
sinon.spy(Faker.definitions, 'bs_noun');
var bs = Faker.Company.bs();

assert.ok(typeof bs === 'string');
assert.ok(Faker.Helpers.randomize.calledThrice);
assert.ok(Faker.definitions.bs_adjective.calledOnce);
assert.ok(Faker.definitions.bs_buzz.calledOnce);
assert.ok(Faker.definitions.bs_noun.calledOnce);

Faker.Helpers.randomize.restore();
Faker.definitions.bs_adjective.restore();
Faker.definitions.bs_buzz.restore();
Faker.definitions.bs_noun.restore();
});
});
});
22 changes: 11 additions & 11 deletions test/name.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var assert = require('assert');
var sinon = require('sinon');
var Faker = require('../index');

describe("name.js", function() {
describe("firstName()", function() {
it("returns a random name from definitions", function(done) {
describe("name.js", function () {
describe("firstName()", function () {
it("returns a random name from definitions", function (done) {
sinon.stub(Faker.definitions, 'first_name').returns(['foo']);
sinon.spy(Faker.Helpers, 'randomize');
sinon.spy(Faker.Helpers, 'randomize');

var first_name = Faker.Name.firstName();

Expand All @@ -20,10 +20,10 @@ describe("name.js", function() {
});
});

describe("lastName()", function() {
it("returns a random name from definitions", function(done) {
describe("lastName()", function () {
it("returns a random name from definitions", function (done) {
sinon.stub(Faker.definitions, 'last_name').returns(['foo']);
sinon.spy(Faker.Helpers, 'randomize');
sinon.spy(Faker.Helpers, 'randomize');

var last_name = Faker.Name.lastName();

Expand All @@ -37,8 +37,8 @@ describe("name.js", function() {
});
});

describe("findName()", function() {
it("usually returns a first name and last name", function() {
describe("findName()", function () {
it("usually returns a first name and last name", function () {
sinon.stub(Faker.Helpers, 'randomNumber').returns(5);
var name = Faker.Name.findName();
assert.ok(name);
Expand All @@ -47,15 +47,15 @@ describe("name.js", function() {
Faker.Helpers.randomNumber.restore();
});

it("occasionally returns a first name and last name with a prefix", function() {
it("occasionally returns a first name and last name with a prefix", function () {
sinon.stub(Faker.Helpers, 'randomNumber').returns(0);
var name = Faker.Name.findName();
var parts = name.split(' ');
assert.strictEqual(parts.length, 3);
Faker.Helpers.randomNumber.restore();
});

it("occasionally returns a first name and last name with a suffix", function() {
it("occasionally returns a first name and last name with a suffix", function () {
sinon.stub(Faker.Helpers, 'randomNumber').returns(1);
var name = Faker.Name.findName();
var parts = name.split(' ');
Expand Down

0 comments on commit 8bd901a

Please sign in to comment.