sclemmer-robut 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +21 -0
  5. data/Gemfile.lock +65 -0
  6. data/README.rdoc +199 -0
  7. data/Rakefile +27 -0
  8. data/bin/robut +10 -0
  9. data/examples/Chatfile +31 -0
  10. data/examples/config.ru +13 -0
  11. data/lib/rexml_patches.rb +26 -0
  12. data/lib/robut/connection.rb +124 -0
  13. data/lib/robut/plugin/alias.rb +109 -0
  14. data/lib/robut/plugin/calc.rb +26 -0
  15. data/lib/robut/plugin/echo.rb +9 -0
  16. data/lib/robut/plugin/google_images.rb +17 -0
  17. data/lib/robut/plugin/help.rb +16 -0
  18. data/lib/robut/plugin/later.rb +81 -0
  19. data/lib/robut/plugin/lunch.rb +76 -0
  20. data/lib/robut/plugin/meme.rb +32 -0
  21. data/lib/robut/plugin/pick.rb +18 -0
  22. data/lib/robut/plugin/ping.rb +9 -0
  23. data/lib/robut/plugin/quips.rb +60 -0
  24. data/lib/robut/plugin/say.rb +23 -0
  25. data/lib/robut/plugin/sayings.rb +37 -0
  26. data/lib/robut/plugin/stock.rb +45 -0
  27. data/lib/robut/plugin/twss.rb +19 -0
  28. data/lib/robut/plugin/weather.rb +126 -0
  29. data/lib/robut/plugin.rb +201 -0
  30. data/lib/robut/pm.rb +40 -0
  31. data/lib/robut/presence.rb +39 -0
  32. data/lib/robut/room.rb +30 -0
  33. data/lib/robut/storage/base.rb +21 -0
  34. data/lib/robut/storage/hash_store.rb +26 -0
  35. data/lib/robut/storage/yaml_store.rb +57 -0
  36. data/lib/robut/storage.rb +3 -0
  37. data/lib/robut/version.rb +4 -0
  38. data/lib/robut/web.rb +26 -0
  39. data/lib/robut.rb +9 -0
  40. data/sclemmer-robut.gemspec +24 -0
  41. data/test/fixtures/bad_location.xml +1 -0
  42. data/test/fixtures/las_vegas.xml +1 -0
  43. data/test/fixtures/seattle.xml +1 -0
  44. data/test/fixtures/tacoma.xml +1 -0
  45. data/test/mocks/connection_mock.rb +22 -0
  46. data/test/mocks/presence_mock.rb +25 -0
  47. data/test/simplecov_helper.rb +2 -0
  48. data/test/test_helper.rb +9 -0
  49. data/test/unit/connection_test.rb +161 -0
  50. data/test/unit/plugin/alias_test.rb +76 -0
  51. data/test/unit/plugin/echo_test.rb +27 -0
  52. data/test/unit/plugin/help_test.rb +46 -0
  53. data/test/unit/plugin/later_test.rb +40 -0
  54. data/test/unit/plugin/lunch_test.rb +36 -0
  55. data/test/unit/plugin/pick_test.rb +35 -0
  56. data/test/unit/plugin/ping_test.rb +22 -0
  57. data/test/unit/plugin/quips_test.rb +58 -0
  58. data/test/unit/plugin/say_test.rb +34 -0
  59. data/test/unit/plugin/weather_test.rb +101 -0
  60. data/test/unit/plugin_test.rb +91 -0
  61. data/test/unit/room_test.rb +51 -0
  62. data/test/unit/storage/hash_store_test.rb +15 -0
  63. data/test/unit/storage/yaml_store_test.rb +47 -0
  64. data/test/unit/storage/yaml_test.yml +1 -0
  65. data/test/unit/web_test.rb +46 -0
  66. metadata +162 -0
@@ -0,0 +1,91 @@
1
+ require 'test_helper'
2
+
3
+ class Robut::PluginTest < Test::Unit::TestCase
4
+
5
+ class HandrolledStubPlugin
6
+ include Robut::Plugin
7
+
8
+ match /^message sent to robut with anchor (\w+)/, :sent_to_me => true do |word|
9
+ reply word
10
+ end
11
+
12
+ match /^another message sent to robut with anchor (\w+)/, :sent_to_me => true do |word|
13
+ reply word
14
+ end
15
+
16
+ desc "stop matcher - stop matching messages"
17
+ match /stop matcher/ do
18
+ true
19
+ end
20
+
21
+ match /stop matcher b/ do
22
+ reply "fail."
23
+ end
24
+ end
25
+
26
+ def setup
27
+ @plugin = HandrolledStubPlugin.new(
28
+ Robut::PresenceMock.new(
29
+ Robut::ConnectionMock
30
+ )
31
+ )
32
+ end
33
+
34
+ def test_sent_to_me_match
35
+ @plugin.handle(Time.now, "@john", "@robut message sent to robut with anchor pass")
36
+ assert_equal ["pass"], @plugin.reply_to.replies
37
+ end
38
+
39
+ def test_match_other_message_sent_to_me
40
+ @plugin.handle(Time.now, "@john", "@robut another message sent to robut with anchor pass")
41
+ assert_equal ["pass"], @plugin.reply_to.replies
42
+ end
43
+
44
+ def test_no_match_if_not_sent_to_me
45
+ @plugin.handle(Time.now, "@john", "message sent to robut with anchor pass")
46
+ assert_equal [], @plugin.reply_to.replies
47
+ end
48
+
49
+ def test_returning_true_stops_matching
50
+ @plugin.handle(Time.now, "@john", "stop matcher b")
51
+ assert_equal [], @plugin.reply_to.replies
52
+ end
53
+
54
+ def test_set_description
55
+ assert_equal ["stop matcher - stop matching messages"], @plugin.usage
56
+ end
57
+
58
+ def test_sent_to_me?
59
+ assert @plugin.sent_to_me?("@Robut hello there")
60
+ assert !@plugin.sent_to_me?("@Robuto hello there")
61
+ assert !@plugin.sent_to_me?("@David hello there")
62
+ assert @plugin.sent_to_me?("this is a @Robut message")
63
+ assert @plugin.sent_to_me?("this is a message to @robut")
64
+ assert !@plugin.sent_to_me?("this is a message to@robut")
65
+ end
66
+
67
+ def test_without_nick_robut_do_this
68
+ assert_equal "do this", @plugin.without_nick("@robut do this")
69
+ end
70
+
71
+ def test_without_nick_do_this_robut
72
+ assert_equal "do this @robut", @plugin.without_nick("do this @robut")
73
+ end
74
+
75
+ def test_sent_to_me_without_mention_configuration_option
76
+ setup_connection_without_mention_name
77
+ assert @plugin.sent_to_me?("@RobutTRobot hello there"), "sent_to_me? should match the standard HipChat mention format"
78
+ assert !@plugin.sent_to_me?("@Robut hello there"), "sent_to_me? should not match @robut if we don't have a mention name set"
79
+ end
80
+
81
+ private
82
+
83
+ def setup_connection_without_mention_name
84
+ @plugin = HandrolledStubPlugin.new(
85
+ Robut::PresenceMock.new(
86
+ Robut::ConnectionMock.new(OpenStruct.new(:nick => 'Robut t. Robot'))
87
+ )
88
+ )
89
+ end
90
+
91
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+ require 'robut/plugin/echo'
3
+
4
+ class MucMock
5
+ attr_accessor :messages, :room
6
+
7
+ def initialize
8
+ @messages = []
9
+ @room = ''
10
+ end
11
+
12
+ def join(room)
13
+ @room = room
14
+ end
15
+
16
+ def send(message)
17
+ @messages << message
18
+ end
19
+
20
+ def on_message(*args, &block)
21
+ if block_given?
22
+ @message_block = block
23
+ else
24
+ @message_block.call(args)
25
+ end
26
+ end
27
+ end
28
+
29
+ class RoomTest < Test::Unit::TestCase
30
+ def setup
31
+ Robut::Plugin.plugins = [Robut::Plugin::Echo]
32
+ connection = Robut::ConnectionMock.new(OpenStruct.new(:nick => 'Dodo'))
33
+ @room = Robut::Room.new(connection, 'fake_room')
34
+ end
35
+
36
+ def test_room_receives_correct_message
37
+ message = 'Huzzah!'
38
+ @room.muc = MucMock.new
39
+ @room.join
40
+
41
+ @room.muc.on_message(Time.now, "Art Vandelay", "@dodo echo #{message}")
42
+ assert_equal @room.muc.messages.first.body, message
43
+ end
44
+
45
+ def test_joining_the_right_room
46
+ @room.muc = MucMock.new
47
+ @room.join
48
+
49
+ assert_equal @room.muc.room, "#{@room.name}/#{@room.connection.config.nick}"
50
+ end
51
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'robut/storage/hash_store'
3
+
4
+ class Robut::Storage::HashStoreTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @store = Robut::Storage::HashStore
8
+ end
9
+
10
+ def test_can_write_and_read
11
+ assert_equal 'in the trunk', (@store['junk'] = 'in the trunk')
12
+ assert_equal 'in the trunk', @store['junk']
13
+ end
14
+
15
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'robut/storage/yaml_store'
3
+
4
+ class Robut::Storage::YamlStoreTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @store = Robut::Storage::YamlStore
8
+ @store.file = new_yaml_file
9
+ end
10
+
11
+ def teardown
12
+ File.delete new_yaml_file if File.exists?(new_yaml_file)
13
+ end
14
+
15
+ def test_can_write_and_read
16
+ assert_equal 'in the trunk', (@store['junk'] = 'in the trunk')
17
+ assert_equal 'in the trunk', @store['junk']
18
+ end
19
+
20
+ def test_load_an_empty_file
21
+ FileUtils.touch(new_yaml_file)
22
+ assert_equal nil, @store['non-exising-key']
23
+ end
24
+
25
+ def test_read_from_file
26
+ @store.file = test_yaml_file
27
+ assert_equal 'bar', @store['foo']
28
+ end
29
+
30
+ def test_persists_to_file
31
+ @store['pot'] = 'roast'
32
+ assert File.exists?(new_yaml_file)
33
+ yaml = YAML.load_file(new_yaml_file)
34
+ assert_equal 'roast', yaml['pot']
35
+ end
36
+
37
+ private
38
+
39
+ def test_yaml_file
40
+ File.join(File.dirname(__FILE__), 'yaml_test.yml')
41
+ end
42
+
43
+ def new_yaml_file
44
+ File.join(File.dirname(__FILE__), 'new_yaml_test.yml')
45
+ end
46
+
47
+ end
@@ -0,0 +1 @@
1
+ foo: bar
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'rack/test'
3
+
4
+ class WebTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Robut::Web
9
+ end
10
+
11
+ def setup
12
+ app.set :show_exceptions, false
13
+ app.set :raise_errors, true
14
+ app.set :connection, connection
15
+ end
16
+
17
+ def test_root
18
+ get '/'
19
+
20
+ assert last_response.ok?
21
+ end
22
+
23
+ def test_say
24
+ app.class_eval do
25
+ get '/test_say' do
26
+ say "Hello", nil
27
+ halt 200
28
+ end
29
+ end
30
+
31
+ get '/test_say'
32
+
33
+ assert_equal messages.first, ["Hello", nil]
34
+ end
35
+
36
+ private
37
+
38
+ def messages
39
+ connection.messages
40
+ end
41
+
42
+ def connection
43
+ @connection ||= Robut::ConnectionMock.new.connect
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sclemmer-robut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Justin Weiss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xmpp4r
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ description: A simple plugin-enabled HipChat bot
42
+ email:
43
+ - justin@uberweiss.org
44
+ executables:
45
+ - robut
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - README.rdoc
54
+ - Rakefile
55
+ - bin/robut
56
+ - examples/Chatfile
57
+ - examples/config.ru
58
+ - lib/rexml_patches.rb
59
+ - lib/robut.rb
60
+ - lib/robut/connection.rb
61
+ - lib/robut/plugin.rb
62
+ - lib/robut/plugin/alias.rb
63
+ - lib/robut/plugin/calc.rb
64
+ - lib/robut/plugin/echo.rb
65
+ - lib/robut/plugin/google_images.rb
66
+ - lib/robut/plugin/help.rb
67
+ - lib/robut/plugin/later.rb
68
+ - lib/robut/plugin/lunch.rb
69
+ - lib/robut/plugin/meme.rb
70
+ - lib/robut/plugin/pick.rb
71
+ - lib/robut/plugin/ping.rb
72
+ - lib/robut/plugin/quips.rb
73
+ - lib/robut/plugin/say.rb
74
+ - lib/robut/plugin/sayings.rb
75
+ - lib/robut/plugin/stock.rb
76
+ - lib/robut/plugin/twss.rb
77
+ - lib/robut/plugin/weather.rb
78
+ - lib/robut/pm.rb
79
+ - lib/robut/presence.rb
80
+ - lib/robut/room.rb
81
+ - lib/robut/storage.rb
82
+ - lib/robut/storage/base.rb
83
+ - lib/robut/storage/hash_store.rb
84
+ - lib/robut/storage/yaml_store.rb
85
+ - lib/robut/version.rb
86
+ - lib/robut/web.rb
87
+ - sclemmer-robut.gemspec
88
+ - test/fixtures/bad_location.xml
89
+ - test/fixtures/las_vegas.xml
90
+ - test/fixtures/seattle.xml
91
+ - test/fixtures/tacoma.xml
92
+ - test/mocks/connection_mock.rb
93
+ - test/mocks/presence_mock.rb
94
+ - test/simplecov_helper.rb
95
+ - test/test_helper.rb
96
+ - test/unit/connection_test.rb
97
+ - test/unit/plugin/alias_test.rb
98
+ - test/unit/plugin/echo_test.rb
99
+ - test/unit/plugin/help_test.rb
100
+ - test/unit/plugin/later_test.rb
101
+ - test/unit/plugin/lunch_test.rb
102
+ - test/unit/plugin/pick_test.rb
103
+ - test/unit/plugin/ping_test.rb
104
+ - test/unit/plugin/quips_test.rb
105
+ - test/unit/plugin/say_test.rb
106
+ - test/unit/plugin/weather_test.rb
107
+ - test/unit/plugin_test.rb
108
+ - test/unit/room_test.rb
109
+ - test/unit/storage/hash_store_test.rb
110
+ - test/unit/storage/yaml_store_test.rb
111
+ - test/unit/storage/yaml_test.yml
112
+ - test/unit/web_test.rb
113
+ homepage: http://rdoc.info/github/justinweiss/robut/master/frames
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project: robut
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: A simple plugin-enabled HipChat bot
136
+ test_files:
137
+ - test/fixtures/bad_location.xml
138
+ - test/fixtures/las_vegas.xml
139
+ - test/fixtures/seattle.xml
140
+ - test/fixtures/tacoma.xml
141
+ - test/mocks/connection_mock.rb
142
+ - test/mocks/presence_mock.rb
143
+ - test/simplecov_helper.rb
144
+ - test/test_helper.rb
145
+ - test/unit/connection_test.rb
146
+ - test/unit/plugin/alias_test.rb
147
+ - test/unit/plugin/echo_test.rb
148
+ - test/unit/plugin/help_test.rb
149
+ - test/unit/plugin/later_test.rb
150
+ - test/unit/plugin/lunch_test.rb
151
+ - test/unit/plugin/pick_test.rb
152
+ - test/unit/plugin/ping_test.rb
153
+ - test/unit/plugin/quips_test.rb
154
+ - test/unit/plugin/say_test.rb
155
+ - test/unit/plugin/weather_test.rb
156
+ - test/unit/plugin_test.rb
157
+ - test/unit/room_test.rb
158
+ - test/unit/storage/hash_store_test.rb
159
+ - test/unit/storage/yaml_store_test.rb
160
+ - test/unit/storage/yaml_test.yml
161
+ - test/unit/web_test.rb
162
+ has_rdoc: