Skip to content

Instantly share code, notes, and snippets.

View dangerbell's full-sized avatar

Greg Bell dangerbell

  • Edmonton, Alberta
View GitHub Profile
curl https://api.mover.io/connectors \
-H "Authorization: MoverAPI app_id=2tsc0f9n9l4v209oara0mb2j5ur9my8v app_secret=65oow347p1q7d0loj45oje2u3sol99xd" \
-X GET
@dangerbell
dangerbell / express-app.coffee
Created November 1, 2012 20:16
Example code for Node Testing with Mocha, SuperTest, and Nock
express = require 'express'
app = express();
# Configure
require('./config')(app)
# Routes
require('./routes')(app)
module.exports = app
@dangerbell
dangerbell / mocha-supertest-nock.coffee
Created November 1, 2012 20:10
Mocha Example with SuperTest and Nock
request = require 'supertest'
scope = require 'nock'
app = require process.cwd() + '/app.coffee'
backend = require process.cwd() + 'lib/backend.coffee'
URL =
describe 'Collections', ->
describe 'show', ->
it "should return a 404 if the object doesn't exist", (done) ->
scope = nock(backend.url)
@dangerbell
dangerbell / mocha-supertest.coffee
Created November 1, 2012 20:07
Example of using SuperTest in Mocha
request = require 'supertest'
app = require process.cwd() + '/app.coffee'
describe 'Connectors', ->
describe 'create', ->
it "should return a 400 error if there is no type specified", (done) ->
request(app)
.post("/connectors")
.set( 'Authorization', "MoverApi app_id=embiggen app_secret=cromulent" )
.send( {} )
@dangerbell
dangerbell / express-server.coffee
Created November 1, 2012 20:05
Example Express server file
http = require 'http'
app = require './app'
http.createServer(app).listen app.get('port'), ->
console.log "Express server listening on port " + app.get('port')
@dangerbell
dangerbell / express-app.coffee
Created November 1, 2012 20:04
Example Express app file
express = require 'express'
app = express();
# Configure
require('./config')(app)
# Routes
require('./routes')(app)
module.exports = app
@dangerbell
dangerbell / express-router.coffee
Created November 1, 2012 20:01
Example Express router file
Example = require './controllers/example'
router = (app) ->
# Examples
app.get '/example/:id', Example.show
app.delete '/example/:id', Example.del
app.get '/example', Example.index
app.post '/example', Example.create
module.exports = router
@dangerbell
dangerbell / express-config.coffee
Created November 1, 2012 19:49
Example Express config file
express = require 'express'
config = (app) ->
# Configuration
app.set 'port', process.env.PORT || 3000
app.use express.favicon()
app.use express.methodOverride() # Allows the use of HTTP 'DELETE' AND 'PUT' methods.
app.use express.logger()
app.use app.router
app.use express.errorHandler()
@dangerbell
dangerbell / mocha-async-example.coffee
Created November 1, 2012 16:50
Example of an async test in Mocha
describe "Google", ->
describe "stuff", ->
it "should return success", (done) ->
options =
host: "www.google.com"
method: "GET"
google = http.request options, (res) ->
res.should.have.status 200
done()
google.end()
@dangerbell
dangerbell / mocha-calculator-example.coffee
Created November 1, 2012 16:43
Simple Mocha BDD example
describe "Calculator", ->
describe "addition", ->
it "should add two numbers", ->
add(2, 2).should.equal 4