Skip to content

Commit

Permalink
Bug fix in repository, test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mwawrusch committed Jan 9, 2012
1 parent 13f3b31 commit 22a2613
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 42 deletions.
3 changes: 2 additions & 1 deletion Cakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{spawn, exec} = require 'child_process'

task 'lib', 'Generate the library from the src', ->
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
coffee = spawn 'node_modules/.bin/coffee', ['-c', '-o', 'lib', 'src']
coffee.stdout.on 'data', (data) -> console.log data.toString().trim()

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"main": "./lib/octonode",
"scripts": {
"prepublish": "cake lib",
"test": "NODE_ENV=test node_modules/.bin/mocha -R spec $(find test -name '*.coffee')"
"test": "NODE_ENV=test node_modules/.bin/mocha -R spec $(find test -name '*.coffee')",
"watch" : "node_modules/.bin/coffee -c -w -o lib src"
},
"engines": { "node": ">0.4.11" },
"licenses": [
Expand Down
20 changes: 17 additions & 3 deletions src/octonode/repository.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@
class Repository

constructor: (@name, @client) ->

_invokeGet: (path,expectedStatus = 200,methodName,cb) ->
@client.get path, (err, s, b) ->
return cb(err) if err
if s isnt expectedStatus then cb(new Error("Repository.#{methodName} error")) else cb null, b

# Get a repository
# '/repos/pkumar/hub' GET
info: (cb) ->
@client.get "/repos/#{@name}", (err, s, b) ->
return cb(err) if err
if s isnt 200 then cb(new Error('Repository info error')) cb null, b
@_invokeGet "/repos/#{@name}",200,"info",cb

# Get the commits for a repository
# '/repos/pkumar/hub/commits' GET
getCommits: (cb) ->
@_invokeGet "/repos/#{@name}/commits",200,"getCommits",cb

# Get the tags for a repository
# '/repos/pkumar/hub/commits' GET
getTags: (cb) ->
@_invokeGet "/repos/#{@name}/tags",200,"getTags",cb


# Export module
module.exports = Repository
57 changes: 57 additions & 0 deletions test/repository.get.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

assert = require('assert')
should = require('should')
helper = require('./support/helper')
octonode = require('../lib/octonode')
_ = require('underscore')
#nock = require('./support/nock')
nock = require('nock')

sampleBody = {"has_issues":true,"forks":5,"has_downloads":true,"svn_url":"https://github.com/pksunkara/octonode"}

noParameterGet =
info:
url: "/repos/pksunkara/octonode"
getCommits:
url: "/repos/pksunkara/octonode/commits"
getTags:
url: "/repos/pksunkara/octonode/tags"



describe 'WHEN testing repository get methods', ->
beforeEach (done) ->
@timeout(10000)

nocker = nock("https://api.github.com")
for key in _.keys(noParameterGet)
test = noParameterGet[key]
nocker.get(test.url).reply(200, JSON.stringify(sampleBody))
#console.log "Mocking request for test #{key} for url #{test.url}"

helper.start null, done
after ( done) ->
helper.stop done

for key in _.keys(noParameterGet)
test = noParameterGet[key]

it "should invoke #{key} and return with a result", ( done) ->
@timeout(10000)


client = new octonode.client()
rep = client.repository('pksunkara/octonode')
should.exist rep
rep.should.have.property('name',"pksunkara/octonode")
rep.should.have.property('client')
should.exist rep[key]

rep[key] (err,data) ->
should.not.exist err
return done(err) if err

should.exist data
#console.log "DATA #{JSON.stringify(data)} ENDDATA"
done()

37 changes: 0 additions & 37 deletions test/repository.info.coffee

This file was deleted.

0 comments on commit 22a2613

Please sign in to comment.