<NME> telebotSpec.js
<BEF> const Bluebird = require('bluebird');
const mockery = require('mockery');
let Slimbot;
let slimbot;

describe('Slimbot', () => {

  beforeEach(() => {
    mockery.enable({
      warnOnReplace: false,
      warnOnUnregistered: false,
      useCleanCache: true
    });

    mockery.registerMock('request-promise', options => {
      let response = {
        statusCode: 200,
        body: '{ "result": ["test"] }',
        options: options
      };
      return Bluebird.resolve(response);
    });

    Slimbot = require('../../src/slimbot');
    slimbot = new Slimbot('token');
  });

  afterEach(() => {
    mockery.disable();
    mockery.deregisterAll();
  })

  describe('Core', () => {
    describe('instantiating', () => {
      it('should throw an error if token is not provided', () => {
        expect(() => { const bot = new Slimbot(); }).toThrow();
      });
    });

    describe('_request', () => {
      it('should throw an error if no method provided', done => {
        expect(() => { slimbot._request(); }).toThrow();
        expect(() => { slimbot._request(['getMe']); }).toThrow();
        done();
      });

      it('should return a promise', done => {
        expect(typeof slimbot._request('getUpdates').then === 'function').toEqual(true);
        done();
      });
    });

    describe('_processUpdates', () => {
      let updates;
      let flag;
      let payload;
      beforeEach(() => {
        updates = {
          result: [
            { update_id: 1000, message: 'message' },
            { update_id: 1001, edited_message: 'edited_message' },
            { update_id: 1002, channel_post: 'channel_post' },
            { update_id: 1003, edited_channel_post: 'edited_channel_post' },
            { update_id: 1004, callback_query: 'callback_query' },
            { update_id: 1005, inline_query: 'inline_query' },
            { update_id: 1006, chosen_inline_result: 'chosen_inline_result' },
            { update_id: 1007, shipping_query: 'shipping_query' },
            { update_id: 1008, pre_checkout_query: 'pre_checkout_query' },
            { update_id: 1009, poll: 'poll' },
            { update_id: 1010, poll_answer: 'poll_answer' }
          ]
        };
      });

      it('should take the id of last update increased by 1 as offset', () => {
        slimbot._processUpdates(updates);
        expect(slimbot._offset).toEqual(1011);
      });

      it('should emit "message" if update is of type "message"', () => {
        slimbot.on('message', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('message');
      });

      it('should emit "edited_message" if update is of type "edited_message"', () => {
        slimbot.on('edited_message', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('edited_message');
      });

      it('should emit "channel_post" if update is of type "channel_post"', () => {
        slimbot.on('channel_post', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('channel_post');
      });

      it('should emit "edited_channel_post" if update is of type "edited_channel_post"', () => {
        slimbot.on('edited_channel_post', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;

  describe('startPolling', () => {
    let currentOffset;

    beforeEach(() => {
      currentOffset = telebot._offset;
      telebot.startPolling();
    });

    it('should increase offset by 1', function() {
      expect(currentOffset < telebot._offset).toEqual(true);
    });

          };
        });
      telebot.startPolling();
      expect(telebot._request).toHaveBeenCalled();
    });
  });
});
        expect(payload).toEqual('inline_query');
      });

      it('should emit "chosen_inline_result" if update is of type "chosen_inline_result"', () => {
        slimbot.on('chosen_inline_result', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('chosen_inline_result');
      });

      it('should emit "shipping_query" if update is of type "shipping_query"', () => {
        slimbot.on('shipping_query', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('shipping_query');
      });

      it('should emit "pre_checkout_query" if update is of type "pre_checkout_query"', () => {
        slimbot.on('pre_checkout_query', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('pre_checkout_query');
      });

      it('should emit "poll" if update is of type "poll"', () => {
        slimbot.on('poll', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('poll');
      });

      it('should emit "poll_answer" if update is of type "poll_answer"', () => {
        slimbot.on('poll_answer', data => {
          if (data !== undefined) {
            flag = true;
            payload = data;
          };
        });
        slimbot._processUpdates(updates);
        expect(flag).toEqual(true);
        expect(payload).toEqual('poll_answer');
      });

    });
  });

  // Slimbot API methods

  describe('startPolling', () => {
    it('should call slimbot._request', () => {
      spyOn(slimbot, '_request').and.returnValue(Bluebird.resolve());
      slimbot.startPolling();
      expect(slimbot._request).toHaveBeenCalled();
    });

    it('should call slimbot._processUpdates', done => {
      spyOn(slimbot, '_request').and.returnValue(Bluebird.resolve({}));
      spyOn(slimbot, '_processUpdates');
      slimbot.startPolling().then(() => {
        expect(slimbot._processUpdates).toHaveBeenCalled();
        done();
      });
    });

    it('should store timeout object', done => {
      spyOn(slimbot, '_request').and.returnValue(Bluebird.resolve({}));
      spyOn(slimbot, '_processUpdates');
      slimbot.startPolling().then(() => {
        expect(slimbot._processUpdates).toHaveBeenCalled();
        expect(slimbot._timeout).not.toBe(undefined);
        expect(typeof slimbot._timeout.refresh).toBe('function');
        done();
      });
    });
  });

  describe('stopPolling', () => {
    it('should call slimbot.stopPolling', () => {
      spyOn(slimbot, 'stopPolling');
      slimbot.stopPolling();
      expect(slimbot.stopPolling).toHaveBeenCalled();
      expect(slimbot._timeout).toBe(undefined);
    });
  });
});
<MSG> Added additional test case

<DFF> @@ -121,13 +121,12 @@ describe('Telebot', () => {
 
   describe('startPolling', () => {
     let currentOffset;
-
     beforeEach(() => {
       currentOffset = telebot._offset;
       telebot.startPolling();
     });
 
-    it('should increase offset by 1', function() {
+    it('should increase offset by 1', () => {
       expect(currentOffset < telebot._offset).toEqual(true);
     });
 
@@ -136,5 +135,14 @@ describe('Telebot', () => {
       telebot.startPolling();
       expect(telebot._request).toHaveBeenCalled();
     });
+
+    it('should call telebot._processUpdates', (done) => {
+      spyOn(telebot, '_request').and.returnValue(Bluebird.resolve({}));
+      spyOn(telebot, '_processUpdates');
+      telebot.startPolling().then(() => {
+        expect(telebot._processUpdates).toHaveBeenCalled();
+        done();
+      });
+    });
   });
 });
\ No newline at end of file

{'commit': 'diff --git a/package.json b/package.json\nindex 30f89fb..830cb10 100644\n--- a/package.json\n+++ b/package.json\n@@ -20,7 +20,7 @@\n   "license": "MIT",\n   "scripts": {\n     "start": "pm2 start src/index.js --watch",\n-    "test": "istanbul cover jasmine spec/core/*.js"\n+    "test": "istanbul cover jasmine --captureExceptions spec/core/*.js && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"\n   },\n   "dependencies": {\n     "bluebird": "^3.4.0",\n@@ -28,6 +28,7 @@\n     "request-promise": "^3.0.0"\n   },\n   "devDependencies": {\n+    "coveralls": "^2.11.9",\n     "eslint": "^2.11.0",\n     "istanbul": "^0.4.3",\n     "jasmine": "^2.4.1",\ndiff --git a/spec/core/telebotSpec.js b/spec/core/telebotSpec.js\nindex 24ba340..c77e19a 100644\n--- a/spec/core/telebotSpec.js\n+++ b/spec/core/telebotSpec.js\n@@ -121,13 +121,12 @@ describe(\'Telebot\', () => {\n \n   describe(\'startPolling\', () => {\n     let currentOffset;\n-\n     beforeEach(() => {\n       currentOffset = telebot._offset;\n       telebot.startPolling();\n     });\n \n-    it(\'should increase offset by 1\', function() {\n+    it(\'should increase offset by 1\', () => {\n       expect(currentOffset < telebot._offset).toEqual(true);\n     });\n \n@@ -136,5 +135,14 @@ describe(\'Telebot\', () => {\n       telebot.startPolling();\n       expect(telebot._request).toHaveBeenCalled();\n     });\n+\n+    it(\'should call telebot._processUpdates\', (done) => {\n+      spyOn(telebot, \'_request\').and.returnValue(Bluebird.resolve({}));\n+      spyOn(telebot, \'_processUpdates\');\n+      telebot.startPolling().then(() => {\n+        expect(telebot._processUpdates).toHaveBeenCalled();\n+        done();\n+      });\n+    });\n   });\n });\n\\ No newline at end of file\ndiff --git a/src/telebot.js b/src/telebot.js\nindex 7f4719d..056c89b 100644\n--- a/src/telebot.js\n+++ b/src/telebot.js\n@@ -29,7 +29,7 @@ class Telebot extends Telegram(EventEmitter) {\n \n   startPolling() {\n     this._offset++;\n-    super.getUpdates(this._offset)\n+    return super.getUpdates(this._offset)\n     .then(updates => {\n       this._processUpdates(updates);\n     })\n', 'commit_subject': 'Added additional test case', 'repo_name': 'edisonchee/slimbot', 'committer': {'name': 'Edison Chee', 'email': '27a0423afbbcfc08d54695da9f01ee33529d0ee9@live.com', 'time_sec': '1464973012', 'tz_offset': '480', 'date': {'seconds': '1464973012'}}, 'commit_tree': '17f445b925b36dac8132714b28808bf8a0b9e57d', 'commit_message': 'Added additional test case\n', 'language_name': 'JavaScript', 'license': 'mit', 'hunks': "@@ -121,13 +121,12 @@ describe('Telebot', () => {\n \n   describe('startPolling', () => {\n     let currentOffset;\n-\n     beforeEach(() => {\n       currentOffset = telebot._offset;\n       telebot.startPolling();\n     });\n \n-    it('should increase offset by 1', function() {\n+    it('should increase offset by 1', () => {\n       expect(currentOffset < telebot._offset).toEqual(true);\n     });\n \n@@ -136,5 +135,14 @@ describe('Telebot', () => {\n       telebot.startPolling();\n       expect(telebot._request).toHaveBeenCalled();\n     });\n+\n+    it('should call telebot._processUpdates', (done) => {\n+      spyOn(telebot, '_request').and.returnValue(Bluebird.resolve({}));\n+      spyOn(telebot, '_processUpdates');\n+      telebot.startPolling().then(() => {\n+        expect(telebot._processUpdates).toHaveBeenCalled();\n+        done();\n+      });\n+    });\n   });\n });\n\\ No newline at end of file\n", 'addition_count': 10, 'deletion_count': 2, 'src_file': 'a/spec/core/telebotSpec.js', 'tgt_file': 'b/spec/core/telebotSpec.js', 'file_extension': '.js', 'before_file': 'const Bluebird = require(\'bluebird\');\nconst mockery = require(\'mockery\');\nlet Slimbot;\nlet slimbot;\n\ndescribe(\'Slimbot\', () => {\n\n  beforeEach(() => {\n    mockery.enable({\n      warnOnReplace: false,\n      warnOnUnregistered: false,\n      useCleanCache: true\n    });\n\n    mockery.registerMock(\'request-promise\', options => {\n      let response = {\n        statusCode: 200,\n        body: \'{ "result": ["test"] }\',\n        options: options\n      };\n      return Bluebird.resolve(response);\n    });\n\n    Slimbot = require(\'../../src/slimbot\');\n    slimbot = new Slimbot(\'token\');\n  });\n\n  afterEach(() => {\n    mockery.disable();\n    mockery.deregisterAll();\n  })\n\n  describe(\'Core\', () => {\n    describe(\'instantiating\', () => {\n      it(\'should throw an error if token is not provided\', () => {\n        expect(() => { const bot = new Slimbot(); }).toThrow();\n      });\n    });\n\n    describe(\'_request\', () => {\n      it(\'should throw an error if no method provided\', done => {\n        expect(() => { slimbot._request(); }).toThrow();\n        expect(() => { slimbot._request([\'getMe\']); }).toThrow();\n        done();\n      });\n\n      it(\'should return a promise\', done => {\n        expect(typeof slimbot._request(\'getUpdates\').then === \'function\').toEqual(true);\n        done();\n      });\n    });\n\n    describe(\'_processUpdates\', () => {\n      let updates;\n      let flag;\n      let payload;\n      beforeEach(() => {\n        updates = {\n          result: [\n            { update_id: 1000, message: \'message\' },\n            { update_id: 1001, edited_message: \'edited_message\' },\n            { update_id: 1002, channel_post: \'channel_post\' },\n            { update_id: 1003, edited_channel_post: \'edited_channel_post\' },\n            { update_id: 1004, callback_query: \'callback_query\' },\n            { update_id: 1005, inline_query: \'inline_query\' },\n            { update_id: 1006, chosen_inline_result: \'chosen_inline_result\' },\n            { update_id: 1007, shipping_query: \'shipping_query\' },\n            { update_id: 1008, pre_checkout_query: \'pre_checkout_query\' },\n            { update_id: 1009, poll: \'poll\' },\n            { update_id: 1010, poll_answer: \'poll_answer\' }\n          ]\n        };\n      });\n\n      it(\'should take the id of last update increased by 1 as offset\', () => {\n        slimbot._processUpdates(updates);\n        expect(slimbot._offset).toEqual(1011);\n      });\n\n      it(\'should emit "message" if update is of type "message"\', () => {\n        slimbot.on(\'message\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'message\');\n      });\n\n      it(\'should emit "edited_message" if update is of type "edited_message"\', () => {\n        slimbot.on(\'edited_message\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'edited_message\');\n      });\n\n      it(\'should emit "channel_post" if update is of type "channel_post"\', () => {\n        slimbot.on(\'channel_post\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'channel_post\');\n      });\n\n      it(\'should emit "edited_channel_post" if update is of type "edited_channel_post"\', () => {\n        slimbot.on(\'edited_channel_post\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n\n  describe(\'startPolling\', () => {\n    let currentOffset;\n\n    beforeEach(() => {\n      currentOffset = telebot._offset;\n      telebot.startPolling();\n    });\n\n    it(\'should increase offset by 1\', function() {\n      expect(currentOffset < telebot._offset).toEqual(true);\n    });\n\n          };\n        });\n      telebot.startPolling();\n      expect(telebot._request).toHaveBeenCalled();\n    });\n  });\n});\n        expect(payload).toEqual(\'inline_query\');\n      });\n\n      it(\'should emit "chosen_inline_result" if update is of type "chosen_inline_result"\', () => {\n        slimbot.on(\'chosen_inline_result\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'chosen_inline_result\');\n      });\n\n      it(\'should emit "shipping_query" if update is of type "shipping_query"\', () => {\n        slimbot.on(\'shipping_query\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'shipping_query\');\n      });\n\n      it(\'should emit "pre_checkout_query" if update is of type "pre_checkout_query"\', () => {\n        slimbot.on(\'pre_checkout_query\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'pre_checkout_query\');\n      });\n\n      it(\'should emit "poll" if update is of type "poll"\', () => {\n        slimbot.on(\'poll\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'poll\');\n      });\n\n      it(\'should emit "poll_answer" if update is of type "poll_answer"\', () => {\n        slimbot.on(\'poll_answer\', data => {\n          if (data !== undefined) {\n            flag = true;\n            payload = data;\n          };\n        });\n        slimbot._processUpdates(updates);\n        expect(flag).toEqual(true);\n        expect(payload).toEqual(\'poll_answer\');\n      });\n\n    });\n  });\n\n  // Slimbot API methods\n\n  describe(\'startPolling\', () => {\n    it(\'should call slimbot._request\', () => {\n      spyOn(slimbot, \'_request\').and.returnValue(Bluebird.resolve());\n      slimbot.startPolling();\n      expect(slimbot._request).toHaveBeenCalled();\n    });\n\n    it(\'should call slimbot._processUpdates\', done => {\n      spyOn(slimbot, \'_request\').and.returnValue(Bluebird.resolve({}));\n      spyOn(slimbot, \'_processUpdates\');\n      slimbot.startPolling().then(() => {\n        expect(slimbot._processUpdates).toHaveBeenCalled();\n        done();\n      });\n    });\n\n    it(\'should store timeout object\', done => {\n      spyOn(slimbot, \'_request\').and.returnValue(Bluebird.resolve({}));\n      spyOn(slimbot, \'_processUpdates\');\n      slimbot.startPolling().then(() => {\n        expect(slimbot._processUpdates).toHaveBeenCalled();\n        expect(slimbot._timeout).not.toBe(undefined);\n        expect(typeof slimbot._timeout.refresh).toBe(\'function\');\n        done();\n      });\n    });\n  });\n\n  describe(\'stopPolling\', () => {\n    it(\'should call slimbot.stopPolling\', () => {\n      spyOn(slimbot, \'stopPolling\');\n      slimbot.stopPolling();\n      expect(slimbot.stopPolling).toHaveBeenCalled();\n      expect(slimbot._timeout).toBe(undefined);\n    });\n  });\n});', 'message': 'Added additional test case\n', 'author_name': 'Edison Chee', 'lang': 'js'}