diff options
| author | Levente Löki <[email protected]> | 2016-11-24 14:22:59 +0100 |
|---|---|---|
| committer | Levente Löki <[email protected]> | 2016-11-24 14:22:59 +0100 |
| commit | ca8eedbba9c3a96f916cd9c6e266329ad0686a91 (patch) | |
| tree | 02f83d8b653df5b79f7815662476943f7a8538a7 | |
| parent | 7e96b93869b422af5a63c115e04ff0206bf7b228 (diff) | |
| download | faker-ca8eedbba9c3a96f916cd9c6e266329ad0686a91.tar.xz faker-ca8eedbba9c3a96f916cd9c6e266329ad0686a91.zip | |
Added lorem.slug method
| -rw-r--r-- | lib/lorem.js | 11 | ||||
| -rw-r--r-- | test/lorem.unit.js | 30 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/lorem.js b/lib/lorem.js index 403e0e6d..db6aec72 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -51,6 +51,17 @@ var Lorem = function (faker) { }; /** + * slug + * + * @method faker.lorem.slug + * @param {number} wordCount number of words, defaults to 3 + */ + self.slug = function (wordCount) { + var words = faker.lorem.words(wordCount); + return Helpers.slugify(words); + }; + + /** * sentences * * @method faker.lorem.sentences diff --git a/test/lorem.unit.js b/test/lorem.unit.js index fbf09497..300786b8 100644 --- a/test/lorem.unit.js +++ b/test/lorem.unit.js @@ -34,6 +34,36 @@ describe("lorem.js", function () { }); }); + describe("slug()", function () { + beforeEach(function () { + sinon.spy(faker.helpers, 'shuffle'); + }); + + afterEach(function () { + faker.helpers.shuffle.restore(); + }); + + var validateSlug = function (wordCount, str) { + assert.equal(1, str.match(/^[a-z][a-z-]*[a-z]$/).length); + assert.equal(wordCount - 1, str.match(/-/g).length); + }; + + context("when no 'wordCount' param passed in", function () { + it("returns a slug with three words", function () { + var str = faker.lorem.slug(); + validateSlug(3, str); + }); + }); + + context("when 'wordCount' param passed in", function () { + it("returns a slug with requested number of words", function () { + var str = faker.lorem.slug(7); + validateSlug(7, str); + }); + }); + + }); + /* describe("sentence()", function () { context("when no 'wordCount' or 'range' param passed in", function () { |
