Skip to content

Setting up Alfred with Teaspoon, Chai and SinonJS

Arjen Oosterkamp edited this page Apr 8, 2014 · 2 revisions

Please make sure you've setup Alfred using these instructions: https://github.com/jhnvz/alfred_rails/wiki/Setting-up-Alfred

This page describes setting up Alfred with Teaspoon, Chai and SinonJS. Alfred supports SinonJS serving a fake server with the recorded response. I assume you've set up Teaspoon.

Add Alfred to your Teaspoon environment

# spec_helper.coffee

//=require support/sinon
//=require support/chai
//=require support/sinon-chai

//=require alfred
//=require alfred/sinon_adapter
//=require_tree ./../javascripts/fixtures

should = chai.should()

Set up a test

# Example of a test
describe 'PostModel', ->

  describe '#update', ->

    it 'should update model', ->
      # This is the magic. It creates a fakeServer and sets the response
      @server = Alfred.SinonAdapter.serve('posts_controller/update', 'update post by manager')

      @post.update()
      @server.respond()

      @post.updated().should.equal(true)

Clone this wiki locally