diff --git a/lib/configuration/Response.js b/lib/configuration/Response.js index fe0f12f..08aa71c 100644 --- a/lib/configuration/Response.js +++ b/lib/configuration/Response.js @@ -4,8 +4,16 @@ // deeply merge objects var assign = require('object-assign-deep'); var defaults = require('./defaults'); +var Gun = require('gun/gun'); +/* + This is the test configuration constructor. + An instance is created each time a new + `test()` is declared, and is later configured + dynamically by "Context.js". +*/ function Response(obj) { + this.testID = Gun.text.random(); // provide defaults assign(this, defaults); diff --git a/lib/framework/Test.js b/lib/framework/Test.js index 911e465..67b8780 100644 --- a/lib/framework/Test.js +++ b/lib/framework/Test.js @@ -14,7 +14,6 @@ function done() { } function Test(name, cb, time) { - var ctx; if (!(this instanceof Test)) { return new Test(name, cb); } @@ -22,7 +21,11 @@ function Test(name, cb, time) { cb = name; } - ctx = new Context(this); + if (typeof name === 'string') { + this.description = name; + } + + var ctx = new Context(this); stack.push(ctx); cb.call(ctx, ctx); bump(ctx, done); diff --git a/server/index.js b/server/index.js index 7e4fe49..629e468 100644 --- a/server/index.js +++ b/server/index.js @@ -1,11 +1,11 @@ /*jslint node: true, nomen: true*/ 'use strict'; -//require('../libb/polyfill'); var express = require('express'); var server = express(); var port = process.argv[2] || 8080; +var host = 'localhost'; var path = require('path'); var dist = path.join(__dirname, '../dist'); @@ -28,9 +28,11 @@ module.exports = { router: server, + host: host, + // return the full URL toString: function () { - return 'http://localhost:' + port + '/'; + return 'http://' + host + ':' + port + '/'; } }; @@ -53,4 +55,4 @@ server.post('/done', function (req, res) { module.exports.done.apply(this, arguments); }); -server.listen(port); +server.listen(port, host); diff --git a/spec/configuration/Response.spec.js b/spec/configuration/Response.spec.js index 1de06f5..a0fa46a 100644 --- a/spec/configuration/Response.spec.js +++ b/spec/configuration/Response.spec.js @@ -24,4 +24,16 @@ describe('The Response constructor', function () { var keys = Object.keys(new Response()); expect(keys.length).toBeGreaterThan(0); }); + + it('should produce a test ID string', function () { + var id = new Response().testID; + expect(id).toEqual(jasmine.any(String)); + }); + + it('should produce unique IDs for each instance', function () { + var id2, id1; + id1 = new Response().testID; + id2 = new Response().testID; + expect(id1).not.toBe(id2); + }); }); diff --git a/spec/framework/Test.spec.js b/spec/framework/Test.spec.js index ef9ab60..8fd223e 100644 --- a/spec/framework/Test.spec.js +++ b/spec/framework/Test.spec.js @@ -1,5 +1,5 @@ /*jslint node: true*/ -/*global jasmine, describe, it, expect*/ +/*global jasmine, describe, it, expect, pending*/ 'use strict'; @@ -23,13 +23,22 @@ describe('The test function', function () { }); }); - it('should allow you to name tests', function (done) { - test('Named test', done); + it('should allow you to name tests', function () { + var called = false; + test('Named test', function () { + called = true; + }); + expect(called).toBe(true); }); - it('should pass the context as arg1', function () { + it('should pass the context as arg0', function () { test(function (ctx) { expect(ctx).toEqual(jasmine.any(Context)); }); }); + + it('should remember the test name', function () { + var result = test('fabulous success', function () {}); + expect(result.description).toBe('fabulous success'); + }); }); diff --git a/spec/server/index.spec.js b/spec/server/index.spec.js index 31fe8a3..5f08d5d 100644 --- a/spec/server/index.spec.js +++ b/spec/server/index.spec.js @@ -13,6 +13,14 @@ describe('The router', function () { expect(stringy).toBe(true); }); + it('should export the current port', function () { + expect(route.port).toEqual(jasmine.any(Number)); + }); + + it('should export the hostname', function () { + expect(route.host).toEqual(jasmine.any(String)); + }); + it('should return the full URL when `toString`ed', function () { expect(route.toString()).toMatch(/http/i); });