Created
August 14, 2014 03:42
-
-
Save ajcrites/3c420d86967b9a6776fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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