Skip to content

Instantly share code, notes, and snippets.

@iliabylich
Last active August 29, 2015 14:10
Show Gist options
  • Save iliabylich/fc4596eea147082f094e to your computer and use it in GitHub Desktop.
Save iliabylich/fc4596eea147082f094e to your computer and use it in GitHub Desktop.
Custom rspec runner for opal specs
/*
* Test runner for phantomjs
*/
var args = phantom.args;
var page = require('webpage').create();
var fs = require('fs');
var logfile = args[1] || "/tmp/out.log";
fs.write(logfile, '', 'w');
page.onConsoleMessage = function(msg) {
fs.write(logfile, msg, 'a');
fs.write(logfile, '\n', 'a')
console.log(msg);
};
page.onInitialized = function() {
page.evaluate(function () {
window.OPAL_SPEC_PHANTOM = true;
});
};
page.open(args[0], function(status) {
if (status !== 'success') {
console.error("Cannot load: " + args[0]);
phantom.exit(1);
} else {
var timeout = parseInt(args[1] || 60000, 10);
var start = Date.now();
var interval = setInterval(function() {
if (Date.now() > start + timeout) {
console.error("Specs timed out");
phantom.exit(124);
} else {
var code = page.evaluate(function() {
return window.OPAL_SPEC_CODE;
});
if (code === 0 || code === 1) {
clearInterval(interval);
phantom.exit(code);
}
}
}, 500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment