From fef740533cbbd0e682fd06cfa9516ae9248dd155 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 18 Dec 2013 12:26:21 -0800 Subject: [PATCH] Add tests for Adaptor class --- test/dist/specs/adaptor.spec.js | 44 ++++++++++++++++++++++++++++-- test/src/specs/adaptor.spec.coffee | 35 ++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/test/dist/specs/adaptor.spec.js b/test/dist/specs/adaptor.spec.js index 38853cf..07c4c29 100644 --- a/test/dist/specs/adaptor.spec.js +++ b/test/dist/specs/adaptor.spec.js @@ -1,13 +1,51 @@ (function() { 'use strict'; + var EventEmitter; + source("adaptor"); + EventEmitter = require('events').EventEmitter; + describe("Adaptor", function() { - var adaptor; + var adaptor, conn; + conn = new EventEmitter; adaptor = new Cylon.Adaptor({ - name: 'adapt' + name: 'TestAdaptor', + connection: conn + }); + it("provides a 'connect' method that accepts a callback", function() { + var spy; + expect(adaptor.connect).to.be.a('function'); + spy = sinon.spy(); + adaptor.connect(function() { + return spy(); + }); + return spy.should.have.been.called; + }); + it("tells the connection to emit the 'connect' event when connected", function() { + var spy; + spy = sinon.spy(); + adaptor.connection.on('connect', function() { + return spy(); + }); + adaptor.connect(function() {}); + return spy.should.have.been.called; + }); + it("provides a 'disconnect' method", function() { + return expect(adaptor.disconnect).to.be.a('function'); + }); + it("provides a default empty array of commands", function() { + return expect(adaptor.commands()).to.be.eql([]); + }); + it("saves the provided name in the @name variable", function() { + return expect(adaptor.name).to.be.eql("TestAdaptor"); + }); + it("saves the provided connection in the @connection variable", function() { + return expect(adaptor.connection).to.be.eql(conn); + }); + return it("contains a reference to itself in the @self variable", function() { + return expect(adaptor.self).to.be.eql(adaptor); }); - return it('needs tests'); }); }).call(this); diff --git a/test/src/specs/adaptor.spec.coffee b/test/src/specs/adaptor.spec.coffee index 1760ade..3649575 100644 --- a/test/src/specs/adaptor.spec.coffee +++ b/test/src/specs/adaptor.spec.coffee @@ -1,8 +1,37 @@ -'use strict'; +'use strict' source "adaptor" +EventEmitter = require('events').EventEmitter describe "Adaptor", -> - adaptor = new Cylon.Adaptor(name: 'adapt') + conn = new EventEmitter + adaptor = new Cylon.Adaptor + name: 'TestAdaptor' + connection: conn - it 'needs tests' + it "provides a 'connect' method that accepts a callback", -> + expect(adaptor.connect).to.be.a 'function' + spy = sinon.spy() + adaptor.connect(-> spy()) + spy.should.have.been.called + + it "tells the connection to emit the 'connect' event when connected", -> + spy = sinon.spy() + adaptor.connection.on 'connect', -> spy() + adaptor.connect(->) + spy.should.have.been.called + + it "provides a 'disconnect' method", -> + expect(adaptor.disconnect).to.be.a 'function' + + it "provides a default empty array of commands", -> + expect(adaptor.commands()).to.be.eql [] + + it "saves the provided name in the @name variable", -> + expect(adaptor.name).to.be.eql "TestAdaptor" + + it "saves the provided connection in the @connection variable", -> + expect(adaptor.connection).to.be.eql conn + + it "contains a reference to itself in the @self variable", -> + expect(adaptor.self).to.be.eql adaptor