Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsiaoming Yang committed Dec 6, 2012
1 parent d80ad9b commit 6a372a9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 0.8
8 changes: 4 additions & 4 deletions lib/core/config.js
Expand Up @@ -13,6 +13,9 @@ var config = require('../helpers/config')
var utils = require('../utils')
var spmrcPath = path.join(process.env['HOME'], '.spm', 'spmrc')
utils.safeWrite(spmrcPath)
if (!fs.existsSync(spmrcPath)) {
updateConfig({})
}

exports.description = 'configuration for spm'

Expand All @@ -29,7 +32,7 @@ exports.config = function(key, value) {
if (!value) {
var ret = renderConfig(data);
keys.forEach(function(section) {
ret = ret[section]
ret = ret ? ret[section]: null
})
return ret
}
Expand Down Expand Up @@ -62,9 +65,6 @@ exports.remove = function(section) {


exports.show = function() {
if (!fs.existsSync(spmrcPath)) {
updateConfig({'user': {'username': 'spm'}})
}
var data = config.parseSync(spmrcPath)
console.log()
for (var section in data) {
Expand Down
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -5,11 +5,18 @@
"dependencies": {
"commander": ">=1.1.1"
},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"bin": {
"spm": "bin/spm",
"spm-build": "bin/spm-build",
"spm-config": "bin/spm-config",
"spm-install": "bin/spm-install",
"spm-plugin": "bin/spm-plugin"
},
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec"
}
}
12 changes: 12 additions & 0 deletions test/config.js
@@ -0,0 +1,12 @@
var should = require('should')
require('../index').logging.setlevel('error')
var config = require('../lib/core/config')

describe('config', function() {
it('should get section.key', function() {
config.config('section.key', 'value')
config.config('section.key').should.equal('value')
config.remove('section')
should.not.exist(config.config('section.key'))
})
})

0 comments on commit 6a372a9

Please sign in to comment.