aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielle Adams <[email protected]>2018-06-27 20:31:44 -0400
committerMarak <[email protected]>2018-09-23 11:12:09 -0400
commit200ab1321231e63be401917433cd651ba2df7c51 (patch)
tree9fbcd37eb77dbee6f8ec4f21403f906bae20800e
parentc29b9407064dbc14baa338f2ba9713d49b99e1dd (diff)
downloadfaker-200ab1321231e63be401917433cd651ba2df7c51.tar.xz
faker-200ab1321231e63be401917433cd651ba2df7c51.zip
add commit entry and remove readme changes
-rw-r--r--Readme.md5
-rw-r--r--lib/git.js38
-rw-r--r--test/git.unit.js71
3 files changed, 97 insertions, 17 deletions
diff --git a/Readme.md b/Readme.md
index e879a0f4..4a1c3d0b 100644
--- a/Readme.md
+++ b/Readme.md
@@ -129,11 +129,6 @@ This will interpolate the format string with the value of methods `name.lastName
* ethereumAddress
* iban
* bic
-* git
- * branch
- * commitSha
- * commitMessage
- * shortSha
* hacker
* abbreviation
* adjective
diff --git a/lib/git.js b/lib/git.js
index 5693880f..1cf9121d 100644
--- a/lib/git.js
+++ b/lib/git.js
@@ -14,22 +14,29 @@ var Git = function(faker) {
self.branch = function() {
var noun = faker.hacker.noun().replace(' ', '-');
var verb = faker.hacker.verb().replace(' ', '-');
- return 'noun' + '-' + 'verb';
+ return noun + '-' + verb;
}
/**
- * commitSha
+ * commitEntry
*
- * @method faker.git.commitSha
+ * @method faker.git.commitEntry
+ * @param {object} options
*/
- self.commitSha = function() {
- var commit = "";
+ self.commitEntry = function(options) {
+ options = options || {};
- for (var i = 0; i < 40; i++) {
- commit += faker.random.alphaNumeric();
+ var entry = 'commit {{git.commitSha}}\r\n';
+
+ if (options.merge || (faker.random.number({ min: 0, max: 4 }) === 0)) {
+ entry += 'Merge: {{git.shortSha}} {{git.shortSha}}\r\n';
}
- return commit;
+ entry += 'Author: {{name.firstName}} {{name.lastName}} <{{internet.email}}>\r\n';
+ entry += 'Date: ' + faker.date.recent().toString() + '\r\n';
+ entry += '\r\n\xa0\xa0\xa0\xa0{{git.commitMessage}}\r\n';
+
+ return f(entry);
};
/**
@@ -43,6 +50,21 @@ var Git = function(faker) {
};
/**
+ * commitSha
+ *
+ * @method faker.git.commitSha
+ */
+ self.commitSha = function() {
+ var commit = "";
+
+ for (var i = 0; i < 40; i++) {
+ commit += faker.random.alphaNumeric();
+ }
+
+ return commit;
+ };
+
+ /**
* shortSha
*
* @method faker.git.shortSha
diff --git a/test/git.unit.js b/test/git.unit.js
index 38177a18..d32950c5 100644
--- a/test/git.unit.js
+++ b/test/git.unit.js
@@ -24,10 +24,65 @@ describe("git.js", function() {
});
});
- describe("commitSha()", function() {
- it("returns a random commit SHA", function() {
- var commitSha = faker.git.commitSha();
- assert.ok(commitSha.match(/^[a-z0-9]{40}$/));
+ describe("commitEntry()", function() {
+ beforeEach(function() {
+ sinon.spy(faker.git, 'commitMessage');
+ sinon.spy(faker.git, 'commitSha');
+ sinon.spy(faker.internet, 'email');
+ sinon.spy(faker.name, 'firstName');
+ sinon.spy(faker.name, 'lastName');
+ sinon.spy(faker.random, 'number');
+ });
+
+ afterEach(function() {
+ faker.git.commitMessage.restore();
+ faker.git.commitSha.restore();
+ faker.internet.email.restore();
+ faker.name.firstName.restore();
+ faker.name.lastName.restore();
+ faker.random.number.restore();
+ });
+
+ it("returns merge entry at random", function() {
+ faker.git.commitEntry();
+
+ assert.ok(faker.random.number.called);
+ });
+
+ it("returns a commit entry with git commit message and sha", function() {
+ faker.git.commitEntry();
+
+ assert.ok(faker.git.commitMessage.calledOnce);
+ assert.ok(faker.git.commitSha.calledOnce);
+ });
+
+ it("returns a commit entry with internet email", function() {
+ faker.git.commitEntry();
+
+ assert.ok(faker.internet.email.calledOnce);
+ });
+
+ it("returns a commit entry with name first and last", function() {
+ faker.git.commitEntry();
+
+ assert.ok(faker.name.firstName.calledTwice);
+ assert.ok(faker.name.lastName.calledTwice);
+ });
+
+ context("with options['merge'] equal to true", function() {
+ beforeEach(function() {
+ sinon.spy(faker.git, 'shortSha');
+ });
+
+ afterEach(function() {
+ faker.git.shortSha.restore();
+ });
+
+ it("returns a commit entry with merge details", function() {
+ faker.git.commitEntry({ merge: true });
+
+ assert.ok(faker.git.shortSha.calledTwice);
+ });
});
});
@@ -53,6 +108,14 @@ describe("git.js", function() {
});
});
+
+ describe("commitSha()", function() {
+ it("returns a random commit SHA", function() {
+ var commitSha = faker.git.commitSha();
+ assert.ok(commitSha.match(/^[a-z0-9]{40}$/));
+ });
+ });
+
describe("shortSha()", function() {
it("returns a random short SHA", function() {
var shortSha = faker.git.shortSha();