From ca8eedbba9c3a96f916cd9c6e266329ad0686a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levente=20L=C3=B6ki?= Date: Thu, 24 Nov 2016 14:22:59 +0100 Subject: [PATCH 1/2] Added lorem.slug method --- lib/lorem.js | 11 +++++++++++ test/lorem.unit.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/lorem.js b/lib/lorem.js index 403e0e6da..db6aec726 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -50,6 +50,17 @@ var Lorem = function (faker) { return sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.'; }; + /** + * 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 * diff --git a/test/lorem.unit.js b/test/lorem.unit.js index fbf094972..300786b82 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 () { From 8794efa5bfdaccaf47a7cee227bbef93cffbb66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levente=20L=C3=B6ki?= Date: Thu, 24 Nov 2016 14:31:01 +0100 Subject: [PATCH 2/2] Added lorem.slug to functional test --- test/all.functional.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/all.functional.js b/test/all.functional.js index 605aad2ac..5295777f1 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -16,7 +16,7 @@ var modules = { internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'], - lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'], + lorem: ['words', 'sentence', 'slug', 'sentences', 'paragraph', 'paragraphs'], name: ['firstName', 'lastName', 'findName', 'jobTitle'],