Skip to content

Commit

Permalink
Complete SerialDataSource documentation and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwippermann committed Feb 15, 2014
1 parent e1edc2f commit 7fd8982
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/serial-data-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ var optionKeys = [



var SerialDataSource = DataSource.extend({
var SerialDataSource = DataSource.extend(/** @lends SerialDataSource# */ {

/**
* The path to the serial port.
*/
path: null,

/**
* Creates a new SerialDataSource.
*
* @constructs
* @augments DataSource
*/
constructor: function(options) {
DataSource.call(this, options);

Expand All @@ -40,7 +49,9 @@ var SerialDataSource = DataSource.extend({

var connection = new SerialConnection(options);

return connection.connect();
return connection.connect().then(function() {
return connection;
});
}

});
Expand Down
48 changes: 46 additions & 2 deletions test/specs/serial-data-source.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@



var SerialDataSource = require('./resol-vbus').SerialDataSource;
var Q = require('q');


var vbus = require('./resol-vbus');
var testUtils = require('./test-utils');



var SerialConnection = vbus.SerialConnection;
var SerialDataSource = vbus.SerialDataSource;



Expand All @@ -15,9 +24,44 @@ describe('SerialDataSource', function() {
expect(SerialDataSource).to.be.a('function');
});

it('should have reasonable defaults', function() {
var ds = new SerialDataSource();

expect(ds)
.to.have.a.property('path')
.that.equal(null);
});

});

xit('should perform tests...', function() {
describe('#connectLive', function() {

it('should be a method', function() {
expect(SerialDataSource.prototype)
.to.have.a.property('connectLive')
.that.is.a('function');
});

it('should work correctly', function(done) {
var originalConnect = SerialConnection.prototype.connect;

SerialConnection.prototype.connect = function() {
return Q(null);
};

var ds = new SerialDataSource();

testUtils.performAsyncTest(done, function() {
return Q.fcall(function() {
return ds.connectLive();
}).then(function(connection) {
expect(connection)
.to.be.instanceOf(SerialConnection);
}).finally(function() {
SerialConnection.prototype.connect = originalConnect;
});
});
});

});

Expand Down

0 comments on commit 7fd8982

Please sign in to comment.