spox-mod_spox 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/CHANGELOG +5 -0
  2. data/README.rdoc +61 -1
  3. data/bin/mod_spox +1 -7
  4. data/data/mod_spox/extras/AutoKick.rb +3 -2
  5. data/data/mod_spox/extras/AutoMode.rb +2 -1
  6. data/data/mod_spox/extras/AutoRejoin.rb +5 -4
  7. data/data/mod_spox/extras/Bouncer.rb +243 -131
  8. data/data/mod_spox/extras/FloodKicker.rb +2 -1
  9. data/data/mod_spox/extras/Fortune.rb +5 -1
  10. data/data/mod_spox/extras/Karma.rb +2 -1
  11. data/data/mod_spox/extras/Logger.rb +11 -9
  12. data/data/mod_spox/extras/NickServ.rb +2 -1
  13. data/data/mod_spox/extras/PhpCli.rb +1 -1
  14. data/data/mod_spox/extras/PhpFuncLookup.rb +2 -1
  15. data/data/mod_spox/extras/RegexTracker.rb +2 -1
  16. data/data/mod_spox/extras/Roulette.rb +2 -1
  17. data/data/mod_spox/extras/Seen.rb +10 -8
  18. data/data/mod_spox/extras/Topten.rb +2 -1
  19. data/data/mod_spox/extras/Translate.rb +2 -1
  20. data/data/mod_spox/extras/Twitter.rb +1 -1
  21. data/data/mod_spox/plugins/Authenticator.rb +7 -7
  22. data/data/mod_spox/plugins/Banner.rb +6 -6
  23. data/data/mod_spox/plugins/BotNick.rb +2 -1
  24. data/data/mod_spox/plugins/Initializer.rb +4 -4
  25. data/data/mod_spox/plugins/Joiner.rb +1 -1
  26. data/data/mod_spox/plugins/PluginLoader.rb +1 -1
  27. data/data/mod_spox/plugins/Ponger.rb +8 -8
  28. data/data/mod_spox/plugins/Status.rb +1 -1
  29. data/lib/mod_spox/Bot.rb +27 -27
  30. data/lib/mod_spox/BotConfig.rb +17 -21
  31. data/lib/mod_spox/Filter.rb +29 -0
  32. data/lib/mod_spox/FilterManager.rb +63 -0
  33. data/lib/mod_spox/Helpers.rb +120 -14
  34. data/lib/mod_spox/Loader.rb +1 -1
  35. data/lib/mod_spox/MessageFactory.rb +10 -2
  36. data/lib/mod_spox/Pipeline.rb +66 -61
  37. data/lib/mod_spox/PluginManager.rb +5 -5
  38. data/lib/mod_spox/PriorityQueue.rb +21 -8
  39. data/lib/mod_spox/Sockets.rb +6 -6
  40. data/lib/mod_spox/Timer.rb +3 -3
  41. data/lib/mod_spox/Version.rb +2 -2
  42. data/lib/mod_spox/handlers/UserHost.rb +32 -0
  43. data/lib/mod_spox/handlers/Whois.rb +7 -7
  44. data/lib/mod_spox/messages/incoming/Pong.rb +11 -2
  45. data/lib/mod_spox/messages/incoming/UserHost.rb +24 -0
  46. data/lib/mod_spox/messages/internal/FilterAdd.rb +20 -0
  47. data/lib/mod_spox/messages/internal/FilterList.rb +18 -0
  48. data/lib/mod_spox/messages/internal/FilterListing.rb +22 -0
  49. data/lib/mod_spox/messages/internal/FilterRemove.rb +20 -0
  50. data/lib/mod_spox/messages/internal/Incoming.rb +15 -0
  51. data/lib/mod_spox/migrations/006_ignore.rb +21 -0
  52. data/lib/mod_spox/models/Nick.rb +11 -0
  53. data/lib/mod_spox/rfc2812.rb +2 -1
  54. data/lib/mod_spox/rfc2812_full.rb +185 -0
  55. data/tests/BotHolder.rb +7 -1
  56. data/tests/handlers/tc_Created.rb +28 -8
  57. data/tests/handlers/tc_Invite.rb +11 -9
  58. data/tests/handlers/tc_Join.rb +36 -16
  59. data/tests/handlers/tc_Kick.rb +27 -6
  60. data/tests/handlers/tc_Mode.rb +23 -13
  61. data/tests/handlers/tc_Names.rb +29 -9
  62. data/tests/handlers/tc_Nick.rb +30 -8
  63. data/tests/handlers/tc_Part.rb +30 -20
  64. data/tests/handlers/tc_Ping.rb +32 -19
  65. data/tests/handlers/tc_Pong.rb +28 -8
  66. data/tests/handlers/tc_Privmsg.rb +33 -13
  67. data/tests/handlers/tc_Quit.rb +30 -17
  68. data/tests/handlers/tc_Who.rb +8 -3
  69. data/tests/handlers/tc_Whois.rb +7 -3
  70. data/tests/lib/tc_BotConfig.rb +35 -0
  71. data/tests/lib/tc_Helpers.rb +139 -0
  72. data/tests/lib/tc_PriorityQueue.rb +31 -0
  73. metadata +17 -2
data/tests/BotHolder.rb CHANGED
@@ -14,7 +14,13 @@ class BotHolder
14
14
  attr_reader :bot
15
15
  def initialize
16
16
  ModSpox::Database.db = nil
17
- ModSpox.initialize_bot(Sequel.sqlite('test.db'))
17
+ begin
18
+ File.unlink('test.db') if File.exists?('test.db')
19
+ ModSpox.initialize_bot(Sequel.sqlite('test.db'))
20
+ rescue SQLite3::BusyException
21
+ ModSpox::Database.reconnect
22
+ retry
23
+ end
18
24
  require 'mod_spox/Bot'
19
25
  @bot = ModSpox::Bot.new
20
26
  m = ModSpox::Models::Nick.find_or_create(:nick => 'mod_spox')
@@ -4,21 +4,41 @@ class TestCreatedHandler < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  h = BotHolder.instance
7
- @bot = h.bot
7
+ @bot = h.bot
8
8
  @test = {
9
9
  :good => ':not.configured 003 spox :This server was created Tue Mar 24 2009 at 15:42:36 PDT',
10
10
  :bad => ':fubared 003 fail whale'
11
11
  }
12
+ @queue = Queue.new
13
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Created')
14
+ require 'mod_spox/handlers/Created'
15
+ @handler = ModSpox::Handlers::Created.new({})
12
16
  end
13
17
 
14
- def test_expected
15
- assert_equal('003', @bot.factory.find_key(@test[:good]))
16
- assert_kind_of(ModSpox::Messages::Incoming::Created, @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good]))
17
- assert_equal(@test[:good], @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good]).raw_content)
18
- assert_kind_of(Time, @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good]).date)
18
+ def gather(m)
19
+ @queue << m
19
20
  end
20
-
21
+
22
+ def test_indirect
23
+ @bot.factory << @test[:good]
24
+ sleep(0.1)
25
+ assert_equal(1, @queue.size)
26
+ m = @queue.pop
27
+ check_result(m)
28
+ end
29
+
30
+ def test_direct
31
+ check_result(@handler.process(@test[:good]))
32
+ end
33
+
21
34
  def test_unexpected
22
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
35
+ assert_raise(ModSpox::Exceptions::GeneralException) do
36
+ @handler.process(@test[:bad])
37
+ end
38
+ end
39
+
40
+ def check_result(m)
41
+ assert_kind_of(ModSpox::Messages::Incoming::Created, m)
42
+ assert_equal(m.raw_content, @test[:good])
23
43
  end
24
44
  end
@@ -4,24 +4,20 @@ class TestInviteHandler < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  h = BotHolder.instance
7
- @bot = h.bot
7
+ @bot = h.bot
8
8
  @test = {
9
9
  :good => ':spox!~spox@host INVITE spex :#m',
10
10
  :bad => ':fail INVITE whale'
11
11
  }
12
12
  @queue = Queue.new
13
- @bot.pipeline.hook(self, :gather, :Incoming_Invite)
13
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Invite')
14
+ require 'mod_spox/handlers/Invite'
15
+ @handler = ModSpox::Handlers::Invite.new({})
14
16
  end
15
17
 
16
18
  def gather(m)
17
19
  @queue << m
18
20
  end
19
-
20
- def test_direct
21
- assert_equal(:INVITE, @bot.factory.find_key(@test[:good]))
22
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
23
- check_result(result)
24
- end
25
21
 
26
22
  def test_indirect
27
23
  @bot.factory << @test[:good]
@@ -31,8 +27,14 @@ class TestInviteHandler < Test::Unit::TestCase
31
27
  check_result(m)
32
28
  end
33
29
 
30
+ def test_direct
31
+ check_result(@handler.process(@test[:good]))
32
+ end
33
+
34
34
  def test_unexpected
35
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
35
+ assert_raise(ModSpox::Exceptions::GeneralException) do
36
+ @handler.process(@test[:bad])
37
+ end
36
38
  end
37
39
 
38
40
  private
@@ -9,25 +9,45 @@ class TestJoinHandler < Test::Unit::TestCase
9
9
  :good => ':mod_spox!~mod_spox@host JOIN :#m',
10
10
  :bad => ':fubared JOIN fail whale'
11
11
  }
12
+ @queue = Queue.new
13
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Join')
14
+ require 'mod_spox/handlers/Join'
15
+ @handler = ModSpox::Handlers::Join.new({})
12
16
  end
13
17
 
14
- def test_expected
15
- assert_equal(:JOIN, @bot.factory.find_key(@test[:good]))
16
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
17
- assert_kind_of(ModSpox::Messages::Incoming::Join, result)
18
- assert_equal(@test[:good], result.raw_content)
19
- assert_kind_of(ModSpox::Models::Channel, result.channel)
20
- assert_kind_of(ModSpox::Models::Nick, result.nick)
21
- assert_equal('#m', result.channel.name)
22
- assert_equal('mod_spox', result.nick.nick)
23
- assert_equal('host', result.nick.host)
24
- assert_equal('host', result.nick.address)
25
- assert_equal('~mod_spox', result.nick.username)
26
- assert_equal('mod_spox!~mod_spox@host', result.nick.source)
27
- assert(result.nick.visible)
18
+ def gather(m)
19
+ @queue << m
28
20
  end
29
-
21
+
22
+ def test_indirect
23
+ @bot.factory << @test[:good]
24
+ sleep(0.1)
25
+ assert_equal(1, @queue.size)
26
+ m = @queue.pop
27
+ check_result(m)
28
+ end
29
+
30
+ def test_direct
31
+ check_result(@handler.process(@test[:good]))
32
+ end
33
+
30
34
  def test_unexpected
31
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
35
+ assert_raise(ModSpox::Exceptions::GeneralException) do
36
+ @handler.process(@test[:bad])
37
+ end
38
+ end
39
+
40
+ def check_result(m)
41
+ assert_kind_of(ModSpox::Messages::Incoming::Join, m)
42
+ assert_equal(m.raw_content, @test[:good])
43
+ assert_kind_of(ModSpox::Models::Channel, m.channel)
44
+ assert_kind_of(ModSpox::Models::Nick, m.nick)
45
+ assert_equal('#m', m.channel.name)
46
+ assert_equal('mod_spox', m.nick.nick)
47
+ assert_equal('host', m.nick.host)
48
+ assert_equal('host', m.nick.address)
49
+ assert_equal('~mod_spox', m.nick.username)
50
+ assert_equal('mod_spox!~mod_spox@host', m.nick.source)
51
+ assert(m.nick.visible)
32
52
  end
33
53
  end
@@ -9,11 +9,35 @@ class TestKickHandler < Test::Unit::TestCase
9
9
  :good => ':spax!~spox@host KICK #m spox :foo',
10
10
  :bad => ':fubared KICK fail whale'
11
11
  }
12
+ @queue = Queue.new
13
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Kick')
14
+ require 'mod_spox/handlers/Kick'
15
+ @handler = ModSpox::Handlers::Kick.new({})
12
16
  end
13
17
 
14
- def test_expected
15
- assert_equal(:KICK, @bot.factory.find_key(@test[:good]))
16
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
18
+ def gather(m)
19
+ @queue << m
20
+ end
21
+
22
+ def test_indirect
23
+ @bot.factory << @test[:good]
24
+ sleep(0.1)
25
+ assert_equal(1, @queue.size)
26
+ m = @queue.pop
27
+ check_result(m)
28
+ end
29
+
30
+ def test_direct
31
+ check_result(@handler.process(@test[:good]))
32
+ end
33
+
34
+ def test_unexpected
35
+ assert_raise(ModSpox::Exceptions::GeneralException) do
36
+ @handler.process(@test[:bad])
37
+ end
38
+ end
39
+
40
+ def check_result(result)
17
41
  assert_kind_of(ModSpox::Messages::Incoming::Kick, result)
18
42
  assert_equal(@test[:good], result.raw_content)
19
43
  assert_kind_of(ModSpox::Models::Channel, result.channel)
@@ -26,7 +50,4 @@ class TestKickHandler < Test::Unit::TestCase
26
50
  assert_equal('foo', result.reason)
27
51
  end
28
52
 
29
- def test_unexpected
30
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
31
- end
32
53
  end
@@ -12,11 +12,21 @@ class TestModeHandler < Test::Unit::TestCase
12
12
  :set_self => ':mod_spox MODE mod_spox :+iw',
13
13
  :bad => ':fubared MODE fail whale'
14
14
  }
15
+ @queue = Queue.new
16
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Mode')
17
+ require 'mod_spox/handlers/Mode'
18
+ @handler = ModSpox::Handlers::Mode.new({})
15
19
  end
16
20
 
17
- def test_single
18
- assert_equal(:MODE, @bot.factory.find_key(@test[:set_single]))
19
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:set_single])].process(@test[:set_single])
21
+ def gather(m)
22
+ @queue << m
23
+ end
24
+
25
+ def test_indirect
26
+ @bot.factory << @test[:set_single]
27
+ sleep(0.1)
28
+ assert_equal(1, @queue.size)
29
+ result = @queue.pop
20
30
  assert_kind_of(ModSpox::Messages::Incoming::Mode, result)
21
31
  assert_equal(@test[:set_single], result.raw_content)
22
32
  assert_kind_of(ModSpox::Models::Channel, result.channel)
@@ -29,10 +39,9 @@ class TestModeHandler < Test::Unit::TestCase
29
39
  assert_equal('+o', result.mode)
30
40
  assert(result.target.is_op?(result.channel))
31
41
  end
32
-
42
+
33
43
  def test_double
34
- assert_equal(:MODE, @bot.factory.find_key(@test[:set_double]))
35
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:set_double])].process(@test[:set_double])
44
+ result = @handler.process(@test[:set_double])
36
45
  assert_kind_of(ModSpox::Messages::Incoming::Mode, result)
37
46
  assert_equal(@test[:set_double], result.raw_content)
38
47
  assert_kind_of(ModSpox::Models::Channel, result.channel)
@@ -47,10 +56,9 @@ class TestModeHandler < Test::Unit::TestCase
47
56
  assert(result.target[0].is_op?(result.channel))
48
57
  assert(result.target[1].is_op?(result.channel))
49
58
  end
50
-
59
+
51
60
  def test_channel
52
- assert_equal(:MODE, @bot.factory.find_key(@test[:set_channel]))
53
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:set_channel])].process(@test[:set_channel])
61
+ result = @handler.process(@test[:set_channel])
54
62
  assert_kind_of(ModSpox::Messages::Incoming::Mode, result)
55
63
  assert_equal(@test[:set_channel], result.raw_content)
56
64
  assert_kind_of(ModSpox::Models::Channel, result.channel)
@@ -64,8 +72,7 @@ class TestModeHandler < Test::Unit::TestCase
64
72
  end
65
73
 
66
74
  def test_self
67
- assert_equal(:MODE, @bot.factory.find_key(@test[:set_self]))
68
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:set_self])].process(@test[:set_self])
75
+ result = @handler.process(@test[:set_self])
69
76
  assert_kind_of(ModSpox::Messages::Incoming::Mode, result)
70
77
  assert_equal(@test[:set_self], result.raw_content)
71
78
  assert_nil(result.channel)
@@ -78,8 +85,11 @@ class TestModeHandler < Test::Unit::TestCase
78
85
  assert(result.target.mode_set?('i'))
79
86
  assert(result.target.mode_set?('w'))
80
87
  end
81
-
88
+
82
89
  def test_unexpected
83
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
90
+ assert_raise(ModSpox::Exceptions::GeneralException) do
91
+ @handler.process(@test[:bad])
92
+ end
84
93
  end
94
+
85
95
  end
@@ -10,13 +10,37 @@ class TestNamesHandler < Test::Unit::TestCase
10
10
  :names_end => ':swiftco.wa.us.dal.net 366 spox #mod_spox :End of /NAMES list.',
11
11
  :bad => ':fubared 353 fail whale'
12
12
  }
13
+ @queue = Queue.new
14
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Names')
15
+ require 'mod_spox/handlers/Names'
16
+ @handler = ModSpox::Handlers::Names.new({})
13
17
  end
14
18
 
15
- def test_expected
16
- assert_equal('353', @bot.factory.find_key(@test[:names_start]))
17
- assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:names_start])].process(@test[:names_start]))
18
- assert_equal('366', @bot.factory.find_key(@test[:names_end]))
19
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:names_end])].process(@test[:names_end])
19
+ def gather(m)
20
+ @queue << m
21
+ end
22
+
23
+ def test_indirect
24
+ @bot.factory << @test[:names_start]
25
+ @bot.factory << @test[:names_end]
26
+ sleep(0.1)
27
+ assert_equal(1, @queue.size)
28
+ m = @queue.pop
29
+ check_result(m)
30
+ end
31
+
32
+ def test_direct
33
+ assert_nil(@handler.process(@test[:names_start]))
34
+ check_result(@handler.process(@test[:names_end]))
35
+ end
36
+
37
+ def test_unexpected
38
+ assert_raise(ModSpox::Exceptions::GeneralException) do
39
+ @handler.process(@test[:bad])
40
+ end
41
+ end
42
+
43
+ def check_result(result)
20
44
  assert_kind_of(ModSpox::Messages::Incoming::Names, result)
21
45
  assert_equal('#mod_spox', result.channel.name)
22
46
  assert_equal(5, result.nicks.size)
@@ -28,8 +52,4 @@ class TestNamesHandler < Test::Unit::TestCase
28
52
  assert(!ModSpox::Models::Nick.find_or_create(:nick => 'pizza__').is_op?(result.channel))
29
53
  assert(ModSpox::Models::Nick.find_or_create(:nick => 'spex').is_voice?(result.channel))
30
54
  end
31
-
32
- def test_unexpected
33
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
34
- end
35
55
  end
@@ -10,16 +10,42 @@ class TestNickHandler < Test::Unit::TestCase
10
10
  :bad => ':bad NICK fail'
11
11
  }
12
12
  @nick = ModSpox::Models::Nick.find_or_create(:nick => 'spox')
13
+ @queue = Queue.new
14
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Nick')
15
+ require 'mod_spox/handlers/Nick'
16
+ @handler = ModSpox::Handlers::Nick.new({})
13
17
  end
14
18
 
15
- def test_simple
16
- m = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
19
+ def gather(m)
20
+ @queue << m
21
+ end
22
+
23
+ def test_indirect
24
+ @bot.factory << @test[:good]
25
+ sleep(0.1)
26
+ assert_equal(1, @queue.size)
27
+ m = @queue.pop
28
+ check_result(m)
29
+ end
30
+
31
+ def test_direct
32
+ check_result(@handler.process(@test[:good]))
33
+ end
34
+
35
+ def test_unexpected
36
+ assert_raise(ModSpox::Exceptions::GeneralException) do
37
+ @handler.process(@test[:bad])
38
+ end
39
+ end
40
+
41
+ def check_result(m)
17
42
  assert_kind_of(ModSpox::Messages::Incoming::Nick, m)
18
43
  assert_equal(@test[:good], m.raw_content)
19
44
  assert_kind_of(ModSpox::Models::Nick, m.new_nick)
20
45
  assert_kind_of(ModSpox::Models::Nick, m.original_nick)
21
46
  assert_equal('spox', m.original_nick.nick)
22
47
  assert_equal('flock_of_deer', m.new_nick.nick)
48
+ assert_equal(m.raw_content, @test[:good])
23
49
  end
24
50
 
25
51
  def test_info_move
@@ -27,7 +53,7 @@ class TestNickHandler < Test::Unit::TestCase
27
53
  @nick.username = '~spox'
28
54
  @nick.real_name = 'foobar'
29
55
  @nick.save
30
- m = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
56
+ m = @handler.process(@test[:good])
31
57
  assert_kind_of(ModSpox::Messages::Incoming::Nick, m)
32
58
  assert_equal('spox', m.original_nick.nick)
33
59
  assert_equal('flock_of_deer', m.new_nick.nick)
@@ -41,15 +67,11 @@ class TestNickHandler < Test::Unit::TestCase
41
67
  @nick.add_channel(c)
42
68
  mode = ModSpox::Models::NickMode.find_or_create(:nick_id => @nick.pk, :channel_id => c.pk)
43
69
  mode.set_mode('o')
44
- m = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
70
+ m = @handler.process(@test[:good])
45
71
  assert_kind_of(ModSpox::Messages::Incoming::Nick, m)
46
72
  assert_equal(0, m.original_nick.channels.size)
47
73
  assert(m.new_nick.channels.size > 0)
48
74
  assert(m.new_nick.channels.include?(c))
49
75
  assert(m.new_nick.is_op?(c))
50
76
  end
51
-
52
- def test_unexpected
53
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
54
- end
55
77
  end
@@ -10,35 +10,45 @@ class TestPartHandler < Test::Unit::TestCase
10
10
  :wo_message => ':mod_spox!~mod_spox@host PART #m :',
11
11
  :bad => ':bad PART fail'
12
12
  }
13
+ @queue = Queue.new
14
+ @bot.pipeline.hook(self, :gather, 'ModSpox::Messages::Incoming::Part')
15
+ require 'mod_spox/handlers/Part'
16
+ @handler = ModSpox::Handlers::Part.new({})
13
17
  end
14
18
 
15
- def test_w_message
16
- assert_equal(:PART, @bot.factory.find_key(@test[:w_message]))
17
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:w_message])].process(@test[:w_message])
18
- assert_kind_of(ModSpox::Messages::Incoming::Part, result)
19
- assert_equal(@test[:w_message], result.raw_content)
20
- assert_kind_of(String, result.reason)
21
- assert_kind_of(ModSpox::Models::Nick, result.nick)
22
- assert_kind_of(ModSpox::Models::Channel, result.channel)
23
- assert_equal('mod_spox', result.nick.nick)
24
- assert_equal('#m', result.channel.name)
25
- assert_equal('part message', result.reason)
19
+ def gather(m)
20
+ @queue << m
21
+ end
22
+
23
+ def test_indirect
24
+ @bot.factory << @test[:w_message]
25
+ sleep(0.1)
26
+ assert_equal(1, @queue.size)
27
+ m = @queue.pop
28
+ check_result(m)
29
+ assert_equal('part message', m.reason)
30
+ assert_equal(m.raw_content, @test[:w_message])
31
+ end
32
+
33
+ def test_direct
34
+ m = @handler.process(@test[:wo_message])
35
+ check_result(m)
36
+ assert(m.reason.empty?)
37
+ assert_equal(m.raw_content, @test[:wo_message])
38
+ end
39
+
40
+ def test_unexpected
41
+ assert_raise(ModSpox::Exceptions::GeneralException) do
42
+ @handler.process(@test[:bad])
43
+ end
26
44
  end
27
45
 
28
- def test_wo_message
29
- assert_equal(:PART, @bot.factory.find_key(@test[:wo_message]))
30
- result = @bot.factory.handlers[@bot.factory.find_key(@test[:wo_message])].process(@test[:wo_message])
46
+ def check_result(result)
31
47
  assert_kind_of(ModSpox::Messages::Incoming::Part, result)
32
- assert_equal(@test[:wo_message], result.raw_content)
33
48
  assert_kind_of(String, result.reason)
34
49
  assert_kind_of(ModSpox::Models::Nick, result.nick)
35
50
  assert_kind_of(ModSpox::Models::Channel, result.channel)
36
51
  assert_equal('mod_spox', result.nick.nick)
37
52
  assert_equal('#m', result.channel.name)
38
- assert(result.reason.empty?)
39
- end
40
-
41
- def test_unexpected
42
- assert_raise(ModSpox::Exceptions::GeneralException){@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad])}
43
53
  end
44
54
  end