Permalink
Browse files

Implement a failing unit test

  • Loading branch information...
1 parent b627864 commit a279f5c65ace9d2e78f5732846f672aa15135e32 @creationix creationix committed Jun 28, 2010
Showing with 38 additions and 1 deletion.
  1. +18 −1 test/helper.js
  2. +20 −0 test/saveTest.js
View
@@ -1,7 +1,24 @@
var sys = global.sys = require('sys');
global.assert = require('assert');
+global.fs = require('fs');
global.nStore = require('../lib/nstore');
global.p = function () {
sys.error(sys.inspect.apply(sys, arguments));
-};
+};
+
+function clean() {
+ try {
+ fs.unlinkSync('fixtures/new.db');
+ } catch (err) {
+ if (err.errno !== process.ENOENT) {
+ throw err;
+ }
+ }
+}
+
+// Clean the test environment at startup
+clean();
+
+// Clean on exit too
+// process.addListener('exit', clean);
View
@@ -0,0 +1,20 @@
+require('./helper');
+
+var documents = nStore('fixtures/new.db');
+
+var thesis = {
+ title: "Node is cool",
+ author: "creationix",
+ reasons: ["Non-Blocking I/O", "Super Fast", "Powered by bacon"]
+};
+
+documents.save("thesis", thesis, function (err) {
+ if (err) throw err;
+ assert.equal(documents.length, 1, "There should be 1 document in the collection");
+ documents.get("thesis", function (err, doc, meta) {
+ if (err) throw err;
+ p(arguments);
+ assert.deepEqual(doc, thesis, "Loading it back should look the same");
+ assert.equal(meta.key, "thesis", "The meta should have the key");
+ });
+});

0 comments on commit a279f5c

Please sign in to comment.