From ee8eb83f78cf27fbba3840f031f7d0c3797ef211 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 7 Nov 2010 21:59:53 -0800 Subject: [PATCH] add vows --- Makefile | 7 ++++ vows/blob.js | 35 +++++++++++++++++ vows/branch.js | 37 ++++++++++++++++++ vows/commit.js | 28 ++++++++++++++ vows/helper.js | 39 +++++++++++++++++++ vows/raw.js | 20 ++++++++++ vows/repo.js | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ vows/tree.js | 53 ++++++++++++++++++++++++++ vows/user.js | 63 +++++++++++++++++++++++++++++++ 9 files changed, 382 insertions(+) create mode 100644 Makefile create mode 100644 vows/blob.js create mode 100644 vows/branch.js create mode 100644 vows/commit.js create mode 100644 vows/helper.js create mode 100644 vows/raw.js create mode 100644 vows/repo.js create mode 100644 vows/tree.js create mode 100644 vows/user.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b6cf86d --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +VOWS=vows/{blob,branch,commit,raw,repo,tree,user}.js + +spec: + vows --spec $(VOWS) + +test: + vows $(VOWS) diff --git a/vows/blob.js b/vows/blob.js new file mode 100644 index 0000000..bc56ac8 --- /dev/null +++ b/vows/blob.js @@ -0,0 +1,35 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + , TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc' + , Path = 'lib/index.js' + +vows.describe('Blob').addBatch({ + 'after fetching a blob': { + topic: function() { gh.blob(Proj, TreeSha, Path, this.callback) }, + 'the data object can be accessed with the data() method': function(err, blob) { + assert.ifError(err) + assert.ok(blob) + assert.instanceOf(blob.data(), Object) + }, + 'data is a blob': function(err, blob) { + assert.ifError(err) + assert.ok(h.looksLikeABlob(blob.data())) + }, + }, + 'after fetching commits for a blob': { + topic: function() { gh.blob(Proj, TreeSha, Path).getCommits(this.callback) }, + 'list of commits is available': function(err, commits) { + assert.ifError(err) + assert.ok(commits) + assert.instanceOf(commits, Array) + assert.equal(commits.length, 1) + assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) })) + } + }, +}).export(module) \ No newline at end of file diff --git a/vows/branch.js b/vows/branch.js new file mode 100644 index 0000000..4146390 --- /dev/null +++ b/vows/branch.js @@ -0,0 +1,37 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + , Branch = 'master' + +vows.describe('Branch').addBatch({ + 'after fetching a branch': { + topic: function() { gh.branch(Proj, Branch, this.callback) }, + 'the data object can be accessed with the data() method': function(err, branch) { + assert.ifError(err) + assert.ok(branch) + assert.instanceOf(branch.data(), Object) + }, + 'attributes can be accessed with the data() method': function(err, branch) { + assert.ifError(err) + assert.instanceOf(branch.data('author'), Object) + }, + 'expected fields are present': function(err, branch) { + assert.ifError(err) + assert.ok(h.looksLikeABranch(branch.data())) + }, + }, + 'after fetching commits': { + topic: function() { gh.commits(Proj, Branch, this.callback) }, + 'list of commits is available': function(err, commits) { + assert.ifError(err) + assert.ok(commits) + assert.instanceOf(commits, Array) + assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) })) + } + } +}).export(module) diff --git a/vows/commit.js b/vows/commit.js new file mode 100644 index 0000000..480ec17 --- /dev/null +++ b/vows/commit.js @@ -0,0 +1,28 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + , Sha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc' + +vows.describe('Commit').addBatch({ + 'after fetching a commit': { + topic: function() { gh.commit(Proj, Sha, this.callback) }, + 'the data object can be accessed with the data() method': function(err, commit) { + assert.ifError(err) + assert.ok(commit) + assert.instanceOf(commit.data(), Object) + }, + 'attributes can be accessed with the data() method': function(err, commit) { + assert.ifError(err) + assert.instanceOf(commit.data('author'), Object) + }, + 'expected fields are present': function(err, commit) { + assert.ifError(err) + assert.ok(h.looksLikeACommit(commit.data())) + }, + } +}).export(module) diff --git a/vows/helper.js b/vows/helper.js new file mode 100644 index 0000000..3fb7b6f --- /dev/null +++ b/vows/helper.js @@ -0,0 +1,39 @@ +module.exports = { looksLikeABlob: looksLikeABlob + , looksLikeABranch: looksLikeACommit + , looksLikeACommit: looksLikeACommit + , looksLikeAContributor: looksLikeAContributor + , looksLikeARepo: looksLikeARepo + , looksLikeASha: looksLikeASha + , looksLikeATree: looksLikeATree + , looksLikeAUser: looksLikeAUser + } + +var BlobKeys = ('mimeType mode name sha size').split(' ') + +var CommitKeys = ('author authoredDate committedDate committer id ' + + 'message parents tree url').split(' ') + +var ContributorKeys = ('blog contributions email location login name type').split(' ') + +var RepoKeys = ('createdAt fork forks hasDownloads hasIssues hasWiki ' + + 'name openIssues owner private pushedAt url watchers').split(' ') + +var UserKeys = ('blog company createdAt email followersCount ' + + 'followingCount id location login name ' + + 'publicRepoCount publicGistCount type').split(' ') + +function looksLikeABlob(obj) { return hasKeys(obj, BlobKeys) } +function looksLikeACommit(obj) { return hasKeys(obj, CommitKeys) } +function looksLikeAContributor(obj) { return hasKeys(obj, ContributorKeys) } +function looksLikeARepo(obj) { return hasKeys(obj, RepoKeys) } +function looksLikeASha(s) { return s && s.length === 40 } +function looksLikeATree(obj) { return obj && obj.every(function(b) { return looksLikeABlob(b) }) } +function looksLikeAUser(obj) { return hasKeys(obj, UserKeys) } + +function hasKeys(obj, keys) { + return (obj && typeof obj === 'object' && keys.every(function(k) { + if (!(k in obj)) + console.error( k + ' is not in ' + JSON.stringify(obj, null, 2)) + return k in obj + })) +} diff --git a/vows/raw.js b/vows/raw.js new file mode 100644 index 0000000..c7d5ddf --- /dev/null +++ b/vows/raw.js @@ -0,0 +1,20 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + , Sha = 'a0a2d307cfe7810ccae0aec2ec6854d079de6511' + +vows.describe('Raw').addBatch({ + 'after fetching a raw blob': { + topic: function() { gh.raw(Proj, Sha, this.callback) }, + 'the data object can be accessed with the data() method': function(err, raw) { + assert.ifError(err) + assert.ok(raw) + assert.equal(typeof raw.data(), 'string') + } + } +}).export(module) diff --git a/vows/repo.js b/vows/repo.js new file mode 100644 index 0000000..c586b78 --- /dev/null +++ b/vows/repo.js @@ -0,0 +1,100 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + +vows.describe('Repo').addBatch({ + 'after fetching a repo': { + topic: function() { gh.repo(Proj, this.callback) }, + 'the data object can be accessed with the data() method': function(err, repo) { + assert.ifError(err) + assert.ok(repo) + assert.instanceOf(repo.data(), Object) + }, + 'attributes can be accessed with the data() method': function(err, repo) { + assert.ifError(err) + assert.equal(repo.data('owner'), User) + }, + 'expected fields are present': function(err, repo) { + assert.ifError(err) + assert.ok(h.looksLikeARepo(repo.data())) + }, + }, + 'after fetching branches': { + topic: function() { gh.branches(Proj, this.callback) }, + 'map of branches is available': function(err, branches) { + assert.ifError(err) + assert.ok(branches) + assert.instanceOf(branches, Object) + assert.ok('master' in branches) + }, + 'names and commit ids of branches are available': function(err, branches) { + assert.ifError(err) + assert.ok(Object.keys(branches).every(function(b) { return h.looksLikeASha(branches[b]) })) + } + }, + 'after fetching collaborators': { + topic: function() { gh.collaborators(Proj, this.callback) }, + 'list of collaborators is available': function(err, collaborators) { + assert.ifError(err) + assert.ok(collaborators && collaborators.length >= 1) + assert.ok(collaborators.indexOf(User) !== -1) + }, + 'names of collaborators are available': function(err, collaborators) { + assert.ifError(err) + assert.ok(collaborators.every(function(c) { return c && c.length >= 1 })) + } + }, + 'after fetching contributors': { + topic: function() { gh.contributors(Proj, this.callback) }, + 'list of contributors is available': function(err, contributors) { + assert.ifError(err) + assert.ok(contributors && contributors.length >= 1) + }, + 'names of contributors are available': function(err, contributors) { + assert.ifError(err) + assert.ok(contributors.every(function(c) { return h.looksLikeAContributor(c) })) + } + }, + 'after fetching languages': { + topic: function() { gh.languages(Proj, this.callback) }, + 'map of languages is available': function(err, languages) { + assert.ifError(err) + assert.ok(languages) + assert.instanceOf(languages, Object) + assert.ok('JavaScript' in languages) + } + }, + 'after fetching network': { + topic: function() { gh.network(Proj, this.callback) }, + 'map of network is available': function(err, network) { + assert.ifError(err) + assert.ok(network && network.length >= 1) + assert.ok(network.every(function(r) { return h.looksLikeARepo(r) })) + } + }, + 'after fetching tags': { + topic: function() { gh.tags(Proj, this.callback) }, + 'map of tags is available': function(err, tags) { + assert.ifError(err) + assert.ok(tags) + assert.instanceOf(tags, Object) + } + }, + 'after fetching watchers': { + topic: function() { gh.watchers(Proj, this.callback) }, + 'list of watchers is available': function(err, watchers) { + assert.ifError(err) + assert.ok(watchers && watchers.length >= 1) + assert.ok(watchers.indexOf(User) !== -1) + }, + 'names of watchers are available': function(err, watchers) { + assert.ifError(err) + assert.ok(watchers.every(function(w) { return w && w.length >= 1 })) + } + } +}).export(module) diff --git a/vows/tree.js b/vows/tree.js new file mode 100644 index 0000000..a8de6ff --- /dev/null +++ b/vows/tree.js @@ -0,0 +1,53 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + , Repo = 'gitter' + , Proj = User + '/' + Repo + , TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc' + +vows.describe('Tree').addBatch({ + 'after fetching a tree': { + topic: function() { gh.tree(Proj, TreeSha, this.callback) }, + 'the data object can be accessed with the data() method': function(err, tree) { + assert.ifError(err) + assert.ok(tree) + assert.instanceOf(tree.data(), Array) + }, + 'data is a git tree': function(err, tree) { + assert.ifError(err) + assert.ok(h.looksLikeATree(tree.blobs)) + }, + }, + 'after fetching blobs': { + topic: function() { gh.blobs(Proj, TreeSha, this.callback) }, + 'list of blobs is available': function(err, blobs) { + assert.ifError(err) + assert.ok(blobs) + assert.instanceOf(blobs, Object) + assert.ok(Object.keys(blobs).length > 1) + assert.ok('package.json' in blobs) + assert.ok(Object.keys(blobs).every(function(k) { return h.looksLikeASha(blobs[k]) })) + } + }, + 'after fetching full blobs': { + topic: function() { gh.tree(Proj, TreeSha).getFullBlobs(this.callback) }, + 'full blobs are available': function(err, blobs) { + assert.ifError(err) + assert.ok(blobs) + assert.instanceOf(blobs, Array) + assert.ok(blobs.every(function(b) { return h.looksLikeABlob(b) })) + } + }, + 'after fetching the full tree': { + topic: function() { gh.tree(Proj, TreeSha).getFullTree(this.callback) }, + 'full contents of tree are available': function(err, tree) { + assert.ifError(err) + assert.ok(tree) + assert.instanceOf(tree, Array) + assert.ok(tree.every(function(b) { return h.looksLikeABlob(b) })) + } + } +}).export(module) diff --git a/vows/user.js b/vows/user.js new file mode 100644 index 0000000..f94db7e --- /dev/null +++ b/vows/user.js @@ -0,0 +1,63 @@ +var gh = require('../lib') + , vows = require('vows') + , assert = require('assert') + , h = require('./helper') + + , User = 'samsonjs' + +vows.describe('User').addBatch({ + 'after fetching a user': { + topic: function() { gh.user(User, this.callback) }, + 'the data object can be accessed with the data() method': function(err, user) { + assert.ifError(err) + assert.ok(user) + assert.instanceOf(user.data(), Object) + }, + 'attributes can be accessed with the data() method': function(err, user) { + assert.ifError(err) + assert.equal(user.data('login'), User) + }, + 'expected fields are present': function(err, user) { + assert.ifError(err) + assert.ok(h.looksLikeAUser(user.data())) + }, + }, + 'after fetching their followers': { + topic: function() { gh.followers(User, this.callback) }, + 'list of followers is available': function(err, followers) { + assert.ifError(err) + assert.ok(followers && followers.length > 1) + }, + 'usernames of followers are available': function(err, followers) { + assert.ifError(err) + assert.ok(followers.every(function(f) { return f && f.length > 1 })) + } + }, + 'after fetching users they follow': { + topic: function() { gh.following(User, this.callback) }, + 'list of following users is available': function(err, following) { + assert.ifError(err) + assert.ok(following && following.length > 1) + }, + 'names of following users are available': function(err, following) { + assert.ifError(err) + assert.ok(following.every(function(f) { return f && f.length > 1 })) + } + }, + 'after fetching their public repos': { + topic: function() { gh.repos(User, this.callback) }, + 'list of public repos is available': function(err, repos) { + assert.ifError(err) + assert.ok(repos.length > 1) + assert.ok(repos.every(function(r) { return h.looksLikeARepo(r) })) + } + }, + 'after fetching their watched repos': { + topic: function() { gh.watched(User, this.callback) }, + 'list of watched repos is available': function(err, repos) { + assert.ifError(err) + assert.ok(repos.length > 1) + assert.ok(repos.every(function(r) { return h.looksLikeARepo(r) })) + } + } +}).export(module)