robut 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/Gemfile +2 -3
- data/README.rdoc +38 -19
- data/examples/Chatfile +10 -4
- data/lib/robut.rb +3 -0
- data/lib/robut/connection.rb +10 -72
- data/lib/robut/plugin.rb +94 -13
- data/lib/robut/plugin/echo.rb +3 -13
- data/lib/robut/plugin/google_images.rb +17 -0
- data/lib/robut/plugin/help.rb +7 -15
- data/lib/robut/plugin/meme.rb +22 -53
- data/lib/robut/plugin/pick.rb +18 -0
- data/lib/robut/plugin/ping.rb +3 -9
- data/lib/robut/plugin/quips.rb +60 -0
- data/lib/robut/plugin/say.rb +6 -12
- data/lib/robut/plugin/stock.rb +45 -0
- data/lib/robut/pm.rb +40 -0
- data/lib/robut/presence.rb +35 -0
- data/lib/robut/room.rb +30 -0
- data/lib/robut/version.rb +1 -1
- data/test/mocks/connection_mock.rb +2 -18
- data/test/mocks/presence_mock.rb +25 -0
- data/test/test_helper.rb +3 -1
- data/test/unit/connection_test.rb +58 -25
- data/test/unit/plugin/alias_test.rb +5 -4
- data/test/unit/plugin/echo_test.rb +5 -4
- data/test/unit/plugin/help_test.rb +4 -3
- data/test/unit/plugin/later_test.rb +7 -6
- data/test/unit/plugin/lunch_test.rb +6 -5
- data/test/unit/plugin/pick_test.rb +35 -0
- data/test/unit/plugin/ping_test.rb +4 -3
- data/test/unit/plugin/quips_test.rb +58 -0
- data/test/unit/plugin/say_test.rb +4 -3
- data/test/unit/plugin/weather_test.rb +15 -14
- data/test/unit/plugin_test.rb +62 -1
- data/test/unit/room_test.rb +51 -0
- metadata +28 -20
- data/lib/robut/plugin/rdio.rb +0 -96
- data/lib/robut/plugin/rdio/public/css/rdio.css +0 -141
- data/lib/robut/plugin/rdio/public/css/style.css +0 -79
- data/lib/robut/plugin/rdio/public/css/style_after.css +0 -42
- data/lib/robut/plugin/rdio/public/images/background.png +0 -0
- data/lib/robut/plugin/rdio/public/images/no-album.png +0 -0
- data/lib/robut/plugin/rdio/public/index.html +0 -43
- data/lib/robut/plugin/rdio/public/js/libs/dd_belatedpng.js +0 -13
- data/lib/robut/plugin/rdio/public/js/libs/jquery-1.5.1.min.js +0 -16
- data/lib/robut/plugin/rdio/public/js/libs/modernizr-1.7.min.js +0 -2
- data/lib/robut/plugin/rdio/public/js/rdio.js +0 -129
- data/lib/robut/plugin/rdio/public/js/script.js +0 -3
- data/lib/robut/plugin/rdio/server.rb +0 -57
@@ -4,23 +4,7 @@ class Robut::ConnectionMock < Robut::Connection
|
|
4
4
|
|
5
5
|
def initialize(config = nil)
|
6
6
|
self.config = config || self.class.config
|
7
|
-
self.store
|
7
|
+
self.store = Robut::Storage::HashStore
|
8
|
+
self.client = Jabber::Client.new ''
|
8
9
|
end
|
9
|
-
|
10
|
-
def replies
|
11
|
-
@replies ||= []
|
12
|
-
end
|
13
|
-
|
14
|
-
def reply(msg, to = nil)
|
15
|
-
replies << msg
|
16
|
-
end
|
17
|
-
|
18
|
-
def handle_message(plugins, time, nick, message)
|
19
|
-
messages << [time, nick, message]
|
20
|
-
end
|
21
|
-
|
22
|
-
def messages
|
23
|
-
@messages ||= []
|
24
|
-
end
|
25
|
-
|
26
10
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'robut/storage/hash_store'
|
2
|
+
|
3
|
+
class Robut::PresenceMock < Robut::Room
|
4
|
+
|
5
|
+
def initialize(connection)
|
6
|
+
self.connection = connection
|
7
|
+
end
|
8
|
+
|
9
|
+
def replies
|
10
|
+
@replies ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def reply(msg, to = nil)
|
14
|
+
replies << msg
|
15
|
+
end
|
16
|
+
|
17
|
+
def handle_message(plugins, time, nick, message)
|
18
|
+
messages << [time, nick, message]
|
19
|
+
end
|
20
|
+
|
21
|
+
def messages
|
22
|
+
@messages ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'robut/plugin/echo'
|
2
3
|
|
3
4
|
class SimplePlugin
|
4
5
|
include Robut::Plugin
|
@@ -52,31 +53,61 @@ class ReplyMock
|
|
52
53
|
def room
|
53
54
|
"my_room@test.com"
|
54
55
|
end
|
56
|
+
|
57
|
+
def add_message_callback(code, reply_to)
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def join(path)
|
62
|
+
true
|
63
|
+
end
|
55
64
|
end
|
56
65
|
|
66
|
+
class RoomMock < Robut::Room
|
67
|
+
|
68
|
+
def initialize(connection)
|
69
|
+
@muc = ReplyMock.new
|
70
|
+
@connection = connection
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class PMMock < Robut::PM
|
76
|
+
|
77
|
+
def initialize(connection)
|
78
|
+
@connection = connection
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
57
83
|
class ConnectionTest < Test::Unit::TestCase
|
58
84
|
|
59
85
|
def setup
|
60
86
|
Robut::Plugin.plugins = [SimplePlugin]
|
61
87
|
@connection = Robut::Connection.new({
|
62
88
|
:jid => 'abc@def.com',
|
63
|
-
:nick => "Test Robut"
|
89
|
+
:nick => "Test Robut",
|
90
|
+
:mention_name => 'test'
|
64
91
|
})
|
65
92
|
end
|
66
93
|
|
67
94
|
def test_end_to_end_message
|
68
95
|
Robut::Plugin.plugins = [Robut::Plugin::Echo]
|
69
|
-
|
70
|
-
@connection.
|
71
|
-
|
72
|
-
|
96
|
+
justin = Jabber::JID.new('justin@example.com')
|
97
|
+
@connection.roster = mock_roster(justin)
|
98
|
+
room = RoomMock.new(@connection)
|
99
|
+
room.handle_message(plugins(room), Time.now, 'Justin Weiss', '@test echo Test Message')
|
100
|
+
message = room.muc.messages.first
|
101
|
+
assert_equal(room.muc.room, message.to.to_s)
|
73
102
|
assert_equal("Test Message", message.body)
|
74
103
|
end
|
75
104
|
|
76
105
|
def test_handle_message_delegates_to_plugin
|
77
|
-
|
106
|
+
presence = Robut::Presence.new(@connection)
|
107
|
+
plugins = plugins(presence)
|
78
108
|
assert !plugins.first.run, "The plugin was not set up correctly."
|
79
|
-
|
109
|
+
|
110
|
+
presence.handle_message(plugins, Time.now, 'Justin', 'Test Message')
|
80
111
|
assert plugins.first.run, "The plugin's handle_message method should have been run"
|
81
112
|
end
|
82
113
|
|
@@ -84,8 +115,10 @@ class ConnectionTest < Test::Unit::TestCase
|
|
84
115
|
Robut::Plugin.plugins = [Robut::Plugin::Echo]
|
85
116
|
sender = Jabber::JID.new('justin@example.com')
|
86
117
|
@connection.client = ReplyMock.new
|
87
|
-
|
88
|
-
|
118
|
+
pm = PMMock.new(@connection)
|
119
|
+
|
120
|
+
pm.handle_message(plugins(pm, sender), Time.now, 'Justin', '@test echo Test Message')
|
121
|
+
message = pm.connection.client.messages.first
|
89
122
|
assert_equal(sender, message.to)
|
90
123
|
assert_equal("Test Message", message.body)
|
91
124
|
end
|
@@ -94,16 +127,11 @@ class ConnectionTest < Test::Unit::TestCase
|
|
94
127
|
Robut::Plugin.plugins = [ReplyToUserPlugin]
|
95
128
|
@connection.client = ReplyMock.new
|
96
129
|
justin = Jabber::JID.new('justin@example.com')
|
97
|
-
@connection.roster =
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
})
|
104
|
-
|
105
|
-
@connection.handle_message(plugins(@connection), Time.now, 'justin WEISS', 'Test Message')
|
106
|
-
message = @connection.client.messages.first
|
130
|
+
@connection.roster = mock_roster(justin)
|
131
|
+
pm = Robut::PM.new(@connection, justin)
|
132
|
+
|
133
|
+
pm.handle_message(plugins(pm), Time.now, 'justin WEISS', 'Test Message')
|
134
|
+
message = pm.connection.client.messages.first
|
107
135
|
assert_equal(justin, message.to.to_s)
|
108
136
|
assert_equal(:chat, message.type)
|
109
137
|
assert_equal("Reply", message.body)
|
@@ -112,17 +140,22 @@ class ConnectionTest < Test::Unit::TestCase
|
|
112
140
|
def test_reply_directly_to_room
|
113
141
|
Robut::Plugin.plugins = [ReplyToRoomPlugin]
|
114
142
|
sender = Jabber::JID.new('justin@example.com')
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
143
|
+
room = RoomMock.new(@connection)
|
144
|
+
|
145
|
+
room.handle_message(plugins(room, sender), Time.now, 'Justin', '@test echo Test Message')
|
146
|
+
message = room.muc.messages.first
|
147
|
+
assert_equal(room.muc.room, message.to.to_s)
|
119
148
|
assert_equal("Reply", message.body)
|
120
149
|
end
|
121
150
|
|
122
151
|
private
|
123
152
|
|
124
|
-
def plugins(
|
125
|
-
Robut::Plugin.plugins.map { |p| p.new(
|
153
|
+
def plugins(presence, sender = nil)
|
154
|
+
Robut::Plugin.plugins.map { |p| p.new(presence, sender) }
|
155
|
+
end
|
156
|
+
|
157
|
+
def mock_roster(jid)
|
158
|
+
OpenStruct.new( :items => { jid => OpenStruct.new(:iname => "Justin Weiss") } )
|
126
159
|
end
|
127
160
|
|
128
161
|
end
|
@@ -6,7 +6,8 @@ class Robut::Plugin::AliasTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def setup
|
8
8
|
@connection = Robut::ConnectionMock.new
|
9
|
-
@
|
9
|
+
@presence = Robut::PresenceMock.new(@connection)
|
10
|
+
@plugin = Robut::Plugin::Alias.new(@presence)
|
10
11
|
@plugin.aliases = {}
|
11
12
|
end
|
12
13
|
|
@@ -18,7 +19,7 @@ class Robut::Plugin::AliasTest < Test::Unit::TestCase
|
|
18
19
|
def test_thinks_this_is_that
|
19
20
|
@plugin.handle(Time.now, "@john", "@robut alias this @robut echo that")
|
20
21
|
@plugin.handle(Time.now, "@john", "this")
|
21
|
-
message = @plugin.
|
22
|
+
message = @plugin.reply_to.messages.first
|
22
23
|
assert_equal "@john", message[1]
|
23
24
|
assert_equal "@robut echo that", message[2]
|
24
25
|
end
|
@@ -36,7 +37,7 @@ class Robut::Plugin::AliasTest < Test::Unit::TestCase
|
|
36
37
|
def test_can_apply_aliases_with_quotes
|
37
38
|
@plugin.handle(Time.now, "@john", '@robut alias "long string" "some other long string"')
|
38
39
|
@plugin.handle(Time.now, "@john", "long string")
|
39
|
-
message = @plugin.
|
40
|
+
message = @plugin.reply_to.messages.first
|
40
41
|
assert_equal "@john", message[1]
|
41
42
|
assert_equal "some other long string", message[2]
|
42
43
|
end
|
@@ -63,7 +64,7 @@ class Robut::Plugin::AliasTest < Test::Unit::TestCase
|
|
63
64
|
@plugin.handle(Time.now, "@john", "@robut alias this that")
|
64
65
|
@plugin.handle(Time.now, "@john", "@robut alias something something else")
|
65
66
|
@plugin.handle(Time.now, "@john", "@robut aliases")
|
66
|
-
assert_equal ["something => something else\nthis => that"], @plugin.
|
67
|
+
assert_equal ["something => something else\nthis => that"], @plugin.reply_to.replies
|
67
68
|
end
|
68
69
|
|
69
70
|
def test_can_clear_aliases
|
@@ -5,22 +5,23 @@ class Robut::Plugin::EchoTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@connection = Robut::ConnectionMock.new
|
8
|
-
@
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Echo.new(@presence)
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_replies_with_this
|
12
13
|
@plugin.handle(Time.now, "@john", "@robut echo this")
|
13
|
-
assert_equal ["this"], @plugin.
|
14
|
+
assert_equal ["this"], @plugin.reply_to.replies
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_replies_with_nicks
|
17
18
|
@plugin.handle(Time.now, "@john", "@robut echo @justin look over here!")
|
18
|
-
assert_equal ["@justin look over here!"], @plugin.
|
19
|
+
assert_equal ["@justin look over here!"], @plugin.reply_to.replies
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_doesnt_reply_with_empty
|
22
23
|
@plugin.handle(Time.now, "@john", "@robut echo")
|
23
|
-
assert_equal [], @plugin.
|
24
|
+
assert_equal [], @plugin.reply_to.replies
|
24
25
|
end
|
25
26
|
|
26
27
|
end
|
@@ -14,9 +14,10 @@ class Robut::Plugin::HelpTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
def setup
|
16
16
|
@connection = Robut::ConnectionMock.new
|
17
|
+
@presence = Robut::PresenceMock.new(@connection)
|
17
18
|
Robut::Plugin.plugins << Robut::Plugin::Echo
|
18
19
|
Robut::Plugin.plugins << Robut::Plugin::Help
|
19
|
-
@plugin = Robut::Plugin::Help.new(@
|
20
|
+
@plugin = Robut::Plugin::Help.new(@presence)
|
20
21
|
end
|
21
22
|
|
22
23
|
def teardown
|
@@ -29,7 +30,7 @@ class Robut::Plugin::HelpTest < Test::Unit::TestCase
|
|
29
30
|
"Supported commands:",
|
30
31
|
"@robut echo <message> - replies to the channel with <message>",
|
31
32
|
"@robut help - displays this message",
|
32
|
-
], @plugin.
|
33
|
+
], @plugin.reply_to.replies
|
33
34
|
end
|
34
35
|
|
35
36
|
def test_empty_help
|
@@ -39,7 +40,7 @@ class Robut::Plugin::HelpTest < Test::Unit::TestCase
|
|
39
40
|
"Supported commands:",
|
40
41
|
"@robut echo <message> - replies to the channel with <message>",
|
41
42
|
"@robut help - displays this message",
|
42
|
-
], @plugin.
|
43
|
+
], @plugin.reply_to.replies
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -5,7 +5,8 @@ class Robut::Plugin::LaterTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@connection = Robut::ConnectionMock.new
|
8
|
-
@
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Later.new(@presence)
|
9
10
|
@plugin.instance_eval do
|
10
11
|
def threader; yield; end # no threads
|
11
12
|
def sleep(*prms); end # just skip the whole sleeping part
|
@@ -14,8 +15,8 @@ class Robut::Plugin::LaterTest < Test::Unit::TestCase
|
|
14
15
|
|
15
16
|
def test_replies_with_minutes
|
16
17
|
@plugin.handle(Time.now, "@john", "@robut in 0 minutes msg me")
|
17
|
-
assert_equal ["Ok, see you in 0 minutes"], @plugin.
|
18
|
-
message = @plugin.
|
18
|
+
assert_equal ["Ok, see you in 0 minutes"], @plugin.reply_to.replies
|
19
|
+
message = @plugin.reply_to.messages.first
|
19
20
|
assert message
|
20
21
|
assert_equal message[1], "@john"
|
21
22
|
assert_equal message[2], "@robut msg me"
|
@@ -23,17 +24,17 @@ class Robut::Plugin::LaterTest < Test::Unit::TestCase
|
|
23
24
|
|
24
25
|
def test_replies_with_sec
|
25
26
|
@plugin.handle(Time.now, "@john", "@robut in 1 sec msg me")
|
26
|
-
assert_equal ["Ok, see you in 1 sec"], @plugin.
|
27
|
+
assert_equal ["Ok, see you in 1 sec"], @plugin.reply_to.replies
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_replies_with_hr
|
30
31
|
@plugin.handle(Time.now, "@john", "@robut in 1 hr msg me")
|
31
|
-
assert_equal ["Ok, see you in 1 hr"], @plugin.
|
32
|
+
assert_equal ["Ok, see you in 1 hr"], @plugin.reply_to.replies
|
32
33
|
end
|
33
34
|
|
34
35
|
def test_replies_with_hrs
|
35
36
|
@plugin.handle(Time.now, "@john", "@robut in 2 hrs msg me")
|
36
|
-
assert_equal ["Ok, see you in 2 hrs"], @plugin.
|
37
|
+
assert_equal ["Ok, see you in 2 hrs"], @plugin.reply_to.replies
|
37
38
|
end
|
38
39
|
|
39
40
|
end
|
@@ -5,30 +5,31 @@ class Robut::Plugin::LunchTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@connection = Robut::ConnectionMock.new
|
8
|
-
@
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Lunch.new(@presence)
|
9
10
|
@plugin.places = ["Pho"]
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_handle_returns_pho_for_lunch
|
13
14
|
@plugin.handle(Time.now, "John", "lunch?")
|
14
|
-
assert_equal ["Pho!"], @plugin.
|
15
|
+
assert_equal ["Pho!"], @plugin.reply_to.replies
|
15
16
|
end
|
16
17
|
|
17
18
|
def test_handle_returns_all_places_for_lunch_places
|
18
19
|
@plugin.new_place("Teriyaki")
|
19
20
|
@plugin.handle(Time.now, "John", "@robut lunch places")
|
20
|
-
assert_equal ["Pho, Teriyaki"], @plugin.
|
21
|
+
assert_equal ["Pho, Teriyaki"], @plugin.reply_to.replies
|
21
22
|
end
|
22
23
|
|
23
24
|
def test_handle_new_lunch_place
|
24
25
|
@plugin.handle(Time.now, "John", "@robut new lunch place Green Leaf")
|
25
|
-
assert_equal ["Ok, I'll add \"Green Leaf\" to the the list of lunch places"], @plugin.
|
26
|
+
assert_equal ["Ok, I'll add \"Green Leaf\" to the the list of lunch places"], @plugin.reply_to.replies
|
26
27
|
assert @plugin.places.include?("Green Leaf")
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_handle_remove_lunch_place
|
30
31
|
@plugin.handle(Time.now, "John", "@robut remove lunch place Pho")
|
31
|
-
assert_equal ["I removed \"Pho\" from the list of lunch places"], @plugin.
|
32
|
+
assert_equal ["I removed \"Pho\" from the list of lunch places"], @plugin.reply_to.replies
|
32
33
|
assert @plugin.places.empty?
|
33
34
|
end
|
34
35
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/pick'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
class Robut::Plugin::PickTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@connection = Robut::ConnectionMock.new
|
9
|
+
@presence = Robut::PresenceMock.new(@connection)
|
10
|
+
@plugin = Robut::Plugin::Pick.new(@presence)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_replies_with_correct_response
|
14
|
+
@plugin.stubs(:random).returns(0)
|
15
|
+
@plugin.handle(Time.now, "@john", "@robut pick a, b, c")
|
16
|
+
assert_equal ["And the winner is... a"], @plugin.reply_to.replies
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_does_nothing_when_no_options_are_given
|
20
|
+
@plugin.handle(Time.now, "@john", "@robut pick")
|
21
|
+
assert @plugin.reply_to.replies.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_replies_only_option_if_given_one_options
|
25
|
+
@plugin.handle(Time.now, "@john", "@robut pick a")
|
26
|
+
assert_equal ["And the winner is... a"], @plugin.reply_to.replies
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_handles_spaces
|
30
|
+
@plugin.stubs(:random).returns(1)
|
31
|
+
@plugin.handle(Time.now, "@john", "@robut pick this is the first option, this is the second option, this is the third option")
|
32
|
+
assert_equal ["And the winner is... this is the second option"], @plugin.reply_to.replies
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -5,17 +5,18 @@ class Robut::Plugin::PingTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@connection = Robut::ConnectionMock.new
|
8
|
-
@
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Ping.new(@presence)
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_replies_wih_pong
|
12
13
|
@plugin.handle(Time.now, "@john", "@robut ping")
|
13
|
-
assert_equal ["pong"], @plugin.
|
14
|
+
assert_equal ["pong"], @plugin.reply_to.replies
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_replies_wih_sec
|
17
18
|
@plugin.handle(Time.now, "@john", "@robut ping pong")
|
18
|
-
assert_equal [], @plugin.
|
19
|
+
assert_equal [], @plugin.reply_to.replies
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/quips'
|
3
|
+
|
4
|
+
class Robut::Plugin::QuipsTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Quips.new(@presence)
|
10
|
+
@plugin.store["quips"] = ["the fancier i try and make it, the more complicated it gets!", "It works on my machine ..."]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_add_quip_adds_a_quip_to_the_database
|
14
|
+
@plugin.handle(Time.now, "John", "@robut add quip So, are we self managing now?")
|
15
|
+
assert_equal ["I added the quip to the quip database"], @plugin.reply_to.replies
|
16
|
+
assert_equal "So, are we self managing now?", @plugin.quips.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add_quip_without_a_quip_is_ignored
|
20
|
+
@plugin.handle(Time.now, "John", "@robut add quip ")
|
21
|
+
assert_equal [], @plugin.reply_to.replies
|
22
|
+
assert_equal 2, @plugin.quips.length
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_quip_doesnt_add_duplicates
|
26
|
+
@plugin.handle(Time.now, "John", "@robut add quip the fancier i try and make it, the more complicated it gets!")
|
27
|
+
assert_equal ["I didn't add the quip, since it was already added"], @plugin.reply_to.replies
|
28
|
+
assert_equal 2, @plugin.quips.length
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_remove_quip
|
32
|
+
@plugin.handle(Time.now, "John", "@robut remove quip the fancier i try and make it, the more complicated it gets!")
|
33
|
+
assert_equal ["I removed the quip from the quip database"], @plugin.reply_to.replies
|
34
|
+
assert_equal 1, @plugin.quips.length
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_remove_nonexisting_quip_returns_error_message
|
38
|
+
@plugin.handle(Time.now, "John", "@robut remove quip boooooooo")
|
39
|
+
assert_equal ["I couldn't remove the quip, since it wasn't in the quip database"], @plugin.reply_to.replies
|
40
|
+
assert_equal 2, @plugin.quips.length
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_quip_me_returns_a_random_quip
|
44
|
+
seed = srand(1)
|
45
|
+
begin
|
46
|
+
@plugin.handle(Time.now, "John", "@robut quip")
|
47
|
+
assert_equal ["It works on my machine ..."], @plugin.reply_to.replies
|
48
|
+
ensure
|
49
|
+
srand(seed)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_quip_me_returns_an_error_if_no_quips
|
54
|
+
@plugin.store["quips"] = []
|
55
|
+
@plugin.handle(Time.now, "John", "@robut quip")
|
56
|
+
assert_equal ["I don't know any quips"], @plugin.reply_to.replies
|
57
|
+
end
|
58
|
+
end
|