Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing tests #5

Closed
wants to merge 2 commits into from

1 participant

@noonat

Upgraded jspec to fix make test not actually running any tests.

Also removed a broken test. It was added in this commit:
http://github.com/visionmedia/js-yaml/commit/0c4c354ddc32c2d46588d8064c28b9d4e1b1d134

But there isn't a matching fixture and it didn't seem to have anything to do with lists...

@noonat noonat closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2010
  1. @noonat

    Upgrading jspec

    noonat authored
  2. @noonat

    Removing invalid test -- fixture doesn't exist, doesn't seem to have …

    noonat authored
    …anything to do with lists?
This page is out of date. Refresh to see the latest.
View
15 spec/lib/jspec.jquery.js
@@ -60,9 +60,18 @@ JSpec
},
have_event_handlers : function(actual, expected) {
- return jQuery(actual).data('events') ?
- jQuery(actual).data('events').hasOwnProperty(expected) :
- false
+ if (jQuery(actual).data('events') && jQuery(actual).data('events').hasOwnProperty(expected)) {
+ return true;
+ } else if (jQuery(actual.context).data('events') && jQuery(actual.context).data('events').hasOwnProperty(expected)) {
+ var events = jQuery(actual.context).data('events')[expected];
+
+ for (index in events) {
+ if (events[index].selector === actual.selector) {
+ return true;
+ }
+ }
+ }
+ return false;
},
'be disabled selected checked' : function(attr) {
View
55 spec/lib/jspec.js
@@ -4,7 +4,7 @@
;(function(){
JSpec = {
- version : '4.2.1',
+ version : '4.3.3',
assert : true,
cache : {},
suites : [],
@@ -1050,8 +1050,12 @@
if (object === false) return 'false'
if (object.an_instance_of) return 'an instance of ' + object.an_instance_of.name
if (object.jquery && object.selector.length > 0) return 'selector ' + puts(object.selector)
- if (object.jquery) return object.get(0).outerHTML
- if (object.nodeName) return object.outerHTML
+ if (object.jquery && object.get(0) && object.get(0).outerHTML) return object.get(0).outerHTML
+ if (object.jquery && object.get(0) && object.get(0).nodeType == 9) return 'jQuery(document)'
+ if (object.jquery && object.get(0)) return document.createElement('div').appendChild(object.get(0)).parentNode.innerHTML
+ if (object.jquery && object.length == 0) return 'jQuery()'
+ if (object.nodeName && object.outerHTML) return object.outerHTML
+ if (object.nodeName) return document.createElement('div').appendChild(object).parentNode.innerHTML
switch (object.constructor) {
case Function: return object.name || object
case String:
@@ -1272,12 +1276,13 @@
destub : function(object, method) {
var captures
if (method) {
- if (object['__prototype__' + method])
+ if (object.hasOwnProperty('__prototype__' + method))
delete object[method]
- else
+ else if (object.hasOwnProperty('__original__' + method))
object[method] = object['__original__' + method]
+
delete object['__prototype__' + method]
- delete object['__original____' + method]
+ delete object['__original__' + method]
}
else if (object) {
for (var key in object)
@@ -1302,9 +1307,13 @@
stub : function(object, method) {
hook('stubbing', object, method)
+
+ //unbind any stub already present on this method
+ JSpec.destub(object, method);
JSpec.stubbed.push(object)
var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
object[type + method] = object[method]
+
object[method] = function(){}
return {
and_return : function(value) {
@@ -1749,10 +1758,20 @@
// --- Node.js support
- if (typeof GLOBAL === 'object' && typeof exports === 'object')
- quit = process.exit,
- print = require('sys').puts,
- readFile = require('fs').readFileSync
+ if (typeof GLOBAL === 'object' && typeof exports === 'object') {
+ var fs = require('fs')
+ quit = process.exit
+ print = require('sys').puts
+ readFile = function(file){
+ return fs.readFileSync(file).toString('utf8')
+ }
+ }
+
+ // --- envjsrb / johnson support
+
+ if (typeof Johnson === 'object') {
+ quit = function () {}
+ }
// --- Utility functions
@@ -1872,17 +1891,17 @@
},
have_prop : function(actual, property, value) {
- return actual[property] === undefined ||
- actual[property] instanceof Function ? false:
- value === undefined ? true:
- does(actual[property], 'eql', value)
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ does(actual[property],'eql',value)
},
have_property : function(actual, property, value) {
- return actual[property] === undefined ||
- actual[property] instanceof Function ? false:
- value === undefined ? true:
- value === actual[property]
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ value === actualVal
}
})
View
182 spec/lib/jspec.timers.js
@@ -1,73 +1,122 @@
-// JSpec - Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+// Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
;(function(){
/**
- * Version.
- */
-
- mockTimersVersion = '1.0.2'
-
- /**
* Localized timer stack.
*/
+ var timers = [];
- var timers = []
+ // nodejs, rhino don't have a window object
+ var global = this;
- /**
- * Set mock timeout with _callback_ and timeout of _ms_.
- *
- * @param {function} callback
- * @param {int} ms
- * @return {int}
- * @api public
- */
+ // if they where mocked before this library is loaded - bad luck
+ var savedGlobals = {
+ setTimeout: global.setTimeout,
+ setInterval: global.setInterval,
+ clearInterval: global.clearInterval,
+ clearTimeout: global.clearTimeout,
+
+ // those should not be globals, but are mocked none the less, so we save them
+ resetTimers: global.resetTimers,
+ tick: global.tick
+ };
+ var hadResetTimers = 'resetTimers' in global;
+ var hadTick = 'tick' in global;
- setTimeout = function(callback, ms) {
- var id
- return id = setInterval(function(){
- callback()
- clearInterval(id)
- }, ms)
+ function forEachProperty(anObject, aClosure) {
+ for (var key in anObject) {
+ if ( ! anObject.hasOwnProperty(key))
+ continue;
+
+ aClosure(key, anObject[key]);
+ }
}
- /**
- * Set mock interval with _callback_ and interval of _ms_.
- *
- * @param {function} callback
- * @param {int} ms
- * @return {int}
- * @api public
- */
-
- setInterval = function(callback, ms) {
- callback.step = ms, callback.current = callback.last = 0
- return timers[timers.length] = callback, timers.length
+ global.MockTimers = {
+
+ mockTimersVersion: '2.0.0',
+
+ mockGlobalTimerFunctions: function() {
+ forEachProperty(this.mocks, function(aName, aFunction) {
+ global[aName] = aFunction;
+ });
+ },
+
+ unmockGlobalTimerFunctions: function() {
+ forEachProperty(this.savedGlobals, function(aName, aFunction) {
+ global[aName] = aFunction;
+ });
+
+ if ( ! hadResetTimers)
+ delete global['resetTimers'];
+ if ( ! hadTick)
+ delete global['tick'];
+
+ }
+ };
+
+ function clearTimer(id) {
+ return delete timers[--id];
}
- /**
- * Destroy timer with _id_.
- *
- * @param {int} id
- * @return {bool}
- * @api public
- */
+ var mocks = {
+
+ /**
+ * Set mock timeout with _callback_ and timeout of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+ setTimeout: function(callback, ms) {
+ var id;
+ return id = setInterval(function(){
+ callback();
+ clearInterval(id);
+ }, ms);
+ },
- clearInterval = clearTimeout = function(id) {
- return delete timers[--id]
- }
+
+ /**
+ * Set mock interval with _callback_ and interval of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+ setInterval: function(callback, ms) {
+ // REFACT: use wrapper object so callback is not changed -> state leak
+ callback.step = ms;
+ callback.current = callback.last = 0;
+ timers[timers.length] = callback;
+ return timers.length;
+ },
+
+ /**
+ * Destroy timer with _id_.
+ *
+ * @param {int} id
+ * @return {bool}
+ * @api public
+ */
+ clearInterval: clearTimer,
+ clearTimeout: clearTimer
+ };
+ // additional functions that are not originally in the global namespace
/**
* Reset timers.
*
* @return {array}
* @api public
*/
-
- resetTimers = function() {
- return timers = []
- }
+ mocks.resetTimers = function() {
+ return timers = [];
+ };
/**
* Increment each timers internal clock by _ms_.
@@ -75,16 +124,31 @@
* @param {int} ms
* @api public
*/
+ mocks.tick = function(ms) {
+ for (var i = 0, len = timers.length; i < len; ++i) {
+ if ( ! timers[i] || ! (timers[i].current += ms))
+ continue;
+
+ if (timers[i].current - timers[i].last < timers[i].step)
+ continue;
+
+ var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step);
+ var remainder = (timers[i].current - timers[i].last) % timers[i].step;
+ timers[i].last = timers[i].current - remainder;
+ while (times-- && timers[i])
+ timers[i]();
+ }
+ };
- tick = function(ms) {
- for (var i = 0, len = timers.length; i < len; ++i)
- if (timers[i] && (timers[i].current += ms))
- if (timers[i].current - timers[i].last >= timers[i].step) {
- var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step)
- var remainder = (timers[i].current - timers[i].last) % timers[i].step
- timers[i].last = timers[i].current - remainder
- while (times-- && timers[i]) timers[i]()
- }
- }
+ // make them available publicly
+ MockTimers.mocks = mocks;
-})()
+ JSpec.include({
+ beforeSpec: function(){
+ MockTimers.mockGlobalTimerFunctions();
+ },
+ afterSpec : function() {
+ MockTimers.unmockGlobalTimerFunctions();
+ }
+ });
+})();
View
4 spec/lib/jspec.xhr.js
@@ -34,7 +34,9 @@
*/
getAllResponseHeaders : function(){
- return this.responseHeaders
+ return JSpec.inject(this.responseHeaders, '', function(buf, key, val){
+ return buf + key + ': ' + val + '\r\n'
+ })
},
/**
View
10 spec/spec.core.js
@@ -106,16 +106,6 @@ describe 'yaml'
assert('list', [1,2,3])
end
- it 'should work with arbitrary text'
- assert('hash.text', {
- user: {
- name: 'tj',
- date: '1987-05-25',
- position: 'web developer and ceo of Vision Media'
- }
- })
- end
-
describe 'inline'
it 'should work'
assert('list.inline', ['tj', 23])
Something went wrong with that request. Please try again.