diff options
| author | Bryan Donovan <[email protected]> | 2013-01-05 19:28:19 -0800 |
|---|---|---|
| committer | Bryan Donovan <[email protected]> | 2013-01-05 19:28:19 -0800 |
| commit | 8bd901a6b09fd390fa5b78a83d08c9e81bb93a27 (patch) | |
| tree | ceb63359cbc48563fa4ef72e18203cb3f76f0373 | |
| parent | bb60206f991652cef84b218fce31a0e86c7ee7fa (diff) | |
| download | faker-8bd901a6b09fd390fa5b78a83d08c9e81bb93a27.tar.xz faker-8bd901a6b09fd390fa5b78a83d08c9e81bb93a27.zip | |
100% coverage on company.js
| -rw-r--r-- | lib/company.js | 12 | ||||
| -rw-r--r-- | test/company.unit.js | 107 | ||||
| -rw-r--r-- | test/name.unit.js | 22 |
3 files changed, 127 insertions, 14 deletions
diff --git a/lib/company.js b/lib/company.js index 11e31e53..d325cfa4 100644 --- a/lib/company.js +++ b/lib/company.js @@ -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()); }; diff --git a/test/company.unit.js b/test/company.unit.js new file mode 100644 index 00000000..0505be65 --- /dev/null +++ b/test/company.unit.js @@ -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(); + }); + }); +}); diff --git a/test/name.unit.js b/test/name.unit.js index a090ad7e..89627cd0 100644 --- a/test/name.unit.js +++ b/test/name.unit.js @@ -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(); @@ -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(); @@ -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); @@ -47,7 +47,7 @@ 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(' '); @@ -55,7 +55,7 @@ describe("name.js", function() { 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(' '); |
