Last active
November 6, 2015 01:20
-
-
Save 7yl4r/744db0ebe11252144aa2 to your computer and use it in GitHub Desktop.
cylon loopback test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!