hybridgroup/cylon — pull request #106 by deadprogram (2014-02-18 21:10:44+00:00)
Title: Test-driven robotics support

Add support for auto-stubbing of adaptors and drivers for use when doing test-driven robotics.

Here is an example using Mocha, Sinon, & Chai:

```
"use strict";
process.env['CYLON_TEST'] = true;

var chai = require("chai");
var sinon = require("sinon");
var sinonChai = require("sinon-chai");
chai.should();
chai.use(sinonChai);

var clock = sinon.useFakeTimers();
var Cylon = require('cylon');
require("./robot.js");

describe("robot", function () {
var robot = Cylon.findRobot("testor");

it("should have work", function () {
return robot.work.should.be.a('function');
});

it("should toggle the led after 1 second", function (done) {
var led = robot.devices['led'];
var toggle = sinon.stub(led, 'toggle');
clock.tick((1).second());
toggle.should.have.been.called;
done();
});
});
```

to test the following robot code:

```
var Cylon = require("cylon");

var robot = Cylon.robot({
name: 'testor',
connection: { name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0' },
device: { name: 'led', driver: 'led', pin: 13 },

work: function(my) {
my.led.toggle();

every((1).second(), function() { my.led.toggle(); });
}
});

robot.start();
```