Skip to content

Instantly share code, notes, and snippets.

Avatar

Greg Bell dangerbell

View GitHub Profile
View request.sh
curl https://api.mover.io/connectors \
-H "Authorization: MoverAPI app_id=2tsc0f9n9l4v209oara0mb2j5ur9my8v app_secret=65oow347p1q7d0loj45oje2u3sol99xd" \
-X GET
@dangerbell
dangerbell / express-app.coffee
Created Nov 1, 2012
Example code for Node Testing with Mocha, SuperTest, and Nock
View express-app.coffee
express = require 'express'
app = express();
# Configure
require('./config')(app)
# Routes
require('./routes')(app)
module.exports = app
@dangerbell
dangerbell / mocha-supertest-nock.coffee
Created Nov 1, 2012
Mocha Example with SuperTest and Nock
View mocha-supertest-nock.coffee
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 Nov 1, 2012
Example of using SuperTest in Mocha
View mocha-supertest.coffee
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 Nov 1, 2012
Example Express server file
View express-server.coffee
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 Nov 1, 2012
Example Express app file
View express-app.coffee
express = require 'express'
app = express();
# Configure
require('./config')(app)
# Routes
require('./routes')(app)
module.exports = app
@dangerbell
dangerbell / express-router.coffee
Created Nov 1, 2012
Example Express router file
View express-router.coffee
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 Nov 1, 2012
Example Express config file
View express-config.coffee
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 Nov 1, 2012
Example of an async test in Mocha
View mocha-async-example.coffee
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()
View mocha-calculator-example.coffee
describe "Calculator", ->
describe "addition", ->
it "should add two numbers", ->
add(2, 2).should.equal 4