Browse files

Merge pull request #14 from mbehrendt/fs-spy

Added fs.write() spy to fix tests
  • Loading branch information...
2 parents 6291094 + 3d07782 commit 0ed13bac45979159f3b9208301cf6c076e145b4d @StephanHoyer committed Jan 6, 2013
Showing with 12 additions and 20 deletions.
  1. +1 −2 package.json
  2. +11 −18 test/index.js
View
3 package.json
@@ -20,7 +20,6 @@
"mocha": "1.7.3",
"gently": "0.9.2",
"should": "1.2.1",
- "path-extra": "0.0.x",
- "testutil": "~0.2.4"
+ "sinon": "1.5.2"
}
}
View
29 test/index.js
@@ -1,7 +1,7 @@
var chuk = require('../')
, fs = require('fs')
- , pathextra = require('path-extra')
- , testutil = require('testutil')
+ , sinon = require('sinon')
+ , spy = sinon.spy(fs, 'write')
, repl
, config = {
'foo': function(context) {
@@ -16,16 +16,15 @@ var chuk = require('../')
};
describe('chuk', function() {
- it('should load chukfile configuration if it\'s a function', function(done) {
+ it('should load chukfile configuration if it\'s a function', function() {
repl = chuk(null, function(context) {
context.foo = 'bar';
});
repl.context.global.should.have.property('foo');
repl.context.global.foo.should.equal('bar');
- done();
});
- it('should load chukfile configuration for given env', function(done) {
+ it('should load chukfile configuration for given env', function() {
repl = chuk('foo', config);
repl.context.global.should.have.property('foo');
repl.context.global.should.not.have.property('bar');
@@ -34,44 +33,38 @@ describe('chuk', function() {
repl.context.global.should.not.have.property('foo');
repl.context.global.should.have.property('bar');
repl.context.global.bar.should.equal(123);
- done();
});
- it('should load default configuration if no env given', function(done) {
+ it('should load default configuration if no env given', function() {
repl = chuk(null, config);
repl.context.global.should.have.property('foo');
repl.context.global.should.not.have.property('bar');
repl.context.global.foo.should.equal('default');
- done();
});
- it('should write to default history file', function(done) {
+ it('should write to default history file', function() {
var command = 'var i = 1;'
- , path = pathextra.join(testutil.createTempDir, '.repl_history');
-
- process.env.REPL_HISTORY = path;
+ , path = '.repl_history';
repl = chuk(null, config);
repl.rli.emit('line', command);
fs.existsSync(path).should.be.true;
- fs.readFileSync(path, 'utf-8').should.include(command);
+ spy.lastCall.args[1].should.include(command);
fs.unlink(path);
- done();
});
- it('should use specified file if REPL_HISTORY is set', function(done) {
+ it('should use specified file if REPL_HISTORY is set', function() {
var command = 'var f = function() { return true };'
- , path = pathextra.join(testutil.createTempDir(), '.custom_history');
+ , path = '.custom_history';
process.env.REPL_HISTORY = path;
repl = chuk(null, config);
repl.rli.emit('line', command);
fs.existsSync(path).should.be.true;
- fs.readFileSync(path, 'utf-8').should.include(command);
+ spy.lastCall.args[1].should.include(command);
process.env.REPL_HISTORY = undefined;
- done();
});
});

0 comments on commit 0ed13ba

Please sign in to comment.