Permalink
Browse files

initial commit - node_modules and an example without promises

  • Loading branch information...
0 parents commit bf44e20d954a41dbd0dcb19437e319494462448f @dominykas dominykas committed Oct 1, 2012
@@ -0,0 +1,31 @@
+if (typeof define !== 'function') { var define = require('amdefine')(module); }
+
+define(["fs", "path"], function(fs, path){
+
+ var defaultLang = "en", UTF = 'utf-8';
+
+ var getFn = function(lang, pageId)
+ {
+ return path.join("testdata", pageId+"."+lang+".html");
+ };
+
+ var getHtml = function (lang, pageId, callback)
+ {
+ fs.readFile(getFn(lang, pageId), UTF, function(e, data){
+ if (e != null) {
+ if (lang == defaultLang) {
+ callback(e, null);
+ } else {
+ getHtml(defaultLang, pageId, callback);
+ }
+ return;
+ }
+ callback(null, data);
+ });
+ };
+
+ return {
+ getHtml: getHtml
+ };
+
+});
@@ -0,0 +1,69 @@
+if (typeof define !== 'function') { var define = require('amdefine')(module); }
+
+define("00-withoutPromises.test", ["buster", "fs", "./00-withoutPromises"], function(buster, fs, html) {
+
+ buster.testCase("00", {
+
+
+ "setUp": function()
+ {
+ this.fsStub = this.stub(fs, "readFile");
+ this.fsStub.withArgs("testdata/one.en.html", "utf-8").yields(null, "one english");
+ this.fsStub.withArgs("testdata/one.de.html", "utf-8").yields(null, "one german");
+ this.fsStub.withArgs("testdata/two.en.html", "utf-8").yields(null, "two english");
+ this.fsStub.withArgs("testdata/two.de.html", "utf-8").yields(new Error(), null);
+ this.fsStub.withArgs("testdata/na.en.html", "utf-8").yields(new Error(), null);
+ this.fsStub.withArgs("testdata/na.de.html", "utf-8").yields(new Error(), null);
+ },
+
+ "should read file (de, exists)": function(done)
+ {
+ html.getHtml("de", "one", function(e, data){
+
+ expect(this.fsStub).toHaveBeenCalledOnce();
+ expect(e).toBeNull();
+ expect(data).toEqual("one german");
+ done();
+
+ }.bind(this));
+ },
+
+ "should read file (de, fallback)": function(done)
+ {
+ html.getHtml("de", "two", function(e, data){
+
+ expect(this.fsStub).toHaveBeenCalledTwice();
+ expect(e).toBeNull();
+ expect(data).toEqual("two english");
+ done();
+
+ }.bind(this));
+ },
+
+ "should return error (en, na)": function(done)
+ {
+ html.getHtml("en", "na", function(e, data){
+
+ expect(this.fsStub).toHaveBeenCalledOnce();
+ expect(e).not.toBeNull();
+ expect(data).toBeNull();
+ done();
+
+ }.bind(this));
+ },
+
+ "should return error (de, na)": function(done)
+ {
+ html.getHtml("de", "na", function(e, data){
+
+ expect(this.fsStub).toHaveBeenCalledTwice();
+ expect(e).not.toBeNull();
+ expect(data).toBeNull();
+ done();
+
+ }.bind(this));
+ }
+
+ });
+
+});
13 LICENSE
@@ -0,0 +1,13 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+Copyright (C) 2012 Dominykas Blyžė https://twitter.com/dymonaz
+
+Everyone is permitted to copy and distribute verbatim or modified
+copies of this license document, and changing it is allowed as long
+as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
1 README
@@ -0,0 +1 @@
+A test project for dublinjs Oct/2012 meetup - examples with TDD and promises
@@ -0,0 +1,9 @@
+var config = module.exports;
+
+config["Node tests"] = {
+ rootPath:".",
+ environment:"node",
+ tests:[
+ "*.test.js"
+ ]
+};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit bf44e20

Please sign in to comment.