Last active
December 30, 2015 00:09
-
-
Save nicolaracco/7747356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app.coffee | |
require 'express' | |
class Server | |
constructor: -> | |
@app = express() | |
@server = http.createServer(@app) | |
@io = SocketIO.listen @server, logger: @logger | |
@configure_app() | |
start: => | |
@server.listen 3000 | |
process.send? status: 'started' # if send is defined, we are inside the fork | |
configure_app: => | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/requests/login_page_spec.coffee | |
TestServer = require '../helpers/test_server' | |
describe 'Login Page', -> | |
beforeAll (done) -> | |
@server = new TestServer done | |
... | |
afterAll (done) -> | |
@server.destroy done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/helpers/test_server.coffee | |
# | |
# This module is included in all the specs | |
fork = require('child_process').fork | |
class TestServer | |
childCmd: "app.coffee" | |
childSettings: | |
cwd : "#{__dirname}/../.." | |
execPath: "./node_modules/coffee-script/bin/coffee" | |
constructor: (done) -> | |
@child = fork @childCmd, [], @childSettings | |
@child.on 'message', (data) -> | |
done() if data.status is 'message' | |
destroy: (done) => | |
@child.on 'exit', -> done() | |
@child.kill 'SIGTERM' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment