Updated to JSpec 3.0.0
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent ddd6f27 · Browse files · 12 files·+281 added−156 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+281 added−156 removed
- tests:+277 added−152 removed
- other:+4 added−4 removed
Provenance
- Commit
694572b- Tree
1d078df- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
ddd6f27
12 files changed+281 added−156 removed
modified:spec/lib/images/sprites.pngbinary
A binary file, modified.
modified:spec/lib/jspec.css+2 added-2 removed
112 unmodified linesExpand all11311411511611711711811912012112212212312412512623 unmodified lines112 unmodified linesExpand all#jspec-report td.pass { background: url(images/sprites.png) 3px -7px no-repeat;}#jspec-report td.fail { background: url(images/sprites.png) 3px -47px no-repeat; background: url(images/sprites.png) 3px -158px no-repeat; font-weight: bold; color: #FC0D0D;}#jspec-report td.requires-implementation { background: url(images/sprites.png) 3px -87px no-repeat; background: url(images/sprites.png) 3px -333px no-repeat;}#jspec-report tr.description td { margin-top: 25px; padding-top: 25px;23 unmodified linesadded:spec/lib/jspec.growl.js+115 added
1+2+// JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4+;(function(){5+ 6+ Growl = {7+ 8+ // --- Version9+ 10+ version: '1.0.0',11+ 12+ /**13+ * Execute the given _cmd_, returning an array of lines from stdout.14+ *15+ * Examples:16+ *17+ * Growl.exec('growlnotify', '-m', msg)18+ *19+ * @param {string ...} cmd20+ * @return {array}21+ * @api public22+ */23+24+ exec: function(cmd) {25+ var lines = [], line26+ with (JavaImporter(java.lang, java.io)) {27+ var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))28+ var stream = new DataInputStream(proccess.getInputStream())29+ while (line = stream.readLine())30+ lines.push(line + '')31+ stream.close() 32+ }33+ return lines34+ },35+ 36+ /**37+ * Return the extension of the given _path_ or null.38+ *39+ * @param {string} path40+ * @return {string}41+ * @api private42+ */43+ 44+ extname: function(path) {45+ return path.lastIndexOf('.') != -1 ? 46+ path.slice(path.lastIndexOf('.') + 1, path.length) :47+ null48+ },49+50+ /**51+ * Version of the 'growlnotify' binary.52+ *53+ * @return {string}54+ * @api private55+ */56+57+ binVersion: function() {58+ try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}59+ },60+61+ /**62+ * Send growl notification _msg_ with _options_.63+ *64+ * Options:65+ *66+ * - title Notification title67+ * - sticky Make the notification stick (defaults to false)68+ * - name Application name (defaults to growlnotify)69+ * - image70+ * - path to an icon sets --iconpath71+ * - path to an image sets --image72+ * - capitalized word sets --appIcon73+ * - filename uses extname as --icon74+ * - otherwise treated as --icon75+ *76+ * Examples:77+ *78+ * Growl.notify('New email')79+ * Growl.notify('5 new emails', { title: 'Thunderbird' })80+ *81+ * @param {string} msg82+ * @param {options} hash83+ * @api public84+ */85+86+ notify: function(msg, options) {87+ options = options || {}88+ var args = ['growlnotify', '-m', msg]89+ if (!this.binVersion()) throw new Error('growlnotify executable is required')90+ if (image = options.image) {91+ var flag, ext = this.extname(image)92+ flag = flag || ext == 'icns' && 'iconpath'93+ flag = flag || /^[A-Z]/.test(image) && 'appIcon'94+ flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'95+ flag = flag || ext && (image = ext) && 'icon'96+ flag = flag || 'icon'97+ args.push('--' + flag, image)98+ }99+ if (options.sticky) args.push('--sticky')100+ if (options.name) args.push('--name', options.name)101+ if (options.title) args.push(options.title)102+ this.exec.apply(this, args)103+ }104+ }105+ 106+ JSpec.include({107+ name: 'Growl',108+ reporting: function(options){109+ var stats = JSpec.stats110+ if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})111+ else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })112+ }113+ })114+ 115+})()modified:spec/lib/jspec.jquery.js+1 added-1 removed
45 unmodified lines46 return !JSpec.does(actual, 'be_visible')47 },48 49 have_classes : function(actual) {50- return !JSpec.any(JSpec.argumentsToArray(arguments, 1), function(arg){50+ return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){51 return !JSpec.does(actual, 'have_class', arg)52 })53 },54 17 unmodified linesmodified:spec/lib/jspec.js+98 added-101 removed
1 2 // JSpec - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4-(function(){4+;(function(){5 6 JSpec = {7-8- version : '2.11.13',7+ version : '3.0.0',8+ assert : true,9 cache : {},10 suites : [],11 modules : [],12 allSuites : [],13 matchers : {},14 stubbed : [],15+ options : {},16 request : 'XMLHttpRequest' in this ? XMLHttpRequest : null,17 stats : { specs: 0, assertions: 0, failures: 0, passes: 0, specsFinished: 0, suitesFinished: 0 },17- options : { profile: false },18 19 /**20 * Default context in which bodies are evaluated.21 *28 unmodified lines50 return { an_instance_of : constructor }51 },52 53 /**54- * Load fixture at _path_. This utility function55- * supplies the means to resolve, and cache fixture contents56- * via the DOM or Rhino.54+ * Load fixture at _path_.55 *56 * Fixtures are resolved as:57 *58 * - <path>61- * - fixtures/<path>62- * - fixtures/<path>.html59+ * - <path>.html60 *61 * @param {string} path62 * @return {string}63 * @api public1 unmodified line65 66 fixture : function(path) {67 if (JSpec.cache[path]) return JSpec.cache[path]68 return JSpec.cache[path] = 72- JSpec.tryLoading(path) ||73- JSpec.tryLoading('fixtures/' + path) ||74- JSpec.tryLoading('fixtures/' + path + '.html') ||75- JSpec.tryLoading('spec/' + path) ||76- JSpec.tryLoading('spec/fixtures/' + path) ||77- JSpec.tryLoading('spec/fixtures/' + path + '.html')69+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) ||70+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.html')71 }72 },73 74 // --- Objects75 83- formatters : {76+ reporters : {77 78 /**79 * Report to server.80 * 34 unmodified lines115 if ('close' in main) main.close()116 },117 118 /**126- * Default formatter, outputting to the DOM.119+ * Default reporter, outputting to the DOM.120 *121 * Options:122 * - reportToId id of element to output reports to, defaults to 'jspec'123 * - failuresOnly displays only suites with failing specs17 unmodified lines141 142 report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \143 <span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \144 <span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \145+ <span class="passes">Duration: <em>' + results.duration + '</em> ms</span> \146 </div><table class="suites">' + map(results.allSuites, function(suite) {147 var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran148 if (displaySuite && suite.hasSpecs())149 return '<tr class="description"><td colspan="2">' + escape(suite.description) + '</td></tr>' +13 unmodified lines163 }).join('') + '</table></div>'164 },165 166 /**173- * Terminal formatter.167+ * Terminal reporter.168 *169 * @api public170 */171 172 Terminal : function(results, options) {173 failuresOnly = option('failuresOnly')174 print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') + 181- color(" Failures: ", 'bold') + color(results.stats.failures, 'red') + "\n")175+ color(" Failures: ", 'bold') + color(results.stats.failures, 'red') +176+ color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n")177 178 function indent(string) {179 return string.replace(/^(.)/gm, ' $1')180 }21 unmodified lines202 quit(results.stats.failures)203 },204 205 /**211- * Console formatter.206+ * Console reporter.207 *208 * @api public209 */210 29 unmodified lines240 241 // Report assertion results242 243 report : function() {244+ if (JSpec.assert) 249- this.passed ? JSpec.stats.passes++ : JSpec.stats.failures++245+ this.passed ? JSpec.stats.passes++ : JSpec.stats.failures++246 return this247 },248 249 // Run the assertion15 unmodified lines265 266 // Proxy267 268 object[method] = function(){273- args = argumentsToArray(arguments)269+ args = toArray(arguments)270 result = old.apply(object, args)271 self.calls.push({ args : args, result : result })272 return result273 }23 unmodified lines297 298 // Proxy arguments passed299 300 with_args : function() {305- this.expectedArgs = argumentsToArray(arguments)301+ this.expectedArgs = toArray(arguments)302 return this303 },304 305 // Check if any calls have failing results1 unmodified line307 anyResultsFail : function() {308 return any(this.calls, function(call){309 return self.expectedResult.an_instance_of ?310 call.result.constructor != self.expectedResult.an_instance_of:315- hash(self.expectedResult) != hash(call.result)311+ !equal(self.expectedResult, call.result)312 })313 },314 315 // Check if any calls have passing results1 unmodified line317 anyResultsPass : function() {318 return any(this.calls, function(call){319 return self.expectedResult.an_instance_of ?320 call.result.constructor == self.expectedResult.an_instance_of:325- hash(self.expectedResult) == hash(call.result)321+ equal(self.expectedResult, call.result)322 })323 },324 325 // Return the passing result15 unmodified lines341 return any(self.expectedArgs, function(i, arg){342 if (arg == null) return call.args[i] == null343 return arg.an_instance_of ?344 call.args[i].constructor != arg.an_instance_of:349- hash(arg) != hash(call.args[i])345+ !equal(arg, call.args[i])346 347 })348 })349 },4 unmodified lines354 return any(this.calls, function(call){355 return any(self.expectedArgs, function(i, arg){356 return arg.an_instance_of ?357 call.args[i].constructor == arg.an_instance_of:362- hash(arg) == hash(call.args[i])358+ equal(arg, call.args[i])359 360 })361 })362 },12 unmodified lines375 376 // Report assertion results377 378 report : function() {379+ if (JSpec.assert) 383- this.passed ? ++JSpec.stats.passes : ++JSpec.stats.failures380+ this.passed ? ++JSpec.stats.passes : ++JSpec.stats.failures381 return this382 },383 384 // Run the assertion117 unmodified lines502 // Add passing assertion503 504 pass : function(message) {505 this.assertions.push({ passed: true, message: message })509- ++JSpec.stats.passes506+ if (JSpec.assert) ++JSpec.stats.passes507 },508 509 // Add failing assertion510 511 fail : function(message) {512 this.assertions.push({ passed: false, message: message })516- ++JSpec.stats.failures513+ if (JSpec.assert) ++JSpec.stats.failures514 },515 516 // Run deferred assertions517 157 unmodified lines675 676 /**677 * Include _object_ which may be a hash or Module instance.678 *682- * @param {has, Module} object679+ * @param {hash, Module} object680 * @return {JSpec}681 * @api public682 */683 2 unmodified lines686 this.modules.push(module)687 if ('init' in module) module.init()688 if ('utilities' in module) extend(this.defaultContext, module.utilities)689 if ('matchers' in module) this.addMatchers(module.matchers)693- if ('formatters' in module) extend(this.formatters, module.formatters)690+ if ('reporters' in module) extend(this.reporters, module.reporters)691 if ('DSLs' in module)692 each(module.DSLs, function(name, methods){693 JSpec.DSLs[name] = JSpec.DSLs[name] || {}694 extend(JSpec.DSLs[name], methods)12 unmodified lines707 * @api private708 */709 710 hook : function(name, args) {714- args = argumentsToArray(arguments, 1)711+ args = toArray(arguments, 1)712 return inject(JSpec.modules, [], function(results, module){713 if (typeof module[name] == 'function')714 results.push(JSpec.evalHook(module, name, args))715 })85 unmodified lines801 * @return {array}802 * @api public803 */804 808- argumentsToArray : function(arguments, offset) {805+ toArray : function(arguments, offset) {806 return Array.prototype.slice.call(arguments, offset || 0)807 },808 809 /**28 unmodified lines838 defaultMatcherMessage : function(actual, expected, negate, name) {839 return 'expected ' + puts(actual) + ' to ' + 840 (negate ? 'not ' : '') + 841 name.replace(/_/g, ' ') +845- ' ' + puts.apply(this, expected.slice(1))842+ ' ' + (expected.length > 1 ?843+ puts.apply(this, expected.slice(1)) :844+ '')845 },846 847 /**848 * Normalize a matcher message.56 unmodified lines905 option : function(key) {906 return (value = query(key)) !== null ? value :907 JSpec.options[key] || null908 },909+ 910+ /**911+ * Check if object _a_, is equal to object _b_.912+ *913+ * @param {object} a914+ * @param {object} b915+ * @return {bool}916+ * @api private917+ */918+ 919+ equal: function(a, b) {920+ if (typeof a != typeof b) return921+ if (a === b) return true922+ if (a instanceof RegExp)923+ return a.toString() === b.toString()924+ if (a instanceof Date)925+ return Number(a) === Number(b)926+ if (typeof a != 'object') return927+ if (a.length !== undefined)928+ if (a.length !== b.length) return929+ else930+ for (var i = 0, len = a.length; i < len; ++i)931+ if (!equal(a[i], b[i]))932+ return933+ for (var key in a)934+ if (!equal(a[key], b[key]))935+ return936+ return true937+ },938 939 /**912- * Generates a hash of the object passed.913- *914- * @param {object} object915- * @return {string}916- * @api private917- */918-919- hash : function(object) {920- if (object == null) return 'null'921- if (object == undefined) return 'undefined'922- function serialize(prefix) {923- return inject(object, prefix + ':', function(buffer, key, value){924- return buffer += hash(value)925- })926- }927- switch (object.constructor) {928- case Array : return serialize('a')929- case RegExp: return 'r:' + object.toString()930- case Number: return 'n:' + object.toString()931- case String: return 's:' + object.toString()932- case Object: return 'o:' + inject(object, [], function(array, key, value){933- array.push([key, hash(value)])934- }).sort()935- default: return object.toString()936- }937- },938-939- /**940 * Return last element of an array.941 *942 * @param {array} array943 * @return {object}12 unmodified lines956 * @api public957 */958 959 puts : function(object) {960- if (arguments.length > 1) {961- return map(argumentsToArray(arguments), function(arg){960+ if (arguments.length > 1)961+ return map(toArray(arguments), function(arg){962 return puts(arg)963 }).join(', ')964- }965- if (object === undefined) return ''964+ if (object === undefined) return 'undefined'965 if (object === null) return 'null'966 if (object === true) return 'true'967 if (object === false) return 'false'968 if (object.an_instance_of) return 'an instance of ' + object.an_instance_of.name970- if (object.jquery && object.selector.length > 0) return 'selector ' + puts(object.selector) + ''969+ if (object.jquery && object.selector.length > 0) return 'selector ' + puts(object.selector)970 if (object.jquery) return object.get(0).outerHTML971 if (object.nodeName) return object.outerHTML972 switch (object.constructor) {974- case String: return "'" + object + "'"975- case Number: return object973 case Function: return object.name || object 974+ case String: 975+ return '"' + object976+ .replace(/"/g, '\\"')977+ .replace(/\n/g, '\\n')978+ .replace(/\t/g, '\\t')979+ + '"'980 case Array: 981 return inject(object, '[', function(b, v){982 return b + ', ' + puts(v)983 }).replace('[,', '[') + ' ]'984 case Object:985+ object.__hit__ = true986 return inject(object, '{', function(b, k, v) {983- return b + ', ' + puts(k) + ' : ' + puts(v)987+ if (k == '__hit__') return b988+ return b + ', ' + k + ': ' + (v && v.__hit__ ? '<circular reference>' : puts(v))989 }).replace('{,', '{') + ' }'990 default: 991 return object.toString()992 }35 unmodified lines1028 * @api private1029 */1030 1031 does : function(actual, matcher, expected) {1027- var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, argumentsToArray(arguments, 2))1032+ var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, toArray(arguments, 2))1033 return assertion.run().result1034 },1035 1036 /**9 unmodified lines1046 */1047 1048 expect : function(actual) {1049 assert = function(matcher, args, negate) {1045- var expected = argumentsToArray(args, 1)1050+ var expected = toArray(args, 1)1051 matcher.negate = negate 1052 assertion = new JSpec.Assertion(matcher, actual, expected, negate)1053 hook('beforeAssertion', assertion)1054 if (matcher.defer) assertion.run()63 unmodified lines1118 1119 /**1120 * Iterate an object, invoking the given callback.1121 *1117- * @param {hash, array, string} object1122+ * @param {hash, array} object1123 * @param {function} callback1124 * @return {JSpec}1125 * @api public1126 */1127 1128 each : function(object, callback) {1129+ if (object.constructor == Array)1130+ for (var i = 0, len = object.length; i < len; ++i)1131+ callIterator(callback, i, object[i])1124- if (typeof object == 'string') object = object.split(' ')1125- for (key in object) 1126- if (object.hasOwnProperty(key))1127- callIterator(callback, key, object[key])1132+ else1133+ for (var key in object) 1134+ if (object.hasOwnProperty(key))1135+ callIterator(callback, key, object[key])1136 },1137 1138 /**1139 * Iterate with memo.193 unmodified lines1333 var matchers = this.matchers1334 var context = this.context || this.defaultContext1335 var contents = this.contentsOf(body)1336 hook('evaluatingBody', dsl, matchers, context, contents)1329- try { eval('with (dsl){ with (context) { with (matchers) { ' + contents + ' }}}') }1337+ try { with (dsl){ with (context) { with (matchers) { eval(contents) }}} }1338 catch(e) { error(errorMessage, e) }1339 },1340 1341 /**9 unmodified lines1351 input = hookImmutable('preprocessing', input)1352 return input.1353 replace(/\t/g, ' ').1354 replace(/\r\n|\n|\r/g, '\n').1347- replace(/__END__[^]*/, '').1355+ split('__END__')[0].1356 replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)').1357 replace(/describe\s+(.*?)$/gm, 'describe($1, function(){').1358 replace(/^\s+it\s+(.*?)$/gm, ' it($1, function(){').1359 replace(/^ *(before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){').28 unmodified lines1388 * @api public1389 */1390 1391 report : function() {1392+ this.duration = Number(new Date) - this.start1393 hook('reporting', JSpec.options)1385- new (JSpec.options.formatter || JSpec.formatters.DOM)(JSpec, JSpec.options)1394+ new (JSpec.options.reporter || JSpec.reporters.DOM)(JSpec, JSpec.options)1395 },1396 1397 /**1398 * Run the spec suites. Options are merged6 unmodified lines1405 1406 run : function(options) {1407 if (any(hook('running'), haveStopped)) return this1408 if (options) extend(this.options, options)1400- if (option('profile')) console.group('Profile')1409+ this.start = Number(new Date)1410 each(this.suites, function(suite) { JSpec.runSuite(suite) })1402- if (option('profile')) console.groupEnd()1411 return this1412 },1413 1414 /**54 unmodified lines1469 */1470 1471 runSpec : function(spec) {1472 this.currentSpec = spec1465- if (option('profile')) console.time(spec.description)1473 try { this.evalBody(spec.body) }1474 catch (e) { fail(e) }1468- if (option('profile')) console.timeEnd(spec.description)1475 spec.runDeferredAssertions()1476 destub()1477 this.stats.specsFinished++1478 this.stats.assertions += spec.assertions.length114 unmodified lines1593 * @api public1594 */1595 1596 tryLoading : function(file) {1591- try { return JSpec.load(file) }1592- catch (e) {}1597+ try { return JSpec.load(file) } catch (e) {}1598 },1599 1600 /**1601 * Load a _file_'s contents.40 unmodified lines1642 1643 var main = this1644 var find = JSpec.any1645 var utils = 'haveStopped stub hookImmutable hook destub map any last pass fail range each option inject select \1641- error escape extend puts hash query strip color does addMatchers callIterator argumentsToArray'.split(/\s+/)1642- while (utils.length) util = utils.shift(), eval('var ' + util + ' = JSpec.' + util)1646+ error escape extend puts query strip color does addMatchers callIterator toArray equal'.split(/\s+/)1647+ while (utils.length) eval('var ' + utils[0] + ' = JSpec.' + utils.shift())1648 if (!main.setTimeout) main.setTimeout = function(callback){ callback() }1649 1650 // --- Matchers1651 1652 addMatchers({1653 equal : "===",1654+ eql : "equal(actual, expected)",1655 be : "alias equal",1656 be_greater_than : ">",1657 be_less_than : "<",1658 be_at_least : ">=",10 unmodified lines1669 respond_to : "typeof actual[expected] == 'function'",1670 have_length : "actual.length == expected",1671 be_within : "actual >= expected[0] && actual <= last(expected)",1672 have_length_within : "actual.length >= expected[0] && actual.length <= last(expected)",1667-1668- eql : function(actual, expected) {1669- return actual.constructor == Array ||1670- actual instanceof Object ? 1671- hash(actual) == hash(expected):1672- actual == expected1673- },1673 1674 receive : { defer : true, match : function(actual, method, times) {1675 proxy = new JSpec.ProxyAssertion(actual, method, times, this.negate)1676 JSpec.currentSpec.assertions.push(proxy)22 unmodified lines1699 state = arg in actual1700 break1701 1702 case Array: 1704- state = any(actual, function(value){ return hash(value) == hash(arg) })1703+ state = any(actual, function(value){ return equal(value, arg) })1704 break1705 }1706 if (!state) return false1707 }5 unmodified lines1713 catch (e) {1714 this.e = e1715 var assert = function(arg) {1716 switch (arg.constructor) {1718- case RegExp : return arg.test(e)1717+ case RegExp : return arg.test(e.message || e.toString())1718 case String : return arg == (e.message || e.toString())1720- case Function : return (e.name || 'Error') == arg.name1719+ case Function : return e instanceof arg || e.name == arg.name1720 }1721 }1722 return message ? assert(expected) && assert(message) :1723 expected ? assert(expected) :45 unmodified lines1769 value === actual[property]1770 }1771 })1772 1774- if ('exports' in main) exports.JSpec = JSpec1775-1773 })()modified:spec/lib/jspec.shell.js+5 added-2 removed
13 unmodified lines14151617181819202122233 unmodified lines2728293031323033343536372 unmodified lines13 unmodified lines // --- Commands commands: { quit: ['Terminate the shell', function(){ _quit() }], exit: ['Terminate the shell', function(){ _quit() }] exit: ['Terminate the shell', function(){ _quit() }], p: ['Inspect an object', function(o){ return o.toSource() }] }, /** * Start the interactive shell.3 unmodified lines start : function() { for (var name in this.commands) if (this.commands.hasOwnProperty(name)) this.commands[name][1].length ? this.main[name] = this.commands[name][1] : this.main.__defineGetter__(name, this.commands[name][1]) this.main.__defineGetter__(name, this.commands[name][1]) } } Shell.start()2 unmodified linesmodified:spec/lib/jspec.timers.js+1 added-1 removed
1 2-// Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)2+// JSpec - Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 ;(function(){5 6 /**84 unmodified linesmodified:spec/lib/jspec.xhr.js+12 added-2 removed
6 unmodified lines7 8 var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ? 9 XMLHttpRequest :10 function(){}11+ var OriginalActiveXObject = 'ActiveXObject' in this ?12+ ActiveXObject :13+ undefined11-14+ 15 // --- MockXMLHttpRequest16 17 var MockXMLHttpRequest = function() {18 this.requestHeaders = {}49 unmodified lines68 * Send request _data_.69 */70 71 send : function(data) {72+ var self = this73 this.data = data74 this.readyState = 475 if (this.method == 'HEAD') this.responseText = null76 this.responseHeaders['content-length'] = (this.responseText || '').length77 if(this.async) this.onreadystatechange()78+ lastRequest = function(){79+ return self80+ }81 }82 }83 84 // --- Response status codes53 unmodified lines138 139 function mockRequest() {140 return { and_return : function(body, type, status, headers) {141 XMLHttpRequest = MockXMLHttpRequest142+ ActiveXObject = false143 status = status || 200144 headers = headers || {}145 headers['content-type'] = type146 JSpec.extend(XMLHttpRequest.prototype, {12 unmodified lines159 */160 161 function unmockRequest() {162 XMLHttpRequest = OriginalXMLHttpRequest163+ ActiveXObject = OriginalActiveXObject164 }165 166 JSpec.include({167 name: 'Mock XHR',15 unmodified lines183 184 DSLs : {185 snake : {186 mock_request: mockRequest,178- unmock_request: unmockRequest187+ unmock_request: unmockRequest,188+ last_request: function(){ return lastRequest() }189 }190 }191 192 })1 unmodified lineadded:spec/node.js+43 added
1+2+require.paths.unshift('spec', 'lib', 'spec/lib', 'spec/support/libxmljs')3+require("jspec")4+require("express")5+require("express/spec")6+7+quit = process.exit8+print = puts9+10+readFile = function(path) {11+ var promise = require('posix').cat(path, 'utf8')12+ var result = ''13+ promise.addErrback(function(){ throw "failed to read file `" + path + "'" })14+ promise.addCallback(function(contents){15+ result = contents16+ })17+ promise.wait()18+ return result19+}20+21+if (process.ARGV[2])22+ JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') 23+else24+ JSpec25+ .exec('spec/spec.core.js')26+ .exec('spec/spec.routing.js')27+ .exec('spec/spec.helpers.js')28+ .exec('spec/spec.request.js')29+ .exec('spec/spec.mime.js')30+ .exec('spec/spec.static.js')31+ .exec('spec/spec.collection.js')32+ .exec('spec/spec.element-collection.js')33+ .exec('spec/spec.plugins.js')34+ .exec('spec/spec.plugins.view.js')35+ .exec('spec/spec.plugins.common-logger.js')36+ .exec('spec/spec.plugins.content-length.js')37+ .exec('spec/spec.plugins.method-override.js')38+ .exec('spec/spec.plugins.body-decoder.js')39+ .exec('spec/spec.plugins.redirect.js')40+ .exec('spec/spec.plugins.hooks.js')41+ .exec('spec/spec.plugins.cookie.js')42+JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true })43+JSpec.report()deleted:spec/spec.node.js-43 removed
1-2-require.paths.unshift('spec', 'lib', 'spec/lib', 'spec/support/libxmljs')3-require("jspec")4-require("express")5-require("express/spec")6-7-quit = process.exit8-print = puts9-10-readFile = function(path) {11- var promise = require('posix').cat(path, "utf8")12- var result = ''13- promise.addErrback(function(){ throw "failed to read file `" + path + "'" })14- promise.addCallback(function(contents){15- result = contents16- })17- promise.wait()18- return result19-}20-21-if (process.ARGV[2])22- JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') 23-else24- JSpec25- .exec('spec/spec.core.js')26- .exec('spec/spec.routing.js')27- .exec('spec/spec.helpers.js')28- .exec('spec/spec.request.js')29- .exec('spec/spec.mime.js')30- .exec('spec/spec.static.js')31- .exec('spec/spec.collection.js')32- .exec('spec/spec.element-collection.js')33- .exec('spec/spec.plugins.js')34- .exec('spec/spec.plugins.view.js')35- .exec('spec/spec.plugins.common-logger.js')36- .exec('spec/spec.plugins.content-length.js')37- .exec('spec/spec.plugins.method-override.js')38- .exec('spec/spec.plugins.body-decoder.js')39- .exec('spec/spec.plugins.redirect.js')40- .exec('spec/spec.plugins.hooks.js')41- .exec('spec/spec.plugins.cookie.js')42-JSpec.run({ formatter: JSpec.formatters.Terminal, failuresOnly: true })43-JSpec.report()modified:Makefile+1 added-1 removed
1 2 NODE = node3 4 test: spec/support/libxmljs/libxmljs.node5- @$(NODE) spec/spec.node.js5+ @$(NODE) spec/node.js6 7 app:8 @$(NODE) examples/app.js9 7 unmodified linesmodified:Readme.md+3 added-3 removed
86 unmodified lines87 $ make test88 89 Run individual suites:90 91- $ node spec/spec.node.js core92- $ node spec/spec.node.js mime93- $ node spec/spec.node.js routing91+ $ node spec/node.js core92+ $ node spec/node.js mime93+ $ node spec/node.js routing94 ...95 96 Runnning libxmljs related specs, if you have an architecture issue97 then you will need to rebuild _spec/support/libxmljs.node_.39 unmodified lines