Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created August 14, 2014 03:42
Show Gist options
  • Save ajcrites/3c420d86967b9a6776fb to your computer and use it in GitHub Desktop.
Save ajcrites/3c420d86967b9a6776fb to your computer and use it in GitHub Desktop.
var lorem = require('lorem-ipsum'),
exercise = require('workshopper-exercise')(),
filecheck = require('workshopper-exercise/filecheck'),
execute = require('workshopper-exercise/execute'),
comparestdout = require('workshopper-exercise/comparestdout'),
path = require("path"),
os = require("os"),
fs = require("fs"),
assert = require("assert"),
tmpFile = path.join(os.tmpDir(), "_generators-adventure_" + process.pid + ".txt");
exercise = filecheck(exercise);
exercise = execute(exercise);
exercise.addSetup(function(mode, callback) {
this.submission = this.args[0];
if (!this.solution) this.solution = path.join(this.dir, './solution/solution.js');
this.submissionModule = require(process.cwd() + '/' + this.submission);
this.solutionModule = require(this.solution);
this._tmpFile = tmpFile;
fs.writeFile(tmpFile, lorem(), "utf8", function (err) {
if (err) {
callback(err);
}
process.nextTick(callback);
});
})
exercise.addVerifyProcessor(function(callback) {
var self = this;
self.submissionModule(self._tmpFile)(function (err, submissionContents) {
self.solutionModule(self._tmpFile)(function (err, solutionContents) {
assert.equal(submissionContents.toString(), solutionContents.toString());
callback();
});
});
});
exercise.addCleanup(function (mode, passed, callback) {
fs.unlink(tmpFile, callback);
});
module.exports = exercise;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment