aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarak <[email protected]>2017-02-09 23:24:39 -0500
committerGitHub <[email protected]>2017-02-09 23:24:39 -0500
commit530c2ea186858ce82ab9707d11fe35def51bfbcf (patch)
tree14dc708ef33887dfa287ecc656a3ea12ecfc3c02
parentecb42b179573138dac20ad0b4481954a2ac72e67 (diff)
parent8794efa5bfdaccaf47a7cee227bbef93cffbb66e (diff)
downloadfaker-530c2ea186858ce82ab9707d11fe35def51bfbcf.tar.xz
faker-530c2ea186858ce82ab9707d11fe35def51bfbcf.zip
Merge pull request #437 from lencse/master
[api] Added `lorem.slug` method
-rw-r--r--lib/lorem.js11
-rw-r--r--test/all.functional.js2
-rw-r--r--test/lorem.unit.js30
3 files changed, 42 insertions, 1 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/all.functional.js b/test/all.functional.js
index 02025837..4ea196b6 100644
--- a/test/all.functional.js
+++ b/test/all.functional.js
@@ -18,7 +18,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'],
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 () {