sclemmer-robut 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +11 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +65 -0
- data/README.rdoc +199 -0
- data/Rakefile +27 -0
- data/bin/robut +10 -0
- data/examples/Chatfile +31 -0
- data/examples/config.ru +13 -0
- data/lib/rexml_patches.rb +26 -0
- data/lib/robut/connection.rb +124 -0
- data/lib/robut/plugin/alias.rb +109 -0
- data/lib/robut/plugin/calc.rb +26 -0
- data/lib/robut/plugin/echo.rb +9 -0
- data/lib/robut/plugin/google_images.rb +17 -0
- data/lib/robut/plugin/help.rb +16 -0
- data/lib/robut/plugin/later.rb +81 -0
- data/lib/robut/plugin/lunch.rb +76 -0
- data/lib/robut/plugin/meme.rb +32 -0
- data/lib/robut/plugin/pick.rb +18 -0
- data/lib/robut/plugin/ping.rb +9 -0
- data/lib/robut/plugin/quips.rb +60 -0
- data/lib/robut/plugin/say.rb +23 -0
- data/lib/robut/plugin/sayings.rb +37 -0
- data/lib/robut/plugin/stock.rb +45 -0
- data/lib/robut/plugin/twss.rb +19 -0
- data/lib/robut/plugin/weather.rb +126 -0
- data/lib/robut/plugin.rb +201 -0
- data/lib/robut/pm.rb +40 -0
- data/lib/robut/presence.rb +39 -0
- data/lib/robut/room.rb +30 -0
- data/lib/robut/storage/base.rb +21 -0
- data/lib/robut/storage/hash_store.rb +26 -0
- data/lib/robut/storage/yaml_store.rb +57 -0
- data/lib/robut/storage.rb +3 -0
- data/lib/robut/version.rb +4 -0
- data/lib/robut/web.rb +26 -0
- data/lib/robut.rb +9 -0
- data/sclemmer-robut.gemspec +24 -0
- data/test/fixtures/bad_location.xml +1 -0
- data/test/fixtures/las_vegas.xml +1 -0
- data/test/fixtures/seattle.xml +1 -0
- data/test/fixtures/tacoma.xml +1 -0
- data/test/mocks/connection_mock.rb +22 -0
- data/test/mocks/presence_mock.rb +25 -0
- data/test/simplecov_helper.rb +2 -0
- data/test/test_helper.rb +9 -0
- data/test/unit/connection_test.rb +161 -0
- data/test/unit/plugin/alias_test.rb +76 -0
- data/test/unit/plugin/echo_test.rb +27 -0
- data/test/unit/plugin/help_test.rb +46 -0
- data/test/unit/plugin/later_test.rb +40 -0
- data/test/unit/plugin/lunch_test.rb +36 -0
- data/test/unit/plugin/pick_test.rb +35 -0
- data/test/unit/plugin/ping_test.rb +22 -0
- data/test/unit/plugin/quips_test.rb +58 -0
- data/test/unit/plugin/say_test.rb +34 -0
- data/test/unit/plugin/weather_test.rb +101 -0
- data/test/unit/plugin_test.rb +91 -0
- data/test/unit/room_test.rb +51 -0
- data/test/unit/storage/hash_store_test.rb +15 -0
- data/test/unit/storage/yaml_store_test.rb +47 -0
- data/test/unit/storage/yaml_test.yml +1 -0
- data/test/unit/web_test.rb +46 -0
- metadata +162 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/echo'
|
3
|
+
|
4
|
+
class SimplePlugin
|
5
|
+
include Robut::Plugin
|
6
|
+
attr_accessor :run
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super(*args)
|
10
|
+
@run = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle(*args)
|
14
|
+
self.run = true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ReplyToUserPlugin
|
19
|
+
include Robut::Plugin
|
20
|
+
|
21
|
+
def initialize(*args)
|
22
|
+
super(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def handle(time, nick, message)
|
26
|
+
reply("Reply", nick)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ReplyToRoomPlugin
|
31
|
+
include Robut::Plugin
|
32
|
+
|
33
|
+
def initialize(*args)
|
34
|
+
super(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle(time, nick, message)
|
38
|
+
reply("Reply", :room)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class ReplyMock
|
43
|
+
attr_accessor :messages
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
@messages = []
|
47
|
+
end
|
48
|
+
|
49
|
+
def send(message)
|
50
|
+
@messages << message
|
51
|
+
end
|
52
|
+
|
53
|
+
def room
|
54
|
+
"my_room@test.com"
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_message_callback(code, reply_to)
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def join(path)
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
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
|
+
|
83
|
+
class ConnectionTest < Test::Unit::TestCase
|
84
|
+
|
85
|
+
def setup
|
86
|
+
Robut::Plugin.plugins = [SimplePlugin]
|
87
|
+
@connection = Robut::Connection.new({
|
88
|
+
:jid => 'abc@def.com',
|
89
|
+
:nick => "Test Robut",
|
90
|
+
:mention_name => 'test'
|
91
|
+
})
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_end_to_end_message
|
95
|
+
Robut::Plugin.plugins = [Robut::Plugin::Echo]
|
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)
|
102
|
+
assert_equal("Test Message", message.body)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_handle_message_delegates_to_plugin
|
106
|
+
presence = Robut::Presence.new(@connection)
|
107
|
+
plugins = plugins(presence)
|
108
|
+
assert !plugins.first.run, "The plugin was not set up correctly."
|
109
|
+
|
110
|
+
presence.handle_message(plugins, Time.now, 'Justin', 'Test Message')
|
111
|
+
assert plugins.first.run, "The plugin's handle_message method should have been run"
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_handle_message_from_person
|
115
|
+
Robut::Plugin.plugins = [Robut::Plugin::Echo]
|
116
|
+
sender = Jabber::JID.new('justin@example.com')
|
117
|
+
@connection.client = ReplyMock.new
|
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
|
122
|
+
assert_equal(sender, message.to)
|
123
|
+
assert_equal("Test Message", message.body)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_reply_directly_to_user
|
127
|
+
Robut::Plugin.plugins = [ReplyToUserPlugin]
|
128
|
+
@connection.client = ReplyMock.new
|
129
|
+
justin = Jabber::JID.new('justin@example.com')
|
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
|
135
|
+
assert_equal(justin, message.to.to_s)
|
136
|
+
assert_equal(:chat, message.type)
|
137
|
+
assert_equal("Reply", message.body)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_reply_directly_to_room
|
141
|
+
Robut::Plugin.plugins = [ReplyToRoomPlugin]
|
142
|
+
sender = Jabber::JID.new('justin@example.com')
|
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)
|
148
|
+
assert_equal("Reply", message.body)
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
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") } )
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/alias'
|
3
|
+
require 'robut/plugin/echo'
|
4
|
+
|
5
|
+
class Robut::Plugin::AliasTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@connection = Robut::ConnectionMock.new
|
9
|
+
@presence = Robut::PresenceMock.new(@connection)
|
10
|
+
@plugin = Robut::Plugin::Alias.new(@presence)
|
11
|
+
@plugin.aliases = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_aliases_this_to_that
|
15
|
+
@plugin.handle(Time.now, "@john", "@robut alias w weather?")
|
16
|
+
assert_equal 'weather?', @plugin.aliases['w']
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_thinks_this_is_that
|
20
|
+
@plugin.handle(Time.now, "@john", "@robut alias this @robut echo that")
|
21
|
+
@plugin.handle(Time.now, "@john", "this")
|
22
|
+
message = @plugin.reply_to.messages.first
|
23
|
+
assert_equal "@john", message[1]
|
24
|
+
assert_equal "@robut echo that", message[2]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_doesnt_alias_when_it_shouldnt
|
28
|
+
@plugin.handle(Time.now, "@john", "@robut somthing alias w weather?")
|
29
|
+
assert @plugin.aliases.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_can_alias_with_quotes
|
33
|
+
@plugin.handle(Time.now, "@john", '@robut alias "long string" "some other long string"')
|
34
|
+
assert_equal 'some other long string', @plugin.aliases['long string']
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_can_apply_aliases_with_quotes
|
38
|
+
@plugin.handle(Time.now, "@john", '@robut alias "long string" "some other long string"')
|
39
|
+
@plugin.handle(Time.now, "@john", "long string")
|
40
|
+
message = @plugin.reply_to.messages.first
|
41
|
+
assert_equal "@john", message[1]
|
42
|
+
assert_equal "some other long string", message[2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_aliases_can_be_removed
|
46
|
+
@plugin.handle(Time.now, "@john", "@robut alias this that")
|
47
|
+
@plugin.handle(Time.now, "@john", "@robut remove alias this")
|
48
|
+
assert @plugin.aliases.empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_remove_aliases_doesnt_choke_on_missing_key
|
52
|
+
@plugin.handle(Time.now, "@john", "@robut alias this that")
|
53
|
+
@plugin.handle(Time.now, "@john", "@robut remove alias")
|
54
|
+
assert_equal({'this' => 'that'}, @plugin.aliases)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_remove_alias_handles_quotes
|
58
|
+
@plugin.handle(Time.now, "@john", '@robut alias "long string" "that"')
|
59
|
+
@plugin.handle(Time.now, "@john", '@robut remove alias "long string"')
|
60
|
+
assert @plugin.aliases.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_can_list_all_aliases
|
64
|
+
@plugin.handle(Time.now, "@john", "@robut alias this that")
|
65
|
+
@plugin.handle(Time.now, "@john", "@robut alias something something else")
|
66
|
+
@plugin.handle(Time.now, "@john", "@robut aliases")
|
67
|
+
assert_equal ["something => something else\nthis => that"], @plugin.reply_to.replies
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_can_clear_aliases
|
71
|
+
@plugin.handle(Time.now, "@john", "@robut alias this that")
|
72
|
+
@plugin.handle(Time.now, "@john", "@robut clear aliases")
|
73
|
+
assert_equal({}, @plugin.aliases)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/echo'
|
3
|
+
|
4
|
+
class Robut::Plugin::EchoTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Echo.new(@presence)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_replies_with_this
|
13
|
+
@plugin.handle(Time.now, "@john", "@robut echo this")
|
14
|
+
assert_equal ["this"], @plugin.reply_to.replies
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_replies_with_nicks
|
18
|
+
@plugin.handle(Time.now, "@john", "@robut echo @justin look over here!")
|
19
|
+
assert_equal ["@justin look over here!"], @plugin.reply_to.replies
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_doesnt_reply_with_empty
|
23
|
+
@plugin.handle(Time.now, "@john", "@robut echo")
|
24
|
+
assert_equal [], @plugin.reply_to.replies
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/echo'
|
3
|
+
require 'robut/plugin/help'
|
4
|
+
|
5
|
+
class Robut::Plugin::PluginWithoutHelp
|
6
|
+
include Robut::Plugin
|
7
|
+
|
8
|
+
def usage
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Robut::Plugin::HelpTest < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@connection = Robut::ConnectionMock.new
|
17
|
+
@presence = Robut::PresenceMock.new(@connection)
|
18
|
+
Robut::Plugin.plugins << Robut::Plugin::Echo
|
19
|
+
Robut::Plugin.plugins << Robut::Plugin::Help
|
20
|
+
@plugin = Robut::Plugin::Help.new(@presence)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
Robut::Plugin.plugins = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_help
|
28
|
+
@plugin.handle(Time.now, "@justin", "@robut help")
|
29
|
+
assert_equal [
|
30
|
+
"Supported commands:",
|
31
|
+
"@robut echo <message> - replies to the channel with <message>",
|
32
|
+
"@robut help - displays this message",
|
33
|
+
], @plugin.reply_to.replies
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_empty_help
|
37
|
+
Robut::Plugin.plugins << Robut::Plugin::PluginWithoutHelp
|
38
|
+
@plugin.handle(Time.now, "@justin", "@robut help")
|
39
|
+
assert_equal [
|
40
|
+
"Supported commands:",
|
41
|
+
"@robut echo <message> - replies to the channel with <message>",
|
42
|
+
"@robut help - displays this message",
|
43
|
+
], @plugin.reply_to.replies
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/later'
|
3
|
+
|
4
|
+
class Robut::Plugin::LaterTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Later.new(@presence)
|
10
|
+
@plugin.instance_eval do
|
11
|
+
def threader; yield; end # no threads
|
12
|
+
def sleep(*prms); end # just skip the whole sleeping part
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_replies_with_minutes
|
17
|
+
@plugin.handle(Time.now, "@john", "@robut in 0 minutes msg me")
|
18
|
+
assert_equal ["Ok, see you in 0 minutes"], @plugin.reply_to.replies
|
19
|
+
message = @plugin.reply_to.messages.first
|
20
|
+
assert message
|
21
|
+
assert_equal message[1], "@john"
|
22
|
+
assert_equal message[2], "@robut msg me"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_replies_with_sec
|
26
|
+
@plugin.handle(Time.now, "@john", "@robut in 1 sec msg me")
|
27
|
+
assert_equal ["Ok, see you in 1 sec"], @plugin.reply_to.replies
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_replies_with_hr
|
31
|
+
@plugin.handle(Time.now, "@john", "@robut in 1 hr msg me")
|
32
|
+
assert_equal ["Ok, see you in 1 hr"], @plugin.reply_to.replies
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_replies_with_hrs
|
36
|
+
@plugin.handle(Time.now, "@john", "@robut in 2 hrs msg me")
|
37
|
+
assert_equal ["Ok, see you in 2 hrs"], @plugin.reply_to.replies
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/lunch'
|
3
|
+
|
4
|
+
class Robut::Plugin::LunchTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Lunch.new(@presence)
|
10
|
+
@plugin.places = ["Pho"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_handle_returns_pho_for_lunch
|
14
|
+
@plugin.handle(Time.now, "John", "lunch?")
|
15
|
+
assert_equal ["Pho!"], @plugin.reply_to.replies
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_handle_returns_all_places_for_lunch_places
|
19
|
+
@plugin.new_place("Teriyaki")
|
20
|
+
@plugin.handle(Time.now, "John", "@robut lunch places")
|
21
|
+
assert_equal ["Pho, Teriyaki"], @plugin.reply_to.replies
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_handle_new_lunch_place
|
25
|
+
@plugin.handle(Time.now, "John", "@robut new lunch place Green Leaf")
|
26
|
+
assert_equal ["Ok, I'll add \"Green Leaf\" to the the list of lunch places"], @plugin.reply_to.replies
|
27
|
+
assert @plugin.places.include?("Green Leaf")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_handle_remove_lunch_place
|
31
|
+
@plugin.handle(Time.now, "John", "@robut remove lunch place Pho")
|
32
|
+
assert_equal ["I removed \"Pho\" from the list of lunch places"], @plugin.reply_to.replies
|
33
|
+
assert @plugin.places.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -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
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/ping'
|
3
|
+
|
4
|
+
class Robut::Plugin::PingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Ping.new(@presence)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_replies_wih_pong
|
13
|
+
@plugin.handle(Time.now, "@john", "@robut ping")
|
14
|
+
assert_equal ["pong"], @plugin.reply_to.replies
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_replies_wih_sec
|
18
|
+
@plugin.handle(Time.now, "@john", "@robut ping pong")
|
19
|
+
assert_equal [], @plugin.reply_to.replies
|
20
|
+
end
|
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
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'robut/plugin/say'
|
3
|
+
|
4
|
+
class Robut::Plugin::SayTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@connection = Robut::ConnectionMock.new
|
8
|
+
@presence = Robut::PresenceMock.new(@connection)
|
9
|
+
@plugin = Robut::Plugin::Say.new(@presence)
|
10
|
+
@plugin.instance_eval do
|
11
|
+
# Stub out system
|
12
|
+
def system(c); system_calls << c; end
|
13
|
+
def system_calls; @system_calls ||= []; end;
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_says_stuff
|
18
|
+
@plugin.handle(Time.now, "@john", "@robut say stuff")
|
19
|
+
assert_equal [], @plugin.reply_to.replies # shouldn't reply to the chat room
|
20
|
+
assert_equal ["say stuff"], @plugin.system_calls
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_doesnt_say_stuff
|
24
|
+
@plugin.handle(Time.now, "@john", "@robut ok don't say stuff")
|
25
|
+
assert_equal [], @plugin.reply_to.replies
|
26
|
+
assert_equal [], @plugin.system_calls
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_strips_bad_chars
|
30
|
+
@plugin.handle(Time.now, "@john", "@robut say it's time for $%@ more_test 123 p\"")
|
31
|
+
assert_equal ["say its time for more test 123 p"], @plugin.system_calls
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'webmock/test_unit'
|
3
|
+
require 'time-warp'
|
4
|
+
require 'robut/plugin/weather'
|
5
|
+
|
6
|
+
class Robut::Plugin::WeatherTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@connection = Robut::ConnectionMock.new
|
10
|
+
@presence = Robut::PresenceMock.new(@connection)
|
11
|
+
@plugin = Robut::Plugin::Weather.new(@presence)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
Robut::Plugin::Weather.default_location = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_handle_no_weather
|
19
|
+
@plugin.handle(Time.now, "John", "lunch?")
|
20
|
+
assert_equal( [], @plugin.reply_to.replies )
|
21
|
+
|
22
|
+
@plugin.handle(Time.now, "John", "?")
|
23
|
+
assert_equal( [], @plugin.reply_to.replies )
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_handle_no_location_no_default
|
27
|
+
@plugin.handle(Time.now, "John", "weather?")
|
28
|
+
assert_equal( ["I don't have a default location!"], @plugin.reply_to.replies )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_handle_no_location_default_set
|
32
|
+
Robut::Plugin::Weather.default_location = "Seattle"
|
33
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Seattle").to_return(:body => File.open(File.expand_path("../../../fixtures/seattle.xml", __FILE__), "r").read)
|
34
|
+
|
35
|
+
@plugin.handle(Time.now, "John", "weather?")
|
36
|
+
assert_equal( ["Weather for Seattle, WA: Mostly Cloudy, 58F"], @plugin.reply_to.replies )
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_handle_location
|
40
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=tacoma").to_return(:body => File.open(File.expand_path("../../../fixtures/tacoma.xml", __FILE__), "r").read)
|
41
|
+
|
42
|
+
@plugin.handle(Time.now, "John", "tacoma weather?")
|
43
|
+
assert_equal( ["Weather for Tacoma, WA: Cloudy, 60F"], @plugin.reply_to.replies )
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_no_question_mark
|
47
|
+
@plugin.handle(Time.now, "John", "seattle weather")
|
48
|
+
assert_equal( [], @plugin.reply_to.replies )
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_handle_day
|
52
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Seattle").to_return(:body => File.open(File.expand_path("../../../fixtures/seattle.xml", __FILE__), "r").read)
|
53
|
+
|
54
|
+
pretend_now_is(2011,"may",23,17) do
|
55
|
+
@plugin.handle(Time.now, "John", "Seattle weather tuesday?")
|
56
|
+
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.reply_to.replies )
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_handle_tomorrow
|
61
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Seattle").to_return(:body => File.open(File.expand_path("../../../fixtures/seattle.xml", __FILE__), "r").read)
|
62
|
+
|
63
|
+
pretend_now_is(2011,"may",23,17) do
|
64
|
+
@plugin.handle(Time.now, "John", "Seattle weather tomorrow?")
|
65
|
+
assert_equal( ["Forecast for Seattle, WA on Tue: Partly Cloudy, High: 67F, Low: 51F"], @plugin.reply_to.replies )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_handle_today
|
70
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Seattle").to_return(:body => File.open(File.expand_path("../../../fixtures/seattle.xml", __FILE__), "r").read)
|
71
|
+
|
72
|
+
pretend_now_is(2011,"may",23,17) do
|
73
|
+
@plugin.handle(Time.now, "John", "Seattle weather today?")
|
74
|
+
assert_equal( ["Forecast for Seattle, WA on Mon: Partly Cloudy, High: 59F, Low: 48F"], @plugin.reply_to.replies )
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_handle_multi_word_location
|
79
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Las%20Vegas").to_return(:body => File.open(File.expand_path("../../../fixtures/las_vegas.xml", __FILE__), "r").read)
|
80
|
+
@plugin.handle(Time.now, "John", "Las Vegas weather?")
|
81
|
+
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.reply_to.replies )
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_handle_location_with_comma
|
85
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=Las%20Vegas,%20NV").to_return(:body => File.open(File.expand_path("../../../fixtures/las_vegas.xml", __FILE__), "r").read)
|
86
|
+
@plugin.handle(Time.now, "John", "Las Vegas, NV weather?")
|
87
|
+
assert_equal( ["Weather for Las Vegas, NV: Mostly Cloudy, 83F"], @plugin.reply_to.replies )
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_handle_bad_location
|
91
|
+
stub_request(:any, "http://www.google.com/ig/api?weather=asdf").to_return(:body => File.open(File.expand_path("../../../fixtures/bad_location.xml", __FILE__), "r").read)
|
92
|
+
@plugin.handle(Time.now, "John", "asdf weather?")
|
93
|
+
assert_equal( ["I don't recognize the location: \"asdf\""], @plugin.reply_to.replies )
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_handle_bad_date
|
97
|
+
@plugin.handle(Time.now, "John", "Seattle weather asdf?")
|
98
|
+
assert_equal( ["I don't recognize the date: \"asdf\""], @plugin.reply_to.replies )
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|