diff options
| author | Bryan Donovan <[email protected]> | 2013-01-05 19:54:21 -0800 |
|---|---|---|
| committer | Bryan Donovan <[email protected]> | 2013-01-05 19:54:21 -0800 |
| commit | 0b3cfbee64547e7a624c8d8f988c293ed463cf4b (patch) | |
| tree | 46b926661b16b3eb8f911777c2fb8f699d8785f1 /test | |
| parent | 8a6ad8d2de768aff38e09cda46fc0dfd2d52b2b8 (diff) | |
| download | faker-0b3cfbee64547e7a624c8d8f988c293ed463cf4b.tar.xz faker-0b3cfbee64547e7a624c8d8f988c293ed463cf4b.zip | |
refactoring so we do not need to use Helpers.randomize() everywhere
Diffstat (limited to 'test')
| -rw-r--r-- | test/company.unit.js | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/test/company.unit.js b/test/company.unit.js index 23402229..c7f6ae99 100644 --- a/test/company.unit.js +++ b/test/company.unit.js @@ -1,6 +1,7 @@ var assert = require('assert'); var sinon = require('sinon'); var Faker = require('../index'); +var random = require('../lib/random'); describe("company.js", function () { describe("companyName()", function () { @@ -16,34 +17,34 @@ describe("company.js", function () { it("sometimes returns three last names", function () { sinon.spy(Faker.definitions, 'last_name'); - sinon.stub(Faker.Helpers, 'randomNumber').returns(2); + sinon.stub(random, 'number').returns(2); var name = Faker.Company.companyName(); var parts = name.split(' '); - assert.strictEqual(parts.length, 3); + assert.strictEqual(parts.length, 4); // account for word 'and' assert.ok(Faker.definitions.last_name.calledThrice); - Faker.Helpers.randomNumber.restore(); + random.number.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); + sinon.stub(random, 'number').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(); + random.number.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); + sinon.stub(random, 'number').returns(0); var name = Faker.Company.companyName(); var parts = name.split(' '); @@ -51,7 +52,7 @@ describe("company.js", function () { assert.ok(Faker.definitions.last_name.calledOnce); assert.ok(Faker.Company.companySuffix.calledOnce); - Faker.Helpers.randomNumber.restore(); + random.number.restore(); Faker.definitions.last_name.restore(); Faker.Company.companySuffix.restore(); }); @@ -66,43 +67,43 @@ describe("company.js", function () { 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'); + sinon.spy(random, 'array_rand'); + sinon.spy(random, 'catch_phrase_adjective'); + sinon.spy(random, 'catch_phrase_descriptor'); + sinon.spy(random, '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(); + assert.ok(random.array_rand.calledThrice); + assert.ok(random.catch_phrase_adjective.calledOnce); + assert.ok(random.catch_phrase_descriptor.calledOnce); + assert.ok(random.catch_phrase_noun.calledOnce); + + random.array_rand.restore(); + random.catch_phrase_adjective.restore(); + random.catch_phrase_descriptor.restore(); + random.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'); + sinon.spy(random, 'array_rand'); + sinon.spy(random, 'bs_adjective'); + sinon.spy(random, 'bs_buzz'); + sinon.spy(random, '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(); + assert.ok(random.array_rand.calledThrice); + assert.ok(random.bs_adjective.calledOnce); + assert.ok(random.bs_buzz.calledOnce); + assert.ok(random.bs_noun.calledOnce); + + random.array_rand.restore(); + random.bs_adjective.restore(); + random.bs_buzz.restore(); + random.bs_noun.restore(); }); }); }); |
