Skip to content

Commit

Permalink
add commit entry and remove readme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielle Adams authored and Marak committed Sep 23, 2018
1 parent c29b940 commit 200ab13
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 17 deletions.
5 changes: 0 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 30 additions & 8 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand All @@ -42,6 +49,21 @@ var Git = function(faker) {
return f(format);
};

/**
* commitSha
*
* @method faker.git.commitSha
*/
self.commitSha = function() {
var commit = "";

for (var i = 0; i < 40; i++) {
commit += faker.random.alphaNumeric();
}

return commit;
};

/**
* shortSha
*
Expand Down
71 changes: 67 additions & 4 deletions test/git.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand All @@ -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();
Expand Down

0 comments on commit 200ab13

Please sign in to comment.