hipbot 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +1 -9
- data/README.md +17 -1
- data/hipbot.gemspec +9 -9
- data/lib/hipbot.rb +1 -0
- data/lib/hipbot/adapters/hipchat/initializer.rb +1 -1
- data/lib/hipbot/callbacks/room_presence.rb +3 -0
- data/lib/hipbot/configuration.rb +4 -1
- data/lib/hipbot/helpers.rb +1 -1
- data/lib/hipbot/http.rb +5 -10
- data/lib/hipbot/logger.rb +2 -4
- data/lib/hipbot/match.rb +2 -2
- data/lib/hipbot/matchable.rb +15 -5
- data/lib/hipbot/presence.rb +17 -0
- data/lib/hipbot/reactable.rb +7 -1
- data/lib/hipbot/reaction.rb +1 -1
- data/lib/hipbot/storages/hash.rb +5 -5
- data/lib/hipbot/user.rb +0 -4
- data/lib/hipbot/version.rb +1 -1
- data/spec/integration/my_hipbot.rb +13 -4
- data/spec/integration/my_hipbot_spec.rb +33 -26
- data/spec/spec_helper.rb +3 -10
- data/spec/unit/bot_spec.rb +29 -30
- data/spec/unit/match_spec.rb +32 -28
- data/spec/unit/matchable_spec.rb +23 -0
- data/spec/unit/message_spec.rb +15 -8
- data/spec/unit/reaction_factory_spec.rb +2 -2
- data/spec/unit/reaction_spec.rb +4 -4
- metadata +46 -44
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,13 @@
|
|
1
1
|
require_relative '../lib/hipbot'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
|
-
config.mock_with :
|
7
|
+
config.mock_with :rspec
|
8
8
|
|
9
9
|
config.before(:all) do
|
10
10
|
Hipbot::User.send(:include, Hipbot::Storages::Hash)
|
11
11
|
Hipbot::Room.send(:include, Hipbot::Storages::Hash)
|
12
|
-
Hipbot.stubs(logger: NullLogger.instance)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class NullLogger
|
17
|
-
def self.instance
|
18
|
-
Logger.new('/dev/null')
|
19
12
|
end
|
20
13
|
end
|
data/spec/unit/bot_spec.rb
CHANGED
@@ -5,7 +5,6 @@ describe "a class that inherits", Hipbot::Bot do
|
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
described_class.instance.plugins.clear
|
8
|
-
described_class.instance.configuration.logger = NullLogger.instance
|
9
8
|
described_class.instance.setup
|
10
9
|
end
|
11
10
|
subject { described_class.instance }
|
@@ -19,7 +18,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
19
18
|
described_class.on /^hello there$/ do
|
20
19
|
reply('hi!')
|
21
20
|
end
|
22
|
-
subject.
|
21
|
+
subject.should_receive(:send_to_room).with(room, 'hi!')
|
23
22
|
subject.react(sender, room, '@robot hello there')
|
24
23
|
end
|
25
24
|
|
@@ -27,7 +26,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
27
26
|
described_class.on /^you are (.*), robot$/ do |adj|
|
28
27
|
reply("i know i'm #{adj}!")
|
29
28
|
end
|
30
|
-
subject.
|
29
|
+
subject.should_receive(:send_to_room).with(room, "i know i'm cool!")
|
31
30
|
subject.react(sender, room, '@robot you are cool, robot')
|
32
31
|
end
|
33
32
|
|
@@ -35,7 +34,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
35
34
|
described_class.on /^send "(.*)" to (.*@.*)$/ do |message, recipient|
|
36
35
|
reply("sent \"#{message}\" to #{recipient}")
|
37
36
|
end
|
38
|
-
subject.
|
37
|
+
subject.should_receive(:send_to_room).with(room, 'sent "hello!" to robot@robots.org')
|
39
38
|
subject.react(sender, room, '@robot send "hello!" to robot@robots.org')
|
40
39
|
end
|
41
40
|
|
@@ -43,14 +42,14 @@ describe "a class that inherits", Hipbot::Bot do
|
|
43
42
|
described_class.default do |message|
|
44
43
|
reply("I don't understand \"#{message}\"")
|
45
44
|
end
|
46
|
-
subject.
|
45
|
+
subject.should_receive(:send_to_room).with(room, 'I don\'t understand "hello robot!"')
|
47
46
|
subject.react(sender, room, '@robot hello robot!')
|
48
47
|
end
|
49
48
|
|
50
49
|
it "should choose first option when multiple options match" do
|
51
50
|
described_class.on /hello there/ do reply('hello there') end
|
52
51
|
described_class.on /hello (.*)/ do reply('hello') end
|
53
|
-
subject.
|
52
|
+
subject.should_receive(:send_to_room).with(room, 'hello there')
|
54
53
|
subject.react(sender, room, '@robot hello there')
|
55
54
|
end
|
56
55
|
|
@@ -62,17 +61,17 @@ describe "a class that inherits", Hipbot::Bot do
|
|
62
61
|
end
|
63
62
|
|
64
63
|
it "should understand simple english" do |msg|
|
65
|
-
subject.
|
64
|
+
subject.should_receive(:send_to_room).with(room, 'hello tom')
|
66
65
|
subject.react(sender, room, '@robot hello tom')
|
67
66
|
end
|
68
67
|
|
69
68
|
it "should understand english" do |msg|
|
70
|
-
subject.
|
69
|
+
subject.should_receive(:send_to_room).with(room, 'hello tom')
|
71
70
|
subject.react(sender, room, '@robot good morning tom')
|
72
71
|
end
|
73
72
|
|
74
73
|
it "should understand german" do |msg|
|
75
|
-
subject.
|
74
|
+
subject.should_receive(:send_to_room).with(room, 'hello tom')
|
76
75
|
subject.react(sender, room, '@robot guten tag tom')
|
77
76
|
end
|
78
77
|
end
|
@@ -82,7 +81,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
82
81
|
described_class.on /^you are (.*)$/, global: true do |adj|
|
83
82
|
reply("i know i'm #{adj}!")
|
84
83
|
end
|
85
|
-
subject.
|
84
|
+
subject.should_receive(:send_to_room).with(room, "i know i'm cool!")
|
86
85
|
subject.react(sender, room, 'you are cool')
|
87
86
|
end
|
88
87
|
|
@@ -90,7 +89,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
90
89
|
described_class.on /^you are (.*)$/ do |adj|
|
91
90
|
reply("i know i'm #{adj}!")
|
92
91
|
end
|
93
|
-
subject.
|
92
|
+
subject.should_receive(:send_to_room).never
|
94
93
|
subject.react(sender, room, 'you are cool')
|
95
94
|
end
|
96
95
|
end
|
@@ -102,7 +101,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
102
101
|
described_class.on /wazzup\?/, from: sender.name do
|
103
102
|
reply('Wazzup, Tom?')
|
104
103
|
end
|
105
|
-
subject.
|
104
|
+
subject.should_receive(:send_to_room).with(room, 'Wazzup, Tom?')
|
106
105
|
subject.react(sender, room, '@robot wazzup?')
|
107
106
|
end
|
108
107
|
|
@@ -110,7 +109,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
110
109
|
described_class.on /wazzup\?/, from: ['someone', sender.name] do
|
111
110
|
reply('wazzup, tom?')
|
112
111
|
end
|
113
|
-
subject.
|
112
|
+
subject.should_receive(:send_to_room).with(room, 'wazzup, tom?')
|
114
113
|
subject.react(sender, room, '@robot wazzup?')
|
115
114
|
end
|
116
115
|
|
@@ -118,7 +117,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
118
117
|
described_class.on /wazzup\?/, from: sender.name do
|
119
118
|
reply('wazzup, tom?')
|
120
119
|
end
|
121
|
-
subject.
|
120
|
+
subject.should_receive(:send_to_room).never
|
122
121
|
subject.react(other_user, room, '@robot wazzup?')
|
123
122
|
end
|
124
123
|
|
@@ -126,7 +125,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
126
125
|
described_class.on /wazzup\?/, from: [sender.name] do
|
127
126
|
reply('wazzup, tom?')
|
128
127
|
end
|
129
|
-
subject.
|
128
|
+
subject.should_receive(:send_to_room).never
|
130
129
|
subject.react(other_user, room, '@robot wazzup?')
|
131
130
|
end
|
132
131
|
end
|
@@ -138,7 +137,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
138
137
|
described_class.on /wazzup\?/, room: 'Test Room' do
|
139
138
|
reply('Wazzup, Tom?')
|
140
139
|
end
|
141
|
-
subject.
|
140
|
+
subject.should_receive(:send_to_room).with(room, 'Wazzup, Tom?')
|
142
141
|
subject.react(sender, room, '@robot wazzup?')
|
143
142
|
end
|
144
143
|
|
@@ -146,7 +145,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
146
145
|
described_class.on /wazzup\?/, room: ['Test Room 2', 'Test Room'] do
|
147
146
|
reply('wazzup, tom?')
|
148
147
|
end
|
149
|
-
subject.
|
148
|
+
subject.should_receive(:send_to_room).with(room, 'wazzup, tom?')
|
150
149
|
subject.react(sender, room, '@robot wazzup?')
|
151
150
|
end
|
152
151
|
|
@@ -154,7 +153,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
154
153
|
described_class.on /wazzup\?/, room: 'Test Room' do
|
155
154
|
reply('wazzup, tom?')
|
156
155
|
end
|
157
|
-
subject.
|
156
|
+
subject.should_receive(:send_to_room).never
|
158
157
|
subject.react(sender, other_room, '@robot wazzup?')
|
159
158
|
end
|
160
159
|
|
@@ -162,7 +161,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
162
161
|
described_class.on /wazzup\?/, room: ['Test Room 2'] do
|
163
162
|
reply('wazzup, tom?')
|
164
163
|
end
|
165
|
-
subject.
|
164
|
+
subject.should_receive(:send_to_room).never
|
166
165
|
subject.react(sender, room, '@robot wazzup?')
|
167
166
|
end
|
168
167
|
end
|
@@ -174,7 +173,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
174
173
|
described_class.on /.*/ do
|
175
174
|
reply("you said: #{message.body}")
|
176
175
|
end
|
177
|
-
subject.
|
176
|
+
subject.should_receive(:send_to_room).with(room, "you said: hello")
|
178
177
|
subject.react(user, room, "@robot hello")
|
179
178
|
end
|
180
179
|
|
@@ -182,7 +181,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
182
181
|
described_class.on /.*/ do
|
183
182
|
reply("you are: #{sender.name}")
|
184
183
|
end
|
185
|
-
subject.
|
184
|
+
subject.should_receive(:send_to_room).with(room, "you are: Tom Smith")
|
186
185
|
subject.react(user, room, "@robot hello")
|
187
186
|
end
|
188
187
|
|
@@ -190,7 +189,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
190
189
|
described_class.on /.*/ do
|
191
190
|
reply("recipients: #{message.recipients.join(', ')}")
|
192
191
|
end
|
193
|
-
subject.
|
192
|
+
subject.should_receive(:send_to_room).with(room, "recipients: robot, dave")
|
194
193
|
subject.react(user, room, "@robot tell @dave hello from me")
|
195
194
|
end
|
196
195
|
|
@@ -198,7 +197,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
198
197
|
described_class.on /.*/ do
|
199
198
|
reply(message.sender.first_name)
|
200
199
|
end
|
201
|
-
subject.
|
200
|
+
subject.should_receive(:send_to_room).with(room, 'Tom')
|
202
201
|
subject.react(user, room, '@robot What\'s my name?')
|
203
202
|
end
|
204
203
|
|
@@ -206,7 +205,7 @@ describe "a class that inherits", Hipbot::Bot do
|
|
206
205
|
described_class.on /.*/ do
|
207
206
|
reply(message.mentions.join(' '))
|
208
207
|
end
|
209
|
-
subject.
|
208
|
+
subject.should_receive(:send_to_room).with(room, 'dave rachel')
|
210
209
|
subject.react(user, room, '@robot do you know @dave? @dave is @rachel father')
|
211
210
|
end
|
212
211
|
end
|
@@ -235,12 +234,12 @@ describe "a class that inherits", Hipbot::Bot do
|
|
235
234
|
}
|
236
235
|
|
237
236
|
it "should respond to reaction defined in plugin" do
|
238
|
-
subject.
|
237
|
+
subject.should_receive(:send_to_room).with(room, 'plugin ack')
|
239
238
|
subject.react(sender, room, '@robot plugin respond')
|
240
239
|
end
|
241
240
|
|
242
241
|
it "should respond to default reaction defined in plugin" do
|
243
|
-
subject.
|
242
|
+
subject.should_receive(:send_to_room).with(room, 'plugin default')
|
244
243
|
subject.react(sender, room, '@robot blahblah')
|
245
244
|
end
|
246
245
|
|
@@ -248,12 +247,12 @@ describe "a class that inherits", Hipbot::Bot do
|
|
248
247
|
described_class.default do
|
249
248
|
reply('bot default')
|
250
249
|
end
|
251
|
-
subject.
|
250
|
+
subject.should_receive(:send_to_room).with(room, 'plugin default')
|
252
251
|
subject.react(sender, room, '@robot blahblah')
|
253
252
|
end
|
254
253
|
|
255
254
|
it 'should have access to #plugin inside reaction' do
|
256
|
-
subject.
|
255
|
+
subject.should_receive(:send_to_room).with(room, 'some method')
|
257
256
|
subject.react(sender, room, '@robot plugin method')
|
258
257
|
end
|
259
258
|
end
|
@@ -262,8 +261,8 @@ describe "a class that inherits", Hipbot::Bot do
|
|
262
261
|
describe "configurable options" do
|
263
262
|
Hipbot::Configuration::OPTIONS.each do |option|
|
264
263
|
it "should delegate #{option} to configuration" do
|
265
|
-
value =
|
266
|
-
subject.configuration.
|
264
|
+
value = double
|
265
|
+
subject.configuration.should_receive(option).and_return(value)
|
267
266
|
subject.send(option)
|
268
267
|
end
|
269
268
|
end
|
data/spec/unit/match_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe Hipbot::Match do
|
4
4
|
subject { described_class.new(reaction, message) }
|
5
5
|
|
6
|
-
let(:message) {
|
6
|
+
let(:message) { double(for?: true, body: 'test message', private?: false) }
|
7
7
|
let(:reaction) do
|
8
|
-
|
8
|
+
double(
|
9
9
|
global?: false,
|
10
10
|
from_anywhere?: true,
|
11
11
|
to_anything?: false,
|
@@ -16,7 +16,11 @@ describe Hipbot::Match do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
before do
|
19
|
-
Hipbot.
|
19
|
+
Hipbot.stub(user: double)
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
Hipbot.unstub(:user)
|
20
24
|
end
|
21
25
|
|
22
26
|
describe "#matches?" do
|
@@ -25,8 +29,8 @@ describe Hipbot::Match do
|
|
25
29
|
describe "specific regexp" do
|
26
30
|
describe "matching the message body" do
|
27
31
|
before do
|
28
|
-
message.
|
29
|
-
reaction.
|
32
|
+
message.stub(body: 'test message')
|
33
|
+
reaction.stub(regexps: [/\Atest/])
|
30
34
|
end
|
31
35
|
|
32
36
|
its(:matches?) { should be_true }
|
@@ -34,8 +38,8 @@ describe Hipbot::Match do
|
|
34
38
|
|
35
39
|
describe "not matching message body" do
|
36
40
|
before do
|
37
|
-
message.
|
38
|
-
reaction.
|
41
|
+
message.stub(body: 'test message')
|
42
|
+
reaction.stub(regexps: [/\Arandom/])
|
39
43
|
end
|
40
44
|
|
41
45
|
its(:matches?) { should be_false }
|
@@ -45,8 +49,8 @@ describe Hipbot::Match do
|
|
45
49
|
describe "multiple regexps" do
|
46
50
|
describe "matching message body" do
|
47
51
|
before do
|
48
|
-
message.
|
49
|
-
reaction.
|
52
|
+
message.stub(body: 'test message')
|
53
|
+
reaction.stub(regexps: [/\Awat/, /\Atest/])
|
50
54
|
end
|
51
55
|
|
52
56
|
its(:matches?) { should be_true }
|
@@ -54,8 +58,8 @@ describe Hipbot::Match do
|
|
54
58
|
|
55
59
|
describe "not matching message body" do
|
56
60
|
before do
|
57
|
-
message.
|
58
|
-
reaction.
|
61
|
+
message.stub(body: 'test message')
|
62
|
+
reaction.stub(regexps: [/\Awat/, /\Arandom/])
|
59
63
|
end
|
60
64
|
|
61
65
|
its(:matches?) { should be_false }
|
@@ -65,7 +69,7 @@ describe Hipbot::Match do
|
|
65
69
|
describe "specific condition" do
|
66
70
|
describe "returning true" do
|
67
71
|
before do
|
68
|
-
reaction.
|
72
|
+
reaction.stub(condition: proc { true })
|
69
73
|
end
|
70
74
|
|
71
75
|
its(:matches?) { should be_true }
|
@@ -73,7 +77,7 @@ describe Hipbot::Match do
|
|
73
77
|
|
74
78
|
describe "returning false" do
|
75
79
|
before do
|
76
|
-
reaction.
|
80
|
+
reaction.stub(condition: proc { false })
|
77
81
|
end
|
78
82
|
|
79
83
|
its(:matches?) { should be_false }
|
@@ -82,10 +86,10 @@ describe Hipbot::Match do
|
|
82
86
|
end
|
83
87
|
|
84
88
|
describe "#invoke" do
|
85
|
-
let(:response) {
|
89
|
+
let(:response) { double }
|
86
90
|
|
87
91
|
before do
|
88
|
-
Hipbot::Response.
|
92
|
+
Hipbot::Response.stub(new: response)
|
89
93
|
end
|
90
94
|
|
91
95
|
after do
|
@@ -94,54 +98,54 @@ describe Hipbot::Match do
|
|
94
98
|
|
95
99
|
describe "a reaction with no regexps" do
|
96
100
|
before do
|
97
|
-
reaction.
|
101
|
+
reaction.stub(to_anything?: true)
|
98
102
|
end
|
99
103
|
|
100
104
|
it "calls response with message body" do
|
101
|
-
response.
|
105
|
+
response.should_receive(:invoke).with([message.body])
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
105
109
|
describe "a reaction with regexp with no variables" do
|
106
110
|
before do
|
107
|
-
reaction.
|
111
|
+
reaction.stub(regexps: [/.*/])
|
108
112
|
end
|
109
113
|
|
110
114
|
it "calls response with message body" do
|
111
|
-
response.
|
115
|
+
response.should_receive(:invoke).with([])
|
112
116
|
end
|
113
117
|
end
|
114
118
|
|
115
119
|
describe "a reaction with regexp with one variable" do
|
116
120
|
before do
|
117
|
-
message.
|
118
|
-
reaction.
|
121
|
+
message.stub(body: 'I like trains.')
|
122
|
+
reaction.stub(regexps: [/\Ai like (\w+)/i])
|
119
123
|
end
|
120
124
|
|
121
125
|
it "calls response with variable parsed out of message body" do
|
122
|
-
response.
|
126
|
+
response.should_receive(:invoke).with(['trains'])
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
130
|
describe "a reaction with regexp with multiple variables" do
|
127
131
|
before do
|
128
|
-
message.
|
129
|
-
reaction.
|
132
|
+
message.stub(body: 'I like trains and cars.')
|
133
|
+
reaction.stub(regexps: [/\Ai like (\w+) and (\w+)/i])
|
130
134
|
end
|
131
135
|
|
132
136
|
it "calls response with variables parsed out of message body" do
|
133
|
-
response.
|
137
|
+
response.should_receive(:invoke).with(%w{trains cars})
|
134
138
|
end
|
135
139
|
end
|
136
140
|
|
137
141
|
describe "a reaction with multiple regexps with variables" do
|
138
142
|
before do
|
139
|
-
message.
|
140
|
-
reaction.
|
143
|
+
message.stub(body: 'I enjoy trains and cars.')
|
144
|
+
reaction.stub(regexps: [/\AI enjoy (\w+) and (\w+)/, /\Ai like (\w+) and (\w+)/i])
|
141
145
|
end
|
142
146
|
|
143
147
|
it "calls response with variable parsed out of message body" do
|
144
|
-
response.
|
148
|
+
response.should_receive(:invoke).with(%w{trains cars})
|
145
149
|
end
|
146
150
|
end
|
147
151
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hipbot::Matchable do
|
4
|
+
include Hipbot::Matchable
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
Hipbot::Bot.instance.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:sender) { Hipbot::User.new(name: 'test user') }
|
11
|
+
let(:room) { Hipbot::Room.new(name: 'test room') }
|
12
|
+
|
13
|
+
def plugins
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#react' do
|
18
|
+
it 'calls #invoke_all on Match' do
|
19
|
+
Hipbot::Match.should_receive(:invoke_all)
|
20
|
+
react(sender, room, 'test message')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|