Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fs.write() spy to fix tests #14

Merged
merged 1 commit into from Jan 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -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"
}
}
29 changes: 11 additions & 18 deletions 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) {
Expand All @@ -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');
Expand All @@ -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();
});
});