Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
Add badges to the README.
  • Loading branch information
Lexmark-haputman committed Nov 8, 2016
1 parent 0a9563c commit 61d61d8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# hubot-encourage
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

> Robot is very encouraging
Expand All @@ -12,7 +13,7 @@ Then add **hubot-encourage** to your `external-scripts.json`:

```json
[
"hubot-taboo-topics"
"hubot-encourage"
]
```

Expand All @@ -35,11 +36,17 @@ To test this script interactively, run:
npm start
```

To run automated tests:

```
npm test
```

[npm-image]: https://badge.fury.io/js/hubot-encourage.svg
[npm-url]: https://npmjs.org/package/hubot-encourage
[travis-image]: https://travis-ci.org/HaroldPutman/hubot-encourage.svg?branch=master
[travis-url]: https://travis-ci.org/HaroldPutman/hubot-encourage
[daviddm-image]: https://david-dm.org/HaroldPutman/hubot-encourage.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/HaroldPutman/hubot-encourage
[coveralls-image]: https://coveralls.io/repos/github/HaroldPutman/hubot-encourage/badge.svg?branch=master
[coveralls-url]:https://coveralls.io/github//hubot-encourage?branch=master
[coveralls-url]:https://coveralls.io/github/HaroldPutman/hubot-encourage?branch=master
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ module.exports = (robot) => {
robot.respond(/encourage @?(?:(me|us|everyone|all|(?:the )?team)|(.+))/i, msg => {
let name = msg.match[2];
if (msg.match[1] === "me") {
name = (Math.random() > 0.5) ? msg.message.user.name : "you";
let mi = [msg.message.user.name, "you"]; // mi, a name I call myself
name = msg.random(mi);
}
if (typeof name !== "undefined") {
msg.send(capitalize(msg.random(data.remarks).replace("%", name)));
Expand Down
32 changes: 30 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NewMockResponse = (function(superClass) {
}

NewMockResponse.prototype.random = function(items) {
return "% is good at like, 10 times more things than I am.";
return items[0];
};

return NewMockResponse;
Expand All @@ -37,7 +37,35 @@ describe('hubot', () => {
room.user.say('alice', 'hubot encourage bill').then(() => {
expect(room.messages).to.eql([
['alice', 'hubot encourage bill'],
['hubot', 'Bill is good at like, 10 times more things than I am.']
['hubot', 'Great job, bill!']
]);

done();

});

});

it('should respond when asked to encourage everyone', (done) => {

room.user.say('kumar', 'hubot encourage us').then(() => {
expect(room.messages).to.eql([
['kumar', 'hubot encourage us'],
['hubot', 'Great job today, everyone!']
]);

done();

});

});

it('should encourage me when asked', (done) => {

room.user.say('bob', 'hubot encourage me').then(() => {
expect(room.messages).to.eql([
['bob', 'hubot encourage me'],
['hubot', 'Great job, bob!']
]);

done();
Expand Down

0 comments on commit 61d61d8

Please sign in to comment.