diff --git a/package.json b/package.json index 81653cc5..f590a9b7 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,13 @@ }, "devDependencies": { "chai": "^3.5.0", + "codecov": "^2.3.1", "coffee-coverage": "^2.0.0", "coffeescript": "^1.12.7", - "codecov": "^2.3.1", "hubot": ">= 2.19.0", "istanbul": "^0.4.3", "mocha": "^3.5.3", + "mockery": "^2.1.0", "should": "^8.0.0" }, "engines": { diff --git a/test/bot.coffee b/test/bot.coffee index f1633f72..9780a236 100644 --- a/test/bot.coffee +++ b/test/bot.coffee @@ -1,27 +1,32 @@ should = require 'should' chai = require 'chai' -{ EnterMessage, LeaveMessage, TopicMessage, CatchAllMessage, Robot } = require.main.require 'hubot' +mockery = require 'mockery' +hubotSlackMock = require '../slack.coffee' +mockery.registerMock('hubot-slack', hubotSlackMock); + +{ EnterMessage, LeaveMessage, TopicMessage, CatchAllMessage, Robot, loadBot } = require.main.require 'hubot' { SlackTextMessage, ReactionMessage, PresenceMessage } = require '../src/message' SlackClient = require '../src/client' _ = require 'lodash' describe 'Adapter', -> + before -> + mockery.enable({ + warnOnUnregistered: false + }); + + after -> + mockery.disable() + it 'Should initialize with a robot', -> @slackbot.robot.should.eql @stubs.robot - it 'Should add the `react` method to the hubot `Robot` prototype', -> - Robot.prototype.react.should.be.an.instanceOf(Function).with.lengthOf(3) - - # This is a sanity check to ensure the @slackbot.robot stub is proper. - @slackbot.robot.listen.should.be.an.instanceOf(Function).with.lengthOf(3) - @slackbot.robot.react.should.be.an.instanceOf(Function).with.lengthOf(3) - - it 'Should add the `presenceChange` method to the hubot `Robot` prototype', -> - Robot.prototype.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3) - - # This is a sanity check to ensure the @slackbot.robot stub is proper. - @slackbot.robot.listen.should.be.an.instanceOf(Function).with.lengthOf(3) - @slackbot.robot.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3) + it 'Should load an instance of Robot with extended methods', -> + loadedRobot = loadBot('', 'slack', false, 'Hubot') + + # Check to make sure presenceChange and react are loaded to Robot + loadedRobot.presenceChange.should.be.an.instanceOf(Function).with.lengthOf(3) + loadedRobot.react.should.be.an.instanceOf(Function).with.lengthOf(3) describe 'Connect', -> it 'Should connect successfully', ->