Skip to content

Commit

Permalink
Destructured setup for ease of reading
Browse files Browse the repository at this point in the history
  • Loading branch information
steveukx committed May 6, 2017
1 parent b98b9a3 commit 892f307
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/unit/test-branch.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
'use strict';

const setup = require('./include/setup');
const {theCommandRun, restore, Instance, closeWith} = require('./include/setup');
const sinon = require('sinon');
const BranchSummary = require('../../src/responses/BranchSummary');
const BranchDeleteSummary = require('../../src/responses/BranchDeleteSummary');

var git, sandbox;

function branchDeleteLog (branchName) {
return 'Deleted branch ' + branchName + ' (was b190102).';
return `Deleted branch ${branchName} (was b190102).`;
}

function testBranchDelete (test, options, err, branchSummary) {
test.ok(
branchSummary instanceof BranchDeleteSummary,
branchSummary instanceof BranchDeleteSummary,
'Uses the BranchDeleteSummary response type'
);
test.equals(null, err);
test.same(['branch'].concat(options), setup.theCommandRun());
test.same(['branch'].concat(options), theCommandRun());
test.equals('new-branch', branchSummary.branch);
test.equals('b190102', branchSummary.hash);
test.equals(true, branchSummary.success);
test.done();
}

exports.setUp = function (done) {
setup.restore();
restore();
sandbox = sinon.sandbox.create();
done();
};

exports.tearDown = function (done) {
setup.restore();
restore();
sandbox.restore();
done();
};

exports.branch = {
setUp: function (done) {
git = setup.Instance();
git = Instance();
done();
},

Expand All @@ -49,7 +49,7 @@ exports.branch = {

git.branch(options, callback);

setup.closeWith(branchDeleteLog(branchName));
closeWith(branchDeleteLog(branchName));
},

'delete local branch with -D option': function (test) {
Expand All @@ -59,7 +59,7 @@ exports.branch = {

git.branch(options, callback);

setup.closeWith(branchDeleteLog(branchName));
closeWith(branchDeleteLog(branchName));
},

'delete local branch with --delete option': function (test) {
Expand All @@ -69,7 +69,7 @@ exports.branch = {

git.branch(options, callback);

setup.closeWith(branchDeleteLog(branchName));
closeWith(branchDeleteLog(branchName));
},

'delete local branch with #deleteLocalBranch': function (test) {
Expand All @@ -78,24 +78,24 @@ exports.branch = {

git.deleteLocalBranch(branchName, callback);

setup.closeWith(branchDeleteLog(branchName));
closeWith(branchDeleteLog(branchName));
},

'delete local branch errors': function (test) {
git.deleteLocalBranch('new-branch', function (err, branchSummary) {
test.ok(
branchSummary instanceof BranchDeleteSummary,
branchSummary instanceof BranchDeleteSummary,
'Uses the BranchDeleteSummary response type'
);
test.equals(null, err);
test.same(['branch', '-d', 'new-branch'], setup.theCommandRun());
test.same(['branch', '-d', 'new-branch'], theCommandRun());
test.equals('new-branch', branchSummary.branch);
test.equals(null, branchSummary.hash);
test.equals(false, branchSummary.success);
test.done();
});

setup.closeWith('error: branch \'new-branch\' not found.');
closeWith('error: branch \'new-branch\' not found.');
},

'detached branches': function (test) {
Expand Down Expand Up @@ -142,20 +142,20 @@ exports.branch = {

'gets branch with options array': function (test) {
git.branch(['-v', '--sort=-committerdate'], function (err, data) {
test.same(['branch', '-v', '--sort=-committerdate'], setup.theCommandRun());
test.same(['branch', '-v', '--sort=-committerdate'], theCommandRun());
test.done();
});

setup.closeWith('');
closeWith('');
},

'gets branch with options object': function (test) {
git.branch({ '-v': null, '--sort': '-committerdate'}, function (err, data) {
test.same(['branch', '-v', '--sort=-committerdate'], setup.theCommandRun());
test.same(['branch', '-v', '--sort=-committerdate'], theCommandRun());
test.done();
});

setup.closeWith('');
closeWith('');
},

'gets branch data': function (test) {
Expand All @@ -171,7 +171,7 @@ exports.branch = {
test.done();
});

setup.closeWith('\
closeWith('\
cflynn07-add-git-ignore a0b67a3 Add support for filenames containing spaces\n\
* drschwabe-add-branches 063069b Merge branch \'add-branches\' of https://github.com/drschwabe/git-js into drschwabe-add-branches\n\
master cb4be06 Release 1.30.0\n\
Expand All @@ -183,10 +183,10 @@ exports.branch = {
test.ok(branchSummary instanceof BranchSummary, 'Uses the BranchSummary response type');
test.equals(null, err, 'not an error');
test.same(['master'], branchSummary.all);
test.same(['branch', '-v'], setup.theCommandRun());
test.same(['branch', '-v'], theCommandRun());
test.done();
});
setup.closeWith('\
closeWith('\
* master 899725c [ahead 1] Add clean method\n\
remotes/origin/HEAD -> origin/master\n\
');
Expand Down

0 comments on commit 892f307

Please sign in to comment.