Skip to content

Instantly share code, notes, and snippets.

@dokipen
Created February 8, 2011 01:36
Show Gist options
  • Select an option

  • Save dokipen/815675 to your computer and use it in GitHub Desktop.

Select an option

Save dokipen/815675 to your computer and use it in GitHub Desktop.
var vows = require('vows')
, assert = require('assert')
, path = require('path')
, Syslog = require('node-syslog').Syslog
, Hash = require('traverse/hash')
Syslog.init("embedly-test", Syslog.LOG_PID | Syslog.LOG_ODELAY, Syslog.LOG_INFO)
require.paths.unshift(path.join(__dirname, '../lib'))
var embedly = require('embedly')
/**
* assert that a response obj arrays properties (names) match
* an array of expected values. name can be a period seperated
* hierarchy of properties. If the response object is known to
* be an array of length == 1, or we want to match the same expected
* value to each obj, then expected can be a string value.
*/
function assertObjValue(name, expected) {
return function(e, objs) {
var expect = expected;
var isString = typeof(expected) == 'string'
objs.forEach(function(obj,i) {
// if expected is a string, then the same expected
// value should be used against all objects
if (!isString) { expect = expected[i] }
// this traverses the object hierarchy with name
var value = name.split('.').reduce(function(o, field) {
return o[field]
}, obj)
assert.equal(value, expect)
})
}
}
var provider_url_vows = {}
;["| http://www.scribd.com/doc/13994900/Easter | http://www.scribd.com/ |"
, "| http://www.scribd.com/doc/28452730/Easter-Cards | http://www.scribd.com/ |"
, "| http://www.youtube.com/watch?v=Zk7dDekYej0 | http://www.youtube.com/ |"
, "| http://tweetphoto.com/14784358 | http://plixi.com |"
].forEach(function(line) {
var parts = line.split('|')
, url = parts[1].trim()
, expected = parts[2].trim()
provider_url_vows['when oembed is called with url '+url] = {
topic: function (api) {
return api.oembed(
{ params:{'url': url}
, complete: this.callback
}
)
}
, 'reponds with provider_url': assertObjValue('provider_url', expected)
}
})
vows.describe('OEmbed').addBatch({
'An API instance': Hash({
topic: new(embedly.api)
}).merge(provider_url_vows).end
}).export(module)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment