Skip to content

Instantly share code, notes, and snippets.

@7yl4r
Last active November 6, 2015 01:20
Show Gist options
  • Save 7yl4r/744db0ebe11252144aa2 to your computer and use it in GitHub Desktop.
Save 7yl4r/744db0ebe11252144aa2 to your computer and use it in GitHub Desktop.
cylon loopback test
"use strict";
// set up robot
var Cylon = require("cylon");
Cylon.api();
Cylon.robot({
name: "cylon-test-bot",
connections: {
loopback: { adaptor: "loopback" }
},
devices: {
ping: { driver: "ping" }
},
functionFired: false,
work: function(my) {
after((5).seconds(), function() {
console.log("5 seconds have passed.");
my.functionFired = true;
});
}
});
Cylon.start();
"use strict";
process.env.NODE_ENV = 'test';
// setup for tests
var chai = require('chai'),
sinon = require('sinon'),
sinonChai = require('sinon-chai');
chai.use(sinonChai);
var clock = sinon.useFakeTimers;
// load the robot, in test mode
var Cylon = require('cylon');
Cylon.config({ testMode: true })
require('../robot.js');
describe("cylon-test-bot", function() {
var robot = Cylon.robots["cylon-test-bot"];
it("should have functionFired == false @ t<5s", function() {
clock.tick(1000);
expect(robot.functionFired).to.be.false;
});
it("should have functionFired == true @ t>5s", function() {
clock.tick(10000);
expect(robot.functionFired).to.be.true;
});
});
@deadprogram
Copy link

Hi, @7yl4r I've updated the page http://cylonjs.com/documentation/guides/test-driven-robotics/ with a couple corrections. Thank you for pointing out it was incorrect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment