diff options
| author | Foster Hersey <[email protected]> | 2014-09-03 00:50:50 -0500 |
|---|---|---|
| committer | Marak <[email protected]> | 2014-09-08 22:57:49 +0200 |
| commit | 3caea6078c05dd7caaffa4d2fd362ebe084168f9 (patch) | |
| tree | ceba18c1e8eca1d9fc1e33f95170a37a529deb8f | |
| parent | 2e65a32c3ca15218df58d3599a648a8e6d614569 (diff) | |
| download | faker-3caea6078c05dd7caaffa4d2fd362ebe084168f9.tar.xz faker-3caea6078c05dd7caaffa4d2fd362ebe084168f9.zip | |
Fix: faker.Lorem.sentence() was ignoring the 'range' parameter.
Conflicts:
lib/lorem.js
| -rw-r--r-- | lib/lorem.js | 2 | ||||
| -rw-r--r-- | test/lorem.unit.js | 12 | ||||
| -rw-r--r-- | test/random.unit.js | 5 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/lorem.js b/lib/lorem.js index efe29acc..12a0e35e 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -15,7 +15,7 @@ var lorem = { // strange issue with the node_min_test failing for captialize, please fix and add faker.Lorem.back //return faker.Lorem.words(wordCount + Helpers.randomNumber(range)).join(' ').capitalize(); - return faker.Lorem.words(wordCount + faker.random.number(7)).join(' '); + return faker.Lorem.words(wordCount + faker.random.number(range)).join(' '); }, sentences: function (sentenceCount) { diff --git a/test/lorem.unit.js b/test/lorem.unit.js index 0bb0a452..f1b174d9 100644 --- a/test/lorem.unit.js +++ b/test/lorem.unit.js @@ -70,17 +70,27 @@ describe("lorem.js", function () { context("when 'wordCount' and 'range' params passed in", function () { it("returns a string of at least the requested number of words", function () { sinon.spy(faker.Lorem, 'words'); - sinon.stub(faker.random, 'number').returns(4); + sinon.stub(faker.random, 'number').returnsArg(0); // it echos back its maximum possible value. + var sentence = faker.Lorem.sentence(10, 4); assert.ok(typeof sentence === 'string'); var parts = sentence.split(' '); assert.equal(parts.length, 14); // requested 10 plus stubbed 4. + assert.ok(faker.random.number.calledWith(4)); // random.number should be called with the 'range' we passed. assert.ok(faker.Lorem.words.calledWith(14)); faker.Lorem.words.restore(); faker.random.number.restore(); }); + + it("returns a string of exactly 'wordCount' length when 'range' is zero", function () { + var sentence = faker.Lorem.sentence(10, 0); + + assert.ok(typeof sentence === 'string'); + var parts = sentence.split(' '); + assert.equal(parts.length, 10); // requested 10 exactly. + }); }); }); diff --git a/test/random.unit.js b/test/random.unit.js index 89f5b786..c50bfada 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -17,5 +17,10 @@ describe("random.js", function () { assert.ok( randomNumber >= min); assert.ok( randomNumber <= max); }); + it("returns zero when given a max of zero.", function() { + var max = 0; + var randomNumber = faker.random.number(max); + assert.ok( randomNumber === 0 ); + }); }); }); |
