Bootstrapping up tests on Vows (DEPENDS ON NPM)
This commit is contained in:
parent
d53cb01282
commit
cd23affb23
12
Makefile
12
Makefile
|
@ -1,9 +1,7 @@
|
||||||
|
#
|
||||||
NODE = node
|
# Run all tests
|
||||||
|
#
|
||||||
all: test
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@$(NODE) spec/node.js all
|
vows tests/* --spec
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test install
|
Binary file not shown.
Before Width: | Height: | Size: 154 B |
Binary file not shown.
Before Width: | Height: | Size: 321 B |
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 145 B |
|
@ -1,149 +0,0 @@
|
||||||
body.jspec {
|
|
||||||
margin: 45px 0;
|
|
||||||
font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
|
||||||
background: #efefef url(images/bg.png) top left repeat-x;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
#jspec {
|
|
||||||
margin: 0 auto;
|
|
||||||
padding-top: 30px;
|
|
||||||
width: 1008px;
|
|
||||||
background: url(images/vr.png) top left repeat-y;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
#jspec-top {
|
|
||||||
position: relative;
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 1008px;
|
|
||||||
height: 40px;
|
|
||||||
background: url(images/sprites.bg.png) top left no-repeat;
|
|
||||||
}
|
|
||||||
#jspec-bottom {
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 1008px;
|
|
||||||
height: 15px;
|
|
||||||
background: url(images/sprites.bg.png) bottom left no-repeat;
|
|
||||||
}
|
|
||||||
#jspec .loading {
|
|
||||||
margin-top: -45px;
|
|
||||||
width: 1008px;
|
|
||||||
height: 80px;
|
|
||||||
background: url(images/loading.gif) 50% 50% no-repeat;
|
|
||||||
}
|
|
||||||
#jspec-title {
|
|
||||||
position: absolute;
|
|
||||||
top: 15px;
|
|
||||||
left: 20px;
|
|
||||||
width: 160px;
|
|
||||||
font-size: 22px;
|
|
||||||
font-weight: normal;
|
|
||||||
background: url(images/sprites.png) 0 -126px no-repeat;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
#jspec-title em {
|
|
||||||
font-size: 10px;
|
|
||||||
font-style: normal;
|
|
||||||
color: #BCC8D1;
|
|
||||||
}
|
|
||||||
#jspec-report * {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
#jspec-report {
|
|
||||||
padding: 15px 40px;
|
|
||||||
font: 11px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
|
||||||
color: #7B8D9B;
|
|
||||||
}
|
|
||||||
#jspec-report.has-failures {
|
|
||||||
padding-bottom: 30px;
|
|
||||||
}
|
|
||||||
#jspec-report .hidden {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#jspec-report .heading {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
}
|
|
||||||
#jspec-report .heading span {
|
|
||||||
padding-right: 10px;
|
|
||||||
}
|
|
||||||
#jspec-report .heading .passes em {
|
|
||||||
color: #0ea0eb;
|
|
||||||
}
|
|
||||||
#jspec-report .heading .failures em {
|
|
||||||
color: #FA1616;
|
|
||||||
}
|
|
||||||
#jspec-report table {
|
|
||||||
font-size: 11px;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
#jspec-report td {
|
|
||||||
padding: 8px;
|
|
||||||
text-indent: 30px;
|
|
||||||
color: #7B8D9B;
|
|
||||||
}
|
|
||||||
#jspec-report tr.body {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#jspec-report tr.body pre {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0 0 5px 25px;
|
|
||||||
}
|
|
||||||
#jspec-report tr.even:hover + tr.body,
|
|
||||||
#jspec-report tr.odd:hover + tr.body {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
#jspec-report tr td:first-child em {
|
|
||||||
display: block;
|
|
||||||
clear: both;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: normal;
|
|
||||||
color: #7B8D9B;
|
|
||||||
}
|
|
||||||
#jspec-report tr.even:hover,
|
|
||||||
#jspec-report tr.odd:hover {
|
|
||||||
text-shadow: 1px 1px 1px #fff;
|
|
||||||
background: #F2F5F7;
|
|
||||||
}
|
|
||||||
#jspec-report td + td {
|
|
||||||
padding-right: 0;
|
|
||||||
width: 15px;
|
|
||||||
}
|
|
||||||
#jspec-report td.pass {
|
|
||||||
background: url(images/sprites.png) 3px -7px no-repeat;
|
|
||||||
}
|
|
||||||
#jspec-report td.fail {
|
|
||||||
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 -333px no-repeat;
|
|
||||||
}
|
|
||||||
#jspec-report tr.description td {
|
|
||||||
margin-top: 25px;
|
|
||||||
padding-top: 25px;
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: bold;
|
|
||||||
text-indent: 0;
|
|
||||||
color: #1a1a1a;
|
|
||||||
}
|
|
||||||
#jspec-report tr.description:first-child td {
|
|
||||||
border-top: none;
|
|
||||||
}
|
|
||||||
#jspec-report .assertion {
|
|
||||||
display: block;
|
|
||||||
float: left;
|
|
||||||
margin: 0 0 0 1px;
|
|
||||||
padding: 0;
|
|
||||||
width: 1px;
|
|
||||||
height: 5px;
|
|
||||||
background: #7B8D9B;
|
|
||||||
}
|
|
||||||
#jspec-report .assertion.failed {
|
|
||||||
background: red;
|
|
||||||
}
|
|
||||||
.jspec-sandbox {
|
|
||||||
display: none;
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
|
|
||||||
// JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
||||||
|
|
||||||
;(function(){
|
|
||||||
|
|
||||||
Growl = {
|
|
||||||
|
|
||||||
// --- Version
|
|
||||||
|
|
||||||
version: '1.0.0',
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the given _cmd_, returning an array of lines from stdout.
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* Growl.exec('growlnotify', '-m', msg)
|
|
||||||
*
|
|
||||||
* @param {string ...} cmd
|
|
||||||
* @return {array}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
exec: function(cmd) {
|
|
||||||
var lines = [], line
|
|
||||||
with (JavaImporter(java.lang, java.io)) {
|
|
||||||
var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
|
|
||||||
var stream = new DataInputStream(proccess.getInputStream())
|
|
||||||
while (line = stream.readLine())
|
|
||||||
lines.push(line + '')
|
|
||||||
stream.close()
|
|
||||||
}
|
|
||||||
return lines
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the extension of the given _path_ or null.
|
|
||||||
*
|
|
||||||
* @param {string} path
|
|
||||||
* @return {string}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
extname: function(path) {
|
|
||||||
return path.lastIndexOf('.') != -1 ?
|
|
||||||
path.slice(path.lastIndexOf('.') + 1, path.length) :
|
|
||||||
null
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Version of the 'growlnotify' binary.
|
|
||||||
*
|
|
||||||
* @return {string}
|
|
||||||
* @api private
|
|
||||||
*/
|
|
||||||
|
|
||||||
binVersion: function() {
|
|
||||||
try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send growl notification _msg_ with _options_.
|
|
||||||
*
|
|
||||||
* Options:
|
|
||||||
*
|
|
||||||
* - title Notification title
|
|
||||||
* - sticky Make the notification stick (defaults to false)
|
|
||||||
* - name Application name (defaults to growlnotify)
|
|
||||||
* - image
|
|
||||||
* - path to an icon sets --iconpath
|
|
||||||
* - path to an image sets --image
|
|
||||||
* - capitalized word sets --appIcon
|
|
||||||
* - filename uses extname as --icon
|
|
||||||
* - otherwise treated as --icon
|
|
||||||
*
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* Growl.notify('New email')
|
|
||||||
* Growl.notify('5 new emails', { title: 'Thunderbird' })
|
|
||||||
*
|
|
||||||
* @param {string} msg
|
|
||||||
* @param {options} hash
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
notify: function(msg, options) {
|
|
||||||
options = options || {}
|
|
||||||
var args = ['growlnotify', '-m', msg]
|
|
||||||
if (!this.binVersion()) throw new Error('growlnotify executable is required')
|
|
||||||
if (image = options.image) {
|
|
||||||
var flag, ext = this.extname(image)
|
|
||||||
flag = flag || ext == 'icns' && 'iconpath'
|
|
||||||
flag = flag || /^[A-Z]/.test(image) && 'appIcon'
|
|
||||||
flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
|
|
||||||
flag = flag || ext && (image = ext) && 'icon'
|
|
||||||
flag = flag || 'icon'
|
|
||||||
args.push('--' + flag, image)
|
|
||||||
}
|
|
||||||
if (options.sticky) args.push('--sticky')
|
|
||||||
if (options.name) args.push('--name', options.name)
|
|
||||||
if (options.title) args.push(options.title)
|
|
||||||
this.exec.apply(this, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JSpec.include({
|
|
||||||
name: 'Growl',
|
|
||||||
reporting: function(options){
|
|
||||||
var stats = JSpec.stats
|
|
||||||
if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})
|
|
||||||
else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
})()
|
|
|
@ -1,71 +0,0 @@
|
||||||
|
|
||||||
// JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
||||||
|
|
||||||
JSpec
|
|
||||||
.requires('jQuery', 'when using jspec.jquery.js')
|
|
||||||
.include({
|
|
||||||
name: 'jQuery',
|
|
||||||
|
|
||||||
// --- Initialize
|
|
||||||
|
|
||||||
init : function() {
|
|
||||||
jQuery.ajaxSetup({ async: false })
|
|
||||||
},
|
|
||||||
|
|
||||||
// --- Utilities
|
|
||||||
|
|
||||||
utilities : {
|
|
||||||
element: jQuery,
|
|
||||||
elements: jQuery,
|
|
||||||
sandbox : function() {
|
|
||||||
return jQuery('<div class="sandbox"></div>')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// --- Matchers
|
|
||||||
|
|
||||||
matchers : {
|
|
||||||
have_tag : "jQuery(expected, actual).length == 1",
|
|
||||||
have_one : "alias have_tag",
|
|
||||||
have_tags : "jQuery(expected, actual).length > 1",
|
|
||||||
have_many : "alias have_tags",
|
|
||||||
have_child : "jQuery(actual).children(expected).length == 1",
|
|
||||||
have_children : "jQuery(actual).children(expected).length > 1",
|
|
||||||
have_text : "jQuery(actual).text() == expected",
|
|
||||||
have_value : "jQuery(actual).val() == expected",
|
|
||||||
be_enabled : "!jQuery(actual).attr('disabled')",
|
|
||||||
have_class : "jQuery(actual).hasClass(expected)",
|
|
||||||
|
|
||||||
be_visible : function(actual) {
|
|
||||||
return jQuery(actual).css('display') != 'none' &&
|
|
||||||
jQuery(actual).css('visibility') != 'hidden' &&
|
|
||||||
jQuery(actual).attr('type') != 'hidden'
|
|
||||||
},
|
|
||||||
|
|
||||||
be_hidden : function(actual) {
|
|
||||||
return !JSpec.does(actual, 'be_visible')
|
|
||||||
},
|
|
||||||
|
|
||||||
have_classes : function(actual) {
|
|
||||||
return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
|
|
||||||
return !JSpec.does(actual, 'have_class', arg)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
have_attr : function(actual, attr, value) {
|
|
||||||
return value ? jQuery(actual).attr(attr) == value:
|
|
||||||
jQuery(actual).attr(attr)
|
|
||||||
},
|
|
||||||
|
|
||||||
'be disabled selected checked' : function(attr) {
|
|
||||||
return 'jQuery(actual).attr("' + attr + '")'
|
|
||||||
},
|
|
||||||
|
|
||||||
'have type id title alt href src sel rev name target' : function(attr) {
|
|
||||||
return function(actual, value) {
|
|
||||||
return JSpec.does(actual, 'have_attr', attr, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
1775
spec/lib/jspec.js
1775
spec/lib/jspec.js
File diff suppressed because it is too large
Load Diff
|
@ -1,39 +0,0 @@
|
||||||
|
|
||||||
// JSpec - Shell - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
||||||
|
|
||||||
;(function(){
|
|
||||||
|
|
||||||
var _quit = quit
|
|
||||||
|
|
||||||
Shell = {
|
|
||||||
|
|
||||||
// --- Global
|
|
||||||
|
|
||||||
main: this,
|
|
||||||
|
|
||||||
// --- Commands
|
|
||||||
|
|
||||||
commands: {
|
|
||||||
quit: ['Terminate the shell', function(){ _quit() }],
|
|
||||||
exit: ['Terminate the shell', function(){ _quit() }],
|
|
||||||
p: ['Inspect an object', function(o){ return o.toSource() }]
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the interactive shell.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Shell.start()
|
|
||||||
|
|
||||||
})()
|
|
|
@ -1,90 +0,0 @@
|
||||||
|
|
||||||
// JSpec - Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
||||||
|
|
||||||
;(function(){
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Version.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mockTimersVersion = '1.0.2'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Localized timer stack.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var timers = []
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroy timer with _id_.
|
|
||||||
*
|
|
||||||
* @param {int} id
|
|
||||||
* @return {bool}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
clearInterval = clearTimeout = function(id) {
|
|
||||||
return delete timers[--id]
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset timers.
|
|
||||||
*
|
|
||||||
* @return {array}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
resetTimers = function() {
|
|
||||||
return timers = []
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increment each timers internal clock by _ms_.
|
|
||||||
*
|
|
||||||
* @param {int} ms
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
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]()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})()
|
|
|
@ -1,193 +0,0 @@
|
||||||
|
|
||||||
// JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
||||||
|
|
||||||
(function(){
|
|
||||||
|
|
||||||
// --- Original XMLHttpRequest
|
|
||||||
|
|
||||||
var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
|
|
||||||
XMLHttpRequest :
|
|
||||||
function(){}
|
|
||||||
var OriginalActiveXObject = 'ActiveXObject' in this ?
|
|
||||||
ActiveXObject :
|
|
||||||
undefined
|
|
||||||
|
|
||||||
// --- MockXMLHttpRequest
|
|
||||||
|
|
||||||
var MockXMLHttpRequest = function() {
|
|
||||||
this.requestHeaders = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
MockXMLHttpRequest.prototype = {
|
|
||||||
status: 0,
|
|
||||||
async: true,
|
|
||||||
readyState: 0,
|
|
||||||
responseText: '',
|
|
||||||
abort: function(){},
|
|
||||||
onreadystatechange: function(){},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return response headers hash.
|
|
||||||
*/
|
|
||||||
|
|
||||||
getAllResponseHeaders : function(){
|
|
||||||
return this.responseHeaders
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return case-insensitive value for header _name_.
|
|
||||||
*/
|
|
||||||
|
|
||||||
getResponseHeader : function(name) {
|
|
||||||
return this.responseHeaders[name.toLowerCase()]
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set case-insensitive _value_ for header _name_.
|
|
||||||
*/
|
|
||||||
|
|
||||||
setRequestHeader : function(name, value) {
|
|
||||||
this.requestHeaders[name.toLowerCase()] = value
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open mock request.
|
|
||||||
*/
|
|
||||||
|
|
||||||
open : function(method, url, async, user, password) {
|
|
||||||
this.user = user
|
|
||||||
this.password = password
|
|
||||||
this.url = url
|
|
||||||
this.readyState = 1
|
|
||||||
this.method = method.toUpperCase()
|
|
||||||
if (async != undefined) this.async = async
|
|
||||||
if (this.async) this.onreadystatechange()
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send request _data_.
|
|
||||||
*/
|
|
||||||
|
|
||||||
send : function(data) {
|
|
||||||
var self = this
|
|
||||||
this.data = data
|
|
||||||
this.readyState = 4
|
|
||||||
if (this.method == 'HEAD') this.responseText = null
|
|
||||||
this.responseHeaders['content-length'] = (this.responseText || '').length
|
|
||||||
if(this.async) this.onreadystatechange()
|
|
||||||
lastRequest = function(){
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Response status codes
|
|
||||||
|
|
||||||
JSpec.statusCodes = {
|
|
||||||
100: 'Continue',
|
|
||||||
101: 'Switching Protocols',
|
|
||||||
200: 'OK',
|
|
||||||
201: 'Created',
|
|
||||||
202: 'Accepted',
|
|
||||||
203: 'Non-Authoritative Information',
|
|
||||||
204: 'No Content',
|
|
||||||
205: 'Reset Content',
|
|
||||||
206: 'Partial Content',
|
|
||||||
300: 'Multiple Choice',
|
|
||||||
301: 'Moved Permanently',
|
|
||||||
302: 'Found',
|
|
||||||
303: 'See Other',
|
|
||||||
304: 'Not Modified',
|
|
||||||
305: 'Use Proxy',
|
|
||||||
307: 'Temporary Redirect',
|
|
||||||
400: 'Bad Request',
|
|
||||||
401: 'Unauthorized',
|
|
||||||
402: 'Payment Required',
|
|
||||||
403: 'Forbidden',
|
|
||||||
404: 'Not Found',
|
|
||||||
405: 'Method Not Allowed',
|
|
||||||
406: 'Not Acceptable',
|
|
||||||
407: 'Proxy Authentication Required',
|
|
||||||
408: 'Request Timeout',
|
|
||||||
409: 'Conflict',
|
|
||||||
410: 'Gone',
|
|
||||||
411: 'Length Required',
|
|
||||||
412: 'Precondition Failed',
|
|
||||||
413: 'Request Entity Too Large',
|
|
||||||
414: 'Request-URI Too Long',
|
|
||||||
415: 'Unsupported Media Type',
|
|
||||||
416: 'Requested Range Not Satisfiable',
|
|
||||||
417: 'Expectation Failed',
|
|
||||||
422: 'Unprocessable Entity',
|
|
||||||
500: 'Internal Server Error',
|
|
||||||
501: 'Not Implemented',
|
|
||||||
502: 'Bad Gateway',
|
|
||||||
503: 'Service Unavailable',
|
|
||||||
504: 'Gateway Timeout',
|
|
||||||
505: 'HTTP Version Not Supported'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock XMLHttpRequest requests.
|
|
||||||
*
|
|
||||||
* mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' })
|
|
||||||
*
|
|
||||||
* @return {hash}
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function mockRequest() {
|
|
||||||
return { and_return : function(body, type, status, headers) {
|
|
||||||
XMLHttpRequest = MockXMLHttpRequest
|
|
||||||
ActiveXObject = false
|
|
||||||
status = status || 200
|
|
||||||
headers = headers || {}
|
|
||||||
headers['content-type'] = type
|
|
||||||
JSpec.extend(XMLHttpRequest.prototype, {
|
|
||||||
responseText: body,
|
|
||||||
responseHeaders: headers,
|
|
||||||
status: status,
|
|
||||||
statusText: JSpec.statusCodes[status]
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unmock XMLHttpRequest requests.
|
|
||||||
*
|
|
||||||
* @api public
|
|
||||||
*/
|
|
||||||
|
|
||||||
function unmockRequest() {
|
|
||||||
XMLHttpRequest = OriginalXMLHttpRequest
|
|
||||||
ActiveXObject = OriginalActiveXObject
|
|
||||||
}
|
|
||||||
|
|
||||||
JSpec.include({
|
|
||||||
name: 'Mock XHR',
|
|
||||||
|
|
||||||
// --- Utilities
|
|
||||||
|
|
||||||
utilities : {
|
|
||||||
mockRequest: mockRequest,
|
|
||||||
unmockRequest: unmockRequest
|
|
||||||
},
|
|
||||||
|
|
||||||
// --- Hooks
|
|
||||||
|
|
||||||
afterSpec : function() {
|
|
||||||
unmockRequest()
|
|
||||||
},
|
|
||||||
|
|
||||||
// --- DSLs
|
|
||||||
|
|
||||||
DSLs : {
|
|
||||||
snake : {
|
|
||||||
mock_request: mockRequest,
|
|
||||||
unmock_request: unmockRequest,
|
|
||||||
last_request: function(){ return lastRequest() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
})()
|
|
29
spec/node.js
29
spec/node.js
|
@ -1,29 +0,0 @@
|
||||||
require.paths.unshift('spec', 'lib', 'spec/lib')
|
|
||||||
require("jspec")
|
|
||||||
|
|
||||||
print = require('sys').puts
|
|
||||||
quit = process.exit
|
|
||||||
readFile = require('fs').readFileSync
|
|
||||||
|
|
||||||
function run(specs) {
|
|
||||||
specs.forEach(function(spec){
|
|
||||||
JSpec.exec('spec/spec.' + spec + '.js')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
specs = {
|
|
||||||
independant: [
|
|
||||||
'oauth',
|
|
||||||
'sha1'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (process.ARGV[2]) {
|
|
||||||
case 'all':
|
|
||||||
run(specs.independant)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
run([process.ARGV[2]])
|
|
||||||
}
|
|
||||||
|
|
||||||
JSpec.run({ reporter: JSpec.reporters.Terminal, failuresOnly: true }).report()
|
|
|
@ -1,15 +0,0 @@
|
||||||
describe 'node-oauth'
|
|
||||||
before_each
|
|
||||||
end
|
|
||||||
describe 'SHA1'
|
|
||||||
describe 'HMAC-SHA1'
|
|
||||||
it 'should produce the specified digest as described in http://oauth.net/core/1.0/#sig_base_example (A.5.2)'
|
|
||||||
var SHA1= require('sha1');
|
|
||||||
var hash= SHA1.HMACSHA1( "kd94hf93k423kf44&pfkkdhi9sl3r4s00",
|
|
||||||
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal")
|
|
||||||
|
|
||||||
hash.should.eql ("tR3+Ty81lMeYAr/Fid0kMTYa/WM=")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,4 +1,4 @@
|
||||||
describe 'node-oauth'
|
/*describe 'node-oauth'
|
||||||
before_each
|
before_each
|
||||||
OAuth= require('oauth').OAuth
|
OAuth= require('oauth').OAuth
|
||||||
end
|
end
|
||||||
|
@ -96,4 +96,4 @@ describe 'node-oauth'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end*/
|
|
@ -0,0 +1,13 @@
|
||||||
|
var vows = require('vows'),
|
||||||
|
assert = require('assert');
|
||||||
|
|
||||||
|
vows.describe('node-oauth').addBatch({
|
||||||
|
'SHA1': {
|
||||||
|
topic: require('../lib/sha1'),
|
||||||
|
'should produce the specified digest as described in http://oauth.net/core/1.0/#sig_base_example (A.5.2)': function (sha1) {
|
||||||
|
assert.equal (sha1.HMACSHA1( "kd94hf93k423kf44&pfkkdhi9sl3r4s00",
|
||||||
|
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"),
|
||||||
|
"tR3+Ty81lMeYAr/Fid0kMTYa/WM=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).export(module);
|
Loading…
Reference in New Issue