From 1778312e6c4fb1f66ff631f8d86e16edd9a46e6a Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Fri, 8 Nov 2013 10:28:48 -0700 Subject: [PATCH] Tests for Cylon#api --- dist/cylon.js | 3 +++ src/cylon.coffee | 2 +- test/dist/specs/cylon.spec.js | 22 +++++++++++++++++++++- test/src/specs/cylon.spec.coffee | 13 +++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/dist/cylon.js b/dist/cylon.js index 4ec63e2..2902c09 100644 --- a/dist/cylon.js +++ b/dist/cylon.js @@ -85,6 +85,9 @@ }; Master.prototype.api = function(opts) { + if (opts == null) { + opts = {}; + } api_config.host = opts.host || "127.0.0.1"; api_config.port = opts.port || "3000"; return api_config; diff --git a/src/cylon.coffee b/src/cylon.coffee index c7485ae..f390864 100644 --- a/src/cylon.coffee +++ b/src/cylon.coffee @@ -86,7 +86,7 @@ class Cylon # port - port API should listen for requests on # # Returns the API configuration - api: (opts) -> + api: (opts = {}) -> api_config.host = opts.host || "127.0.0.1" api_config.port = opts.port || "3000" api_config diff --git a/test/dist/specs/cylon.spec.js b/test/dist/specs/cylon.spec.js index a41c7c3..abddb54 100644 --- a/test/dist/specs/cylon.spec.js +++ b/test/dist/specs/cylon.spec.js @@ -6,7 +6,7 @@ Cylon = source("cylon"); describe("Cylon", function() { - return it("should create a robot", function() { + it("should create a robot", function() { var robot; assert(__indexOf.call(Object.keys(Cylon), 'robot') >= 0); robot = Cylon.robot({ @@ -14,6 +14,26 @@ }); return robot.name.should.be.eql('caprica six'); }); + return describe('#api', function() { + describe('without arguments', function() { + return it("returns the current API configuration", function() { + var api_config; + api_config = Cylon.api(); + assert(__indexOf.call(Object.keys(api_config), 'host') >= 0); + return assert(__indexOf.call(Object.keys(api_config), 'port') >= 0); + }); + }); + return describe('with a host and port', function() { + var api_config; + it('sets the API configuration to what was specified'); + api_config = Cylon.api({ + host: '0.0.0.0', + port: '8888' + }); + api_config.host.should.be.eql("0.0.0.0"); + return api_config.port.should.be.eql("8888"); + }); + }); }); }).call(this); diff --git a/test/src/specs/cylon.spec.coffee b/test/src/specs/cylon.spec.coffee index 6ba9c72..6c697be 100644 --- a/test/src/specs/cylon.spec.coffee +++ b/test/src/specs/cylon.spec.coffee @@ -7,3 +7,16 @@ describe "Cylon", -> assert 'robot' in Object.keys(Cylon) robot = Cylon.robot(name: 'caprica six') robot.name.should.be.eql 'caprica six' + + describe '#api', -> + describe 'without arguments', -> + it "returns the current API configuration", -> + api_config = Cylon.api() + assert 'host' in Object.keys(api_config) + assert 'port' in Object.keys(api_config) + + describe 'with a host and port', -> + it 'sets the API configuration to what was specified' + api_config = Cylon.api(host: '0.0.0.0', port: '8888') + api_config.host.should.be.eql "0.0.0.0" + api_config.port.should.be.eql "8888"