Ruff 0.9.0 Documentation


Ruff Driver Runner#

The ruff-app-runner module provides you a facility for Ruff driver developers to run driver on their development machine. You may include this module with require('ruff-driver-runner');

var runner = require('ruff-driver-runner').runner;
var when = require('ruff-mock').when;

export['test should work well'] = function() {
  runner.run(driverPath, function(device, context) {
    var gpio = context.arg('gpio');
    when(gpio.read()).thenReturn(1);
    assertOk(dev.readValue() == 1);
  }
}

require('test').run(exports);

Ruff driver runner creates a virtual runtime built with ruff-mock, which allows developers to:

  • Retrive mock interface

The second parameter of run function of driver runner is context. Where the interface could be retrived from

var gpio = context.arg('gpio');

The name of the reference passed to context.arg should be same with the name described in driver.json.

  • Mock interface data

Mock device can set its function's return value, e.g:

when(gpio).read().thenReturn(1);
  • Verify device behavior

Upon code execution, invocation behavior can be verified by verify.

verify(gpio).write(1);
  • Trigger device event

Every mock interface supports EventEmitter. Their events can be trigger by emit.

gpio.emit('interrupt');

For more mock details, you can refer to ruff-mock module document.

runner.run(driverPath, runCallback)#

  • driverPath refer to your driver path which contains driver.json.
  • runCallback will run once the virtual runtime has been created and your attach function has been invoked.