update tests, add tests for `.keys`

master
jonschlinkert 9 years ago
parent fd2167a97a
commit 3181b94870

@ -7,28 +7,28 @@
'use strict'; 'use strict';
/* deps:mocha */ require('mocha');
require('should'); require('should');
var git = require('./'); var parse = require('./');
describe('sync:', function() { describe('sync:', function() {
it('should return an object', function() { it('should return an object', function() {
git.sync().should.have.properties(['core']); parse.sync().should.have.properties(['core']);
git.sync().should.not.have.properties(['foo']); parse.sync().should.not.have.properties(['foo']);
git.sync().should.not.throw; parse.sync().should.not.throw;
}); });
}); });
describe('async:', function() { describe('async:', function() {
it('should throw a callback is not passed:', function(cb) { it('should throw a callback is not passed:', function(cb) {
(function() { (function() {
git(); parse();
}).should.throw('parse-git-config async expects a callback function.') }).should.throw('parse-git-config async expects a callback function.');
cb(); cb();
}); });
it('should throw an error when .git/config does not exist:', function(cb) { it('should throw an error when .git/config does not exist:', function(cb) {
git(function(err, config) { parse(function(err, config) {
config.should.have.property('core'); config.should.have.property('core');
config.should.not.have.property('foo'); config.should.not.have.property('foo');
cb(); cb();
@ -36,7 +36,7 @@ describe('async:', function() {
}); });
it('should throw an error when .git/config does not exist:', function(cb) { it('should throw an error when .git/config does not exist:', function(cb) {
git({path: 'foo'}, function(err, config) { parse({path: 'foo'}, function(err, config) {
err.should.be.an.instanceof(Error); err.should.be.an.instanceof(Error);
err.message.should.match(/ENOENT.*parse-git-config/); err.message.should.match(/ENOENT.*parse-git-config/);
cb(); cb();
@ -47,18 +47,34 @@ describe('async:', function() {
describe('resolve:', function() { describe('resolve:', function() {
it('should resolve the git config in the cwd by default', function() { it('should resolve the git config in the cwd by default', function() {
var sep = require('path').sep; var sep = require('path').sep;
git.resolve().should.equal(process.cwd() + sep + '.git' + sep + 'config'); parse.resolve().should.equal(process.cwd() + sep + '.git' + sep + 'config');
}) });
it('should allow override path', function() { it('should allow override path', function() {
var path = require('path').resolve(process.env.HOME, '.gitconfig') var path = require('path').resolve(process.env.HOME, '.gitconfig');
git.resolve({path: path}).should.equal(path); parse.resolve({path: path}).should.equal(path);
}) });
it('should resolve relative path to cwd', function() { it('should resolve relative path to cwd', function() {
git.resolve({path: '.config'}) parse.resolve({path: '.config'})
.should.equal(require('path').resolve(process.cwd(), '.config')); .should.equal(require('path').resolve(process.cwd(), '.config'));
}) });
it('should allow override of cwd', function() { it('should allow override of cwd', function() {
git.resolve({path: '.config', cwd: '/opt/config'}) parse.resolve({path: '.config', cwd: '/opt/config'})
.should.equal(require('path').resolve('/opt/config','.config')) .should.equal(require('path').resolve('/opt/config','.config'));
}) });
}) });
describe('.keys:', function() {
it('should parse ini-style keys', function() {
var config = {
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
parse.keys(config).should.eql({
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
});
});
});

Loading…
Cancel
Save