From e336e4984f35c1033e9e1725fbf6e02b81f91bb3 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 19 Nov 2013 23:04:36 -0600 Subject: [PATCH] codename tests working --- src/spec/code-name-generator.spec.js | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/spec/code-name-generator.spec.js diff --git a/src/spec/code-name-generator.spec.js b/src/spec/code-name-generator.spec.js new file mode 100644 index 0000000..0d88a33 --- /dev/null +++ b/src/spec/code-name-generator.spec.js @@ -0,0 +1,45 @@ +/** + * Created by mattjohansen on 11/19/13. + */ + +var codename = require('../scripts/code-name-generator.coffee'); +var HttpClient = require('scoped-http-client'); + +describe('codename', function() { + var robot, msg = null; + + beforeEach(function(){ + robot = { + respond: function(regex, callback){}, + http: function(url){} + } + spyOn(robot, 'respond').andCallThrough(); + spyOn(robot, 'http').andCallFake(function(){ + var url = robot.http.mostRecentCall.args[0]; + var client = HttpClient.create(url); + spyOn(client, 'get').andReturn(function(){}); + return client + }); + codename(robot); + msg = { + match: 'codename'.match(robot.respond.mostRecentCall.args[0]), + send: function() {} + } + }); + + it('should be a function', function(){ + expect(typeof(codename)).toBe('function'); + }); + + it('should generate the correct URL', function() { + expect(robot.respond).toHaveBeenCalled(); + robot.respond.mostRecentCall.args[1](msg); + expect(robot.http).toHaveBeenCalled(); + expect(robot.http.mostRecentCall.args[0]).toBeDefined(); + expect(robot.http.mostRecentCall.args[0]).toBe('https://gist.github.com/sroberts/6529712/raw/1e979071f6a9e8747d2c44cf5af7c4998e068d49/wordlist') + }); + + //TODO - More verbose tests to make sure this doesn't get called when Regex fails + //TODO - Get access to the callback to actually test the body and parsing + +}); \ No newline at end of file