oojspec 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 724e22dc3d2dd4d39d3e328440d4280d93ace90b
4
- data.tar.gz: 884d9a5c7b832154afc8eb5c99a244ea8b5e17ed
3
+ metadata.gz: 3becd6c69bdfbacd5d8986b464ca2a3f89967650
4
+ data.tar.gz: c46d2342a87bacabdabb0b5903124b852d7b9de0
5
5
  SHA512:
6
- metadata.gz: 7c30d3e29b42ec72bf256ca75562c58d7a988e2c7be902310632ba3cd422b5b8e1ea8ff9be23e6f307840b96a08f27c6d13cc09480349a7762d68a546b2e89ca
7
- data.tar.gz: c58b6b70eb7cbe4543046933f5bd0085c94cf22453535a8d0ed1321f62c5a0b933e14fe2208412532194f593498672b204058d73db1daf72dc753c34de4692e3
6
+ metadata.gz: be7c90618f90c30527b19540ab9c8112048739a59059701b2d81538ac921db278d004e1f19e9d0b4e4b6064b0e078b90b0d1ca911c47349bf68acf91deb6290f
7
+ data.tar.gz: 488cf3725b34c1fa025d0f34ec626ab70e98f3eff64e5f909fa8d155090b6a322ce3b4935c6caf3a136a842caf4a1c8b268f0c0d9bb23f7e3b4c609ea5e99312
@@ -24,9 +24,9 @@ _.extend oojspec, new class OojspecRunner
24
24
  @on 'iframe-end', (w)=> @_iframeByWindow[w.location.pathname].style.display = 'none'
25
25
 
26
26
  _registerEventHandlers: ->
27
- @assertions = buster.assertions
28
- (logFormatter = buster.create buster.format).quoteStrings = false
29
- @assertions.format = buster.bind logFormatter, "ascii"
27
+ @assertions = referee
28
+ logFormatter = formatio.configure quoteStrings: false
29
+ @assertions.format = -> logFormatter.ascii.apply logFormatter, arguments
30
30
  @assertions.on 'pass', => @stats.assertions++
31
31
  @assertions.on 'failure', => @stats.failures++
32
32
  #@events.on 'context:start', => @stats.contexts++
@@ -90,13 +90,13 @@ RESERVED_FOR_EXAMPLE_DSL = ['assert', 'expect', 'fail', 'refute', 'waitsFor', 'r
90
90
  class Description
91
91
  RESERVED = RESERVED_FOR_DESCRIPTION_DSL.concat RESERVED_FOR_EXAMPLE_DSL
92
92
 
93
- constructor: (@description, @block)->
93
+ constructor: (@description, @block, @beforeBlocks = [], @afterBlocks = [])->
94
94
  if @description.runSpecs or @description.prototype?.runSpecs
95
95
  @block = @description
96
96
  @description = @block.description or @block.name
97
97
 
98
98
  processDsl: (@params, @binding, @bare)->
99
- @events = params.events
99
+ @events = @params.events
100
100
  @dsl = new DescribeDsl
101
101
  (@block.runSpecs or @block.prototype?.runSpecs) and @detectBindingError()
102
102
 
@@ -126,7 +126,7 @@ class Description
126
126
 
127
127
  removeDsl: -> delete @binding[p] for p in RESERVED_FOR_DESCRIPTION_DSL; return
128
128
 
129
- run: (@params, @onFinish, @beforeBlocks = [], @afterBlocks = [])->
129
+ run: (@params, @onFinish)->
130
130
  @events.emit 'context:start', name: @description
131
131
  if @bindingError
132
132
  @events.emit 'test:error', name: @description, error: @bindingError
@@ -134,7 +134,7 @@ class Description
134
134
  else
135
135
  @doRun()
136
136
 
137
- doRun: -> @runAround @beforeBlocks, @afterBlocks, @onDescriptionFinished, @processDescriptionBlock
137
+ doRun: -> @runAround [], [], @onDescriptionFinished, @processDescriptionBlock
138
138
 
139
139
  onDescriptionFinished: (error)=>
140
140
  if error and not error.handled
@@ -154,6 +154,7 @@ class Description
154
154
  (@onExamplesFinished(); return) unless @dsl._examples_.length
155
155
  nextStep = @dsl._examples_.shift()
156
156
  (@reportDeferred(nextStep.description); @runNextStep(); return) if nextStep.pending
157
+ @prependHooks nextStep
157
158
  nextTick =
158
159
  if nextStep instanceof Description then =>
159
160
  nextStep.run @params, @runNextStep, @dsl._beforeBlocks_, @dsl._afterBlocks_
@@ -170,6 +171,12 @@ class Description
170
171
  @events.emit 'test:error', { name, error }
171
172
  @onFinish(error)
172
173
 
174
+ prependHooks: (nextStep)->
175
+ @cloneAndPrepend nextStep, type for type in ['beforeBlocks', 'afterBlocks']
176
+
177
+ cloneAndPrepend: (nextStep, type)->
178
+ (nextStep[type] = nextStep[type].slice 0).unshift this[type]...
179
+
173
180
  reportDeferred: (description)-> @events.emit 'test:deferred', name: description
174
181
 
175
182
  class DescribeDsl
@@ -1,3 +1,3 @@
1
1
  module Oojspec
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,3 +1,5 @@
1
+ # =require buster/lodash
2
+ # =require buster/samsam
1
3
  # =require ./buster-core
2
4
  # =require ./buster-event-emitter
3
5
  # =require_tree .
@@ -0,0 +1,174 @@
1
+ ((typeof define === "function" && define.amd && function (m) { define("bane", m); }) ||
2
+ (typeof module === "object" && function (m) { module.exports = m(); }) ||
3
+ function (m) { this.bane = m(); }
4
+ )(function () {
5
+ "use strict";
6
+ var slice = Array.prototype.slice;
7
+
8
+ function handleError(event, error, errbacks) {
9
+ var i, l = errbacks.length;
10
+ if (l > 0) {
11
+ for (i = 0; i < l; ++i) { errbacks[i](event, error); }
12
+ return;
13
+ }
14
+ setTimeout(function () {
15
+ error.message = event + " listener threw error: " + error.message;
16
+ throw error;
17
+ }, 0);
18
+ }
19
+
20
+ function assertFunction(fn) {
21
+ if (typeof fn !== "function") {
22
+ throw new TypeError("Listener is not function");
23
+ }
24
+ return fn;
25
+ }
26
+
27
+ function supervisors(object) {
28
+ if (!object.supervisors) { object.supervisors = []; }
29
+ return object.supervisors;
30
+ }
31
+
32
+ function listeners(object, event) {
33
+ if (!object.listeners) { object.listeners = {}; }
34
+ if (event && !object.listeners[event]) { object.listeners[event] = []; }
35
+ return event ? object.listeners[event] : object.listeners;
36
+ }
37
+
38
+ function errbacks(object) {
39
+ if (!object.errbacks) { object.errbacks = []; }
40
+ return object.errbacks;
41
+ }
42
+
43
+ /**
44
+ * @signature var emitter = bane.createEmitter([object]);
45
+ *
46
+ * Create a new event emitter. If an object is passed, it will be modified
47
+ * by adding the event emitter methods (see below).
48
+ */
49
+ function createEventEmitter(object) {
50
+ object = object || {};
51
+
52
+ function notifyListener(event, listener, args) {
53
+ try {
54
+ listener.listener.apply(listener.thisp || object, args);
55
+ } catch (e) {
56
+ handleError(event, e, errbacks(object));
57
+ }
58
+ }
59
+
60
+ object.on = function (event, listener, thisp) {
61
+ if (typeof event === "function") {
62
+ return supervisors(this).push({
63
+ listener: event,
64
+ thisp: listener
65
+ });
66
+ }
67
+ listeners(this, event).push({
68
+ listener: assertFunction(listener),
69
+ thisp: thisp
70
+ });
71
+ };
72
+
73
+ object.off = function (event, listener) {
74
+ var fns, events, i, l;
75
+ if (!event) {
76
+ fns = supervisors(this);
77
+ fns.splice(0, fns.length);
78
+
79
+ events = listeners(this);
80
+ for (i in events) {
81
+ if (events.hasOwnProperty(i)) {
82
+ fns = listeners(this, i);
83
+ fns.splice(0, fns.length);
84
+ }
85
+ }
86
+
87
+ fns = errbacks(this);
88
+ fns.splice(0, fns.length);
89
+
90
+ return;
91
+ }
92
+ if (typeof event === "function") {
93
+ fns = supervisors(this);
94
+ listener = event;
95
+ } else {
96
+ fns = listeners(this, event);
97
+ }
98
+ if (!listener) {
99
+ fns.splice(0, fns.length);
100
+ return;
101
+ }
102
+ for (i = 0, l = fns.length; i < l; ++i) {
103
+ if (fns[i].listener === listener) {
104
+ fns.splice(i, 1);
105
+ return;
106
+ }
107
+ }
108
+ };
109
+
110
+ object.once = function (event, listener, thisp) {
111
+ var wrapper = function () {
112
+ object.off(event, wrapper);
113
+ listener.apply(this, arguments);
114
+ };
115
+
116
+ object.on(event, wrapper, thisp);
117
+ };
118
+
119
+ object.bind = function (object, events) {
120
+ var prop, i, l;
121
+ if (!events) {
122
+ for (prop in object) {
123
+ if (typeof object[prop] === "function") {
124
+ this.on(prop, object[prop], object);
125
+ }
126
+ }
127
+ } else {
128
+ for (i = 0, l = events.length; i < l; ++i) {
129
+ if (typeof object[events[i]] === "function") {
130
+ this.on(events[i], object[events[i]], object);
131
+ } else {
132
+ throw new Error("No such method " + events[i]);
133
+ }
134
+ }
135
+ }
136
+ return object;
137
+ };
138
+
139
+ object.emit = function (event) {
140
+ var toNotify = supervisors(this);
141
+ var args = slice.call(arguments), i, l;
142
+
143
+ for (i = 0, l = toNotify.length; i < l; ++i) {
144
+ notifyListener(event, toNotify[i], args);
145
+ }
146
+
147
+ toNotify = listeners(this, event).slice();
148
+ args = slice.call(arguments, 1);
149
+ for (i = 0, l = toNotify.length; i < l; ++i) {
150
+ notifyListener(event, toNotify[i], args);
151
+ }
152
+ };
153
+
154
+ object.errback = function (listener) {
155
+ if (!this.errbacks) { this.errbacks = []; }
156
+ this.errbacks.push(assertFunction(listener));
157
+ };
158
+
159
+ return object;
160
+ }
161
+
162
+ return {
163
+ createEventEmitter: createEventEmitter,
164
+ aggregate: function (emitters) {
165
+ var aggregate = createEventEmitter();
166
+ emitters.forEach(function (emitter) {
167
+ emitter.on(function (event, data) {
168
+ aggregate.emit(event, data);
169
+ });
170
+ });
171
+ return aggregate;
172
+ }
173
+ };
174
+ });
@@ -142,7 +142,8 @@ var buster = (function (setTimeout, B) {
142
142
  }
143
143
  };
144
144
 
145
- if (typeof process === "object") {
145
+ if (typeof process === "object" &&
146
+ typeof require === "function" && typeof module === "object") {
146
147
  var crypto = require("crypto");
147
148
  var path = require("path");
148
149
 
@@ -188,18 +189,18 @@ var buster = (function (setTimeout, B) {
188
189
  };
189
190
  } else {
190
191
  // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
191
- buster.filter = function (fn, thisp) {
192
+ buster.filter = function (arr, fn, thisp) {
192
193
  "use strict";
193
- if (this == null) { throw new TypeError(); }
194
+ if (arr == null) { throw new TypeError(); }
194
195
 
195
- var t = Object(this);
196
+ var t = Object(arr);
196
197
  var len = t.length >>> 0;
197
198
  if (typeof fn != "function") { throw new TypeError(); }
198
199
 
199
200
  var res = [];
200
201
  for (var i = 0; i < len; i++) {
201
202
  if (i in t) {
202
- var val = t[i]; // in case fun mutates this
203
+ var val = t[i];
203
204
  if (fn.call(thisp, val, i, t)) { res.push(val); }
204
205
  }
205
206
  }
@@ -1,63 +1,67 @@
1
- if (typeof module == "object" && typeof require == "function") {
2
- var buster = require("buster-core");
3
- buster.assertions = require("../buster-assertions");
4
- }
1
+ ((typeof define === "function" && define.amd && function (m) {
2
+ define("expect", ["lodash"], m);
3
+ }) || (typeof module === "object" && function (m) {
4
+ module.exports = m(require("lodash"));
5
+ }) || function (m) { this.expect = m(this._); }
6
+ )(function (_) {
7
+ var expectation = {};
8
+ function F() {}
9
+ var create = function (object) { F.prototype = object; return new F(); };
5
10
 
6
- (function (ba) {
7
- ba.expectation = {};
8
-
9
- ba.expect = function (actual) {
10
- var expectation = buster.extend(buster.create(ba.expectation), {
11
+ var expect = function (actual) {
12
+ var expectation = _.extend(create(expect.expectation), {
11
13
  actual: actual,
12
14
  assertMode: true
13
15
  });
14
- expectation.not = buster.create(expectation);
16
+ expectation.not = create(expectation);
15
17
  expectation.not.assertMode = false;
16
18
  return expectation;
17
19
  };
18
20
 
19
- ba.expect.wrapAssertion = function (assertion, expectation) {
20
- ba.expectation[expectation] = function () {
21
- var args = [this.actual].concat(Array.prototype.slice.call(arguments));
21
+ expect.expectation = expectation;
22
+
23
+ expect.wrapAssertion = function (assertion, expectation, referee) {
24
+ expect.expectation[expectation] = function () {
25
+ var args = [this.actual].concat(_.toArray(arguments));
22
26
  var type = this.assertMode ? "assert" : "refute";
23
27
  var callFunc;
24
28
 
25
29
  if (assertion === "assert") {
26
- callFunc = this.assertMode ? ba.assert : ba.refute;
30
+ callFunc = this.assertMode ? referee.assert : referee.refute;
27
31
  } else if (assertion === "refute") {
28
- callFunc = this.assertMode ? ba.refute : ba.assert;
32
+ callFunc = this.assertMode ? referee.refute : referee.assert;
29
33
  } else {
30
- callFunc = ba[type][assertion];
34
+ callFunc = referee[type][assertion];
31
35
  }
32
36
 
33
37
  try {
34
- return callFunc.apply(ba.expect, args);
38
+ return callFunc.apply(referee.expect, args);
35
39
  } catch (e) {
36
40
  e.message = (e.message || "").replace(
37
41
  "[" + type + "." + assertion + "]",
38
- "[expect." + (this.assertMode ? "" : "not.") + expectation + "]");
42
+ "[expect." + (this.assertMode ? "" : "not.") +
43
+ expectation + "]"
44
+ );
39
45
  throw e;
40
46
  }
41
47
  };
42
48
  };
43
49
 
44
- var prop, expectationName;
45
-
46
- for (prop in ba.assert) {
47
- if (ba.assert[prop].expectationName) {
48
- expectationName = ba.assert[prop].expectationName;
49
- ba.expect.wrapAssertion(prop, expectationName);
50
- }
51
- }
50
+ expect.init = function (referee) {
51
+ _.each(_.keys(referee.assert), function (name) {
52
+ var expectationName = referee.assert[name].expectationName;
53
+ if (expectationName) {
54
+ expect.wrapAssertion(name, expectationName, referee);
55
+ }
56
+ });
52
57
 
53
- ba.expect.wrapAssertion("assert", "toBeTruthy");
54
- ba.expect.wrapAssertion("refute", "toBeFalsy");
58
+ expect.wrapAssertion("assert", "toBeTruthy", referee);
59
+ expect.wrapAssertion("refute", "toBeFalsy", referee);
55
60
 
56
- if (ba.expectation.toBeNear) {
57
- ba.expectation.toBeCloseTo = ba.expectation.toBeNear;
58
- }
61
+ if (expect.expectation.toBeNear) {
62
+ expect.expectation.toBeCloseTo = expect.expectation.toBeNear;
63
+ }
64
+ };
59
65
 
60
- if (typeof module == "object") {
61
- module.exports = ba.expect;
62
- }
63
- }(buster.assertions));
66
+ return expect;
67
+ });
@@ -0,0 +1,215 @@
1
+ ((typeof define === "function" && define.amd && function (m) {
2
+ define("formatio", ["samsam"], m);
3
+ }) || (typeof module === "object" && function (m) {
4
+ module.exports = m(require("samsam"));
5
+ }) || function (m) { this.formatio = m(this.samsam); }
6
+ )(function (samsam) {
7
+ "use strict";
8
+
9
+ var formatio = {
10
+ excludeConstructors: ["Object", /^.$/],
11
+ quoteStrings: true,
12
+ limitChildrenCount: 0
13
+ };
14
+
15
+ var hasOwn = Object.prototype.hasOwnProperty;
16
+
17
+ var specialObjects = [];
18
+ if (typeof global !== "undefined") {
19
+ specialObjects.push({ object: global, value: "[object global]" });
20
+ }
21
+ if (typeof document !== "undefined") {
22
+ specialObjects.push({
23
+ object: document,
24
+ value: "[object HTMLDocument]"
25
+ });
26
+ }
27
+ if (typeof window !== "undefined") {
28
+ specialObjects.push({ object: window, value: "[object Window]" });
29
+ }
30
+
31
+ function functionName(func) {
32
+ if (!func) { return ""; }
33
+ if (func.displayName) { return func.displayName; }
34
+ if (func.name) { return func.name; }
35
+ var matches = func.toString().match(/function\s+([^\(]+)/m);
36
+ return (matches && matches[1]) || "";
37
+ }
38
+
39
+ function constructorName(f, object) {
40
+ var name = functionName(object && object.constructor);
41
+ var excludes = f.excludeConstructors ||
42
+ formatio.excludeConstructors || [];
43
+
44
+ var i, l;
45
+ for (i = 0, l = excludes.length; i < l; ++i) {
46
+ if (typeof excludes[i] === "string" && excludes[i] === name) {
47
+ return "";
48
+ } else if (excludes[i].test && excludes[i].test(name)) {
49
+ return "";
50
+ }
51
+ }
52
+
53
+ return name;
54
+ }
55
+
56
+ function isCircular(object, objects) {
57
+ if (typeof object !== "object") { return false; }
58
+ var i, l;
59
+ for (i = 0, l = objects.length; i < l; ++i) {
60
+ if (objects[i] === object) { return true; }
61
+ }
62
+ return false;
63
+ }
64
+
65
+ function ascii(f, object, processed, indent) {
66
+ if (typeof object === "string") {
67
+ if (object.length === 0) { return "(empty string)"; }
68
+ var qs = f.quoteStrings;
69
+ var quote = typeof qs !== "boolean" || qs;
70
+ return processed || quote ? '"' + object + '"' : object;
71
+ }
72
+
73
+ if (typeof object === "function" && !(object instanceof RegExp)) {
74
+ return ascii.func(object);
75
+ }
76
+
77
+ processed = processed || [];
78
+
79
+ if (isCircular(object, processed)) { return "[Circular]"; }
80
+
81
+ if (Object.prototype.toString.call(object) === "[object Array]") {
82
+ return ascii.array.call(f, object, processed);
83
+ }
84
+
85
+ if (!object) { return String((1/object) === -Infinity ? "-0" : object); }
86
+ if (samsam.isElement(object)) { return ascii.element(object); }
87
+
88
+ if (typeof object.toString === "function" &&
89
+ object.toString !== Object.prototype.toString) {
90
+ return object.toString();
91
+ }
92
+
93
+ var i, l;
94
+ for (i = 0, l = specialObjects.length; i < l; i++) {
95
+ if (object === specialObjects[i].object) {
96
+ return specialObjects[i].value;
97
+ }
98
+ }
99
+
100
+ return ascii.object.call(f, object, processed, indent);
101
+ }
102
+
103
+ ascii.func = function (func) {
104
+ return "function " + functionName(func) + "() {}";
105
+ };
106
+
107
+ ascii.array = function (array, processed) {
108
+ processed = processed || [];
109
+ processed.push(array);
110
+ var pieces = [];
111
+ var i, l;
112
+ l = (this.limitChildrenCount > 0) ?
113
+ Math.min(this.limitChildrenCount, array.length) : array.length;
114
+
115
+ for (i = 0; i < l; ++i) {
116
+ pieces.push(ascii(this, array[i], processed));
117
+ }
118
+
119
+ if(l < array.length)
120
+ pieces.push("[... " + (array.length - l) + " more elements]");
121
+
122
+ return "[" + pieces.join(", ") + "]";
123
+ };
124
+
125
+ ascii.object = function (object, processed, indent) {
126
+ processed = processed || [];
127
+ processed.push(object);
128
+ indent = indent || 0;
129
+ var pieces = [], properties = samsam.keys(object).sort();
130
+ var length = 3;
131
+ var prop, str, obj, i, k, l;
132
+ l = (this.limitChildrenCount > 0) ?
133
+ Math.min(this.limitChildrenCount, properties.length) : properties.length;
134
+
135
+ for (i = 0; i < l; ++i) {
136
+ prop = properties[i];
137
+ obj = object[prop];
138
+
139
+ if (isCircular(obj, processed)) {
140
+ str = "[Circular]";
141
+ } else {
142
+ str = ascii(this, obj, processed, indent + 2);
143
+ }
144
+
145
+ str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str;
146
+ length += str.length;
147
+ pieces.push(str);
148
+ }
149
+
150
+ var cons = constructorName(this, object);
151
+ var prefix = cons ? "[" + cons + "] " : "";
152
+ var is = "";
153
+ for (i = 0, k = indent; i < k; ++i) { is += " "; }
154
+
155
+ if(l < properties.length)
156
+ pieces.push("[... " + (properties.length - l) + " more elements]");
157
+
158
+ if (length + indent > 80) {
159
+ return prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" +
160
+ is + "}";
161
+ }
162
+ return prefix + "{ " + pieces.join(", ") + " }";
163
+ };
164
+
165
+ ascii.element = function (element) {
166
+ var tagName = element.tagName.toLowerCase();
167
+ var attrs = element.attributes, attr, pairs = [], attrName, i, l, val;
168
+
169
+ for (i = 0, l = attrs.length; i < l; ++i) {
170
+ attr = attrs.item(i);
171
+ attrName = attr.nodeName.toLowerCase().replace("html:", "");
172
+ val = attr.nodeValue;
173
+ if (attrName !== "contenteditable" || val !== "inherit") {
174
+ if (!!val) { pairs.push(attrName + "=\"" + val + "\""); }
175
+ }
176
+ }
177
+
178
+ var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
179
+ // SVG elements have undefined innerHTML
180
+ var content = element.innerHTML || '';
181
+
182
+ if (content.length > 20) {
183
+ content = content.substr(0, 20) + "[...]";
184
+ }
185
+
186
+ var res = formatted + pairs.join(" ") + ">" + content +
187
+ "</" + tagName + ">";
188
+
189
+ return res.replace(/ contentEditable="inherit"/, "");
190
+ };
191
+
192
+ function Formatio(options) {
193
+ for (var opt in options) {
194
+ this[opt] = options[opt];
195
+ }
196
+ }
197
+
198
+ Formatio.prototype = {
199
+ functionName: functionName,
200
+
201
+ configure: function (options) {
202
+ return new Formatio(options);
203
+ },
204
+
205
+ constructorName: function (object) {
206
+ return constructorName(this, object);
207
+ },
208
+
209
+ ascii: function (object, processed, indent) {
210
+ return ascii(this, object, processed, indent);
211
+ }
212
+ };
213
+
214
+ return Formatio.prototype;
215
+ });