ircguerilla-irc 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/lib/irc/client/client_error.rb +35 -0
  2. data/lib/irc/client/command_handler.rb +113 -0
  3. data/lib/irc/client/connected_state.rb +95 -0
  4. data/lib/irc/client/connection.rb +119 -0
  5. data/lib/irc/client/connection_listener.rb +97 -0
  6. data/lib/irc/client/connection_state.rb +88 -0
  7. data/lib/irc/client/context.rb +250 -0
  8. data/lib/irc/client/disconnected_state.rb +132 -0
  9. data/lib/irc/client/message_handler.rb +87 -0
  10. data/lib/irc/client/registered_state.rb +90 -0
  11. data/lib/irc/client/unregistered_state.rb +113 -0
  12. data/lib/irc/commands/command.rb +57 -0
  13. data/lib/irc/commands/invalid_command.rb +35 -0
  14. data/lib/irc/commands/join_command.rb +122 -0
  15. data/lib/irc/commands/nick_command.rb +86 -0
  16. data/lib/irc/commands/part_command.rb +84 -0
  17. data/lib/irc/commands/password_command.rb +72 -0
  18. data/lib/irc/commands/ping_command.rb +79 -0
  19. data/lib/irc/commands/pong_command.rb +68 -0
  20. data/lib/irc/commands/quit_command.rb +77 -0
  21. data/lib/irc/commands/user_command.rb +105 -0
  22. data/lib/irc/messages/codes.rb +186 -0
  23. data/lib/irc/messages/error_join_message.rb +72 -0
  24. data/lib/irc/messages/error_message.rb +101 -0
  25. data/lib/irc/messages/factory.rb +122 -0
  26. data/lib/irc/messages/invalid_message.rb +35 -0
  27. data/lib/irc/messages/join_message.rb +130 -0
  28. data/lib/irc/messages/message.rb +110 -0
  29. data/lib/irc/messages/nick_message.rb +93 -0
  30. data/lib/irc/messages/notice_message.rb +87 -0
  31. data/lib/irc/messages/part_message.rb +95 -0
  32. data/lib/irc/messages/ping_message.rb +101 -0
  33. data/lib/irc/messages/pong_message.rb +89 -0
  34. data/lib/irc/messages/private_message.rb +121 -0
  35. data/lib/irc/models/bot.rb +159 -0
  36. data/lib/irc/models/channel.rb +158 -0
  37. data/lib/irc/models/network.rb +252 -0
  38. data/lib/irc/models/packet.rb +84 -0
  39. data/lib/irc/models/server.rb +116 -0
  40. data/lib/irc/models/user.rb +112 -0
  41. data/test/functional/irc/client/connection_test.rb +118 -0
  42. data/test/functional/irc/client/context_test.rb +126 -0
  43. data/test/test_helper.rb +32 -0
  44. data/test/unit/irc/client/command_handler_test.rb +137 -0
  45. data/test/unit/irc/commands/join_command_test.rb +72 -0
  46. data/test/unit/irc/commands/nick_command_test.rb +35 -0
  47. data/test/unit/irc/commands/part_command_test.rb +52 -0
  48. data/test/unit/irc/commands/password_command_test.rb +35 -0
  49. data/test/unit/irc/commands/ping_command_test.rb +36 -0
  50. data/test/unit/irc/commands/pong_command_test.rb +36 -0
  51. data/test/unit/irc/commands/quit_command_test.rb +35 -0
  52. data/test/unit/irc/commands/user_command_test.rb +35 -0
  53. data/test/unit/irc/messages/error_join_message_test.rb +45 -0
  54. data/test/unit/irc/messages/factory_test.rb +62 -0
  55. data/test/unit/irc/messages/join_message_test.rb +46 -0
  56. data/test/unit/irc/messages/message_test.rb +56 -0
  57. data/test/unit/irc/messages/nick_message_test.rb +48 -0
  58. data/test/unit/irc/messages/notice_message_test.rb +43 -0
  59. data/test/unit/irc/messages/part_message_test.rb +47 -0
  60. data/test/unit/irc/messages/ping_message_test.rb +57 -0
  61. data/test/unit/irc/messages/pong_message_test.rb +57 -0
  62. data/test/unit/irc/messages/private_message_test.rb +42 -0
  63. data/test/unit/irc/models/bot_test.rb +85 -0
  64. data/test/unit/irc/models/channel_test.rb +90 -0
  65. data/test/unit/irc/models/network_test.rb +210 -0
  66. data/test/unit/irc/models/packet_test.rb +38 -0
  67. data/test/unit/irc/models/server_test.rb +54 -0
  68. data/test/unit/irc/models/user_test.rb +67 -0
  69. metadata +111 -0
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: packet.rb 85 2006-08-13 11:42:07Z roman $
25
+ #
26
+ require 'irc/models/user'
27
+
28
+ module IRC
29
+
30
+ module Models
31
+
32
+ class Packet
33
+
34
+ attr_reader :bot
35
+ attr_reader :number
36
+
37
+ attr_accessor :description
38
+ attr_accessor :size_in_bytes
39
+ attr_accessor :number_of_downloads
40
+
41
+ def initialize(attributes)
42
+
43
+ raise ArgumentError.new("Can't create a new packet. The :bot attribute is missing.") if attributes[:bot] == nil
44
+ @bot = attributes[:bot]
45
+
46
+ raise ArgumentError.new("Can't create a new packet. The :number attribute is missing.") if attributes[:number] == nil
47
+ @number = attributes[:number]
48
+
49
+ self.description = attributes[:description]
50
+ self.size_in_bytes = attributes[:size_in_bytes]
51
+ self.number_of_downloads = attributes[:number_of_downloads]
52
+
53
+ end
54
+
55
+ def merge(other)
56
+ # @bot = other.bot
57
+ @number = other.number
58
+ self.description = other.description
59
+ self.size_in_bytes = other.size_in_bytes
60
+ self.number_of_downloads = other.number_of_downloads
61
+ end
62
+
63
+ def ==(other)
64
+ return eql?(other)
65
+ end
66
+
67
+ # Returns true if the other Packet object is equal to the current.
68
+ def eql?(other)
69
+ return other.instance_of?(Packet) && bot == other.bot && number == other.number && description == other.description
70
+ end
71
+
72
+ def hash
73
+ return key.hash
74
+ end
75
+
76
+ def key
77
+ return "#{bot.network.name.strip}|#{bot.nick.strip}|#{number.to_s}".downcase
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: server.rb 85 2006-08-13 11:42:07Z roman $
25
+ #
26
+ require 'irc/models/network'
27
+
28
+ module IRC
29
+
30
+ module Models
31
+
32
+ class Server
33
+
34
+ DEFAULT_PORT = 6667
35
+
36
+ attr_reader :network
37
+ attr_reader :hostname
38
+ attr_reader :port
39
+
40
+ attr_accessor :password
41
+ attr_accessor :last_connect
42
+ attr_accessor :last_disconnect
43
+
44
+ # Creates a new server object with a hostname, an optional
45
+ # port and optinal password, that belongs to a network.
46
+ def initialize(attributes)
47
+
48
+ raise ArgumentError.new("Can't create a new server object. The :network attribute is missing.") if attributes[:network] == nil
49
+ @network = attributes[:network]
50
+
51
+ raise ArgumentError.new("Can't create a new server object. The :hostname attribute is missing.") if attributes[:hostname] == nil
52
+ @hostname = attributes[:hostname].strip
53
+
54
+ @port = attributes[:port] || DEFAULT_PORT
55
+
56
+ self.password = attributes[:password]
57
+ self.last_connect = attributes[:last_connect]
58
+ self.last_disconnect = attributes[:last_disconnect]
59
+
60
+ end
61
+
62
+ def ==(other)
63
+ return eql?(other)
64
+ end
65
+
66
+ # Returns true if the other Server object is equal to the
67
+ # current.
68
+ def eql?(other)
69
+ return other.instance_of?(Server) && network == other.network && hostname == other.hostname && port == other.port
70
+ end
71
+
72
+ def hash
73
+ return key.hash
74
+ end
75
+
76
+ def key
77
+ return "#{network.name}|#{hostname}|#{port}".downcase
78
+ end
79
+
80
+ def merge(other)
81
+
82
+ # @network = other.network
83
+ @hostname = other.hostname
84
+ @port = other.port
85
+
86
+ self.password = other.password
87
+ self.last_connect = other.last_connect
88
+ self.last_disconnect = other.last_disconnect
89
+
90
+ end
91
+
92
+ # Returns the name of the server. If the port is different from the
93
+ # default IRC port the port number is also appended.
94
+ def to_s
95
+ return hostname
96
+ end
97
+
98
+ # Returns the name of the server. If the port is different from the
99
+ # default IRC port the port number is also appended.
100
+ def to_str
101
+ return to_s
102
+ end
103
+
104
+ def to_xml
105
+ server = REXML::Element.new("Server")
106
+ server.add_element("Hostname").add_text(REXML::CData.new(hostname))
107
+ server.add_element("Port").add_text(port.to_s)
108
+ server.add_element("Password").add_text(REXML::CData.new(password)) if password != nil
109
+ return server
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: user.rb 85 2006-08-13 11:42:07Z roman $
25
+ #
26
+ require 'irc/models/network'
27
+
28
+ module IRC
29
+
30
+ module Models
31
+
32
+ class User
33
+
34
+ attr_reader :network
35
+ attr_reader :nick
36
+
37
+ attr_accessor :login
38
+ attr_accessor :hostname
39
+ attr_accessor :realname
40
+
41
+ def initialize(attributes)
42
+
43
+ raise ArgumentError.new("Can't create a new user object. The :network attribute is missing.") if attributes[:network] == nil
44
+ @network = attributes[:network]
45
+
46
+ raise ArgumentError.new("Can't create a new user object. The :nick attribute is missing.") if attributes[:nick] == nil
47
+ @nick = attributes[:nick].strip
48
+
49
+ @login = attributes[:login]
50
+ @hostname = attributes[:hostname]
51
+
52
+ @channels = Hash.new
53
+
54
+ end
55
+
56
+ def add_channel(channel)
57
+ @channels[channel] = channel
58
+ end
59
+
60
+ def channels
61
+ return @channels.values
62
+ end
63
+
64
+ def eql?(other)
65
+ return (other.instance_of?(Bot) || other.instance_of?(User)) && network == other.network && nick == other.nick
66
+ end
67
+
68
+ def hash
69
+ return key.hash
70
+ end
71
+
72
+ def key
73
+ return "#{network.name.strip}|#{nick.strip}".downcase
74
+ end
75
+
76
+ def merge(other)
77
+
78
+ @nick = other.nick
79
+
80
+ self.login = other.login
81
+ self.hostname = other.hostname
82
+
83
+ other.channels.each do |other_channel|
84
+ channel = network.lookup_or_create_channel(other_channel.name)
85
+ add_channel(channel)
86
+ end
87
+
88
+ end
89
+
90
+ def remove_channel(channel)
91
+ return @channels.delete(channel)
92
+ end
93
+
94
+ # Returns the nick name of the user.
95
+ def to_s
96
+ return @nick
97
+ end
98
+
99
+ # Returns the nick name of the user.
100
+ def to_str
101
+ return to_s
102
+ end
103
+
104
+ def ==(other)
105
+ return eql?(other)
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id$
25
+ #
26
+ require 'stringio'
27
+ require 'irc/client/connection'
28
+ require 'irc/client/disconnected_state'
29
+ require 'irc/models/network'
30
+ require 'test/unit'
31
+ require 'timeout'
32
+
33
+ require File.dirname(__FILE__) + '/../../../test_helper'
34
+
35
+ @response = StringIO.new
36
+
37
+
38
+ class IRC::Client::ConnectionTest < Test::Unit::TestCase
39
+
40
+ def setup
41
+
42
+ # Initialize the network, channel & server that is used for testing.
43
+ network = IRC::Models::Network.new(:name => "Efnet")
44
+ @channel = network.create_channel("#MP3_RAP_N_REGGAE")
45
+ @server = network.create_server("irc.efnet.net")
46
+
47
+ # Initialize the connection connection.
48
+ @connection = IRC::Client::Connection::Context.new("fumanshu")
49
+
50
+ end
51
+
52
+ def test_connect
53
+
54
+ # The connection shouldn't be connected now.
55
+ assert !@connection.connected?
56
+
57
+ # Connect to the server and wait until the connection is in the unregistered state.
58
+ Timeout::timeout(IRC::Client::Connection::MAX_CONNECTION_TIMEOUT_IN_SEC) do
59
+ @connection.connect(@server)
60
+ while !@connection.connected? do sleep 0.1; end
61
+ assert @connection.connected?
62
+ end
63
+
64
+ # Wait until the connection is registered.
65
+ Timeout::timeout(5) do
66
+ while !@connection.registered? do sleep 0.1; end
67
+ assert @connection.registered?
68
+ end
69
+
70
+ # Disconnect and wait until the connection is in the disconnected state.
71
+ Timeout::timeout(5) do
72
+ @connection.disconnect
73
+ while @connection.connected? do sleep 0.1; end
74
+ assert !@connection.connected?
75
+ end
76
+
77
+ end
78
+
79
+ def test_join_and_part
80
+
81
+ # The connection shouldn't be connected now.
82
+ assert !@connection.connected?
83
+
84
+ # Connect to the server and wait until the connection is in the unregistered state.
85
+ Timeout::timeout(IRC::Client::Connection::MAX_CONNECTION_TIMEOUT_IN_SEC) do
86
+ @connection.connect(@server)
87
+ while !@connection.connected? do sleep 0.1; end
88
+ assert @connection.connected?
89
+ end
90
+
91
+ # Wait until the connection is registered.
92
+ Timeout::timeout(5) do
93
+ while !@connection.registered? do sleep 0.1; end
94
+ assert @connection.registered?
95
+ end
96
+
97
+ # Join a channel & wait until the channel is joined and the block was called.
98
+ Timeout::timeout(5) do
99
+ @connection.join(@channel)
100
+ while !@connection.joined?(@channel) do sleep 0.1 end
101
+ end
102
+
103
+ # Leave the joined channel.
104
+ Timeout::timeout(5) do
105
+ @connection.part(@channel)
106
+ while @connection.joined?(@channel) do sleep 0.1 end
107
+ end
108
+
109
+ # Disconnect and wait until the connection is in the disconnected state.
110
+ Timeout::timeout(5) do
111
+ @connection.disconnect
112
+ while @connection.connected? do sleep 0.1; end
113
+ assert !@connection.connected?
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ #
24
+ # $Id: context_test.rb 94 2006-08-13 21:40:40Z roman $
25
+ #
26
+ require 'stringio'
27
+ require 'irc/client/context'
28
+ require 'irc/client/disconnected_state'
29
+ require 'irc/models/network'
30
+ require 'test/unit'
31
+ require 'timeout'
32
+
33
+ require File.dirname(__FILE__) + '/../../../test_helper'
34
+
35
+ @response = StringIO.new
36
+
37
+
38
+ class IRC::Client::ContextTest < Test::Unit::TestCase
39
+
40
+ def setup
41
+
42
+ # Initialize the network, channel & server that is used for testing.
43
+ network = IRC::Models::Network.new(:name => "Efnet")
44
+ @channel = network.create_channel("#ircguerilla")
45
+ @server = network.create_server("irc.efnet.net")
46
+
47
+ # Initialize the connection context.
48
+ @context = IRC::Client::Connection::Context.new("fumanshu")
49
+
50
+ end
51
+
52
+ def test_connect
53
+
54
+ # The context should be in the disconnected state.
55
+ assert @context.state.instance_of?(IRC::Client::DisconnectedState)
56
+
57
+ # The context shouldn't be connected now.
58
+ assert !@context.connected?
59
+
60
+ # Connect to the server and wait until the context is in the unregistered state.
61
+ Timeout::timeout(IRC::Client::Connection::MAX_CONNECTION_TIMEOUT_IN_SEC) do
62
+ @context.connect(@server)
63
+ while @context.state.instance_of?(IRC::Client::DisconnectedState) do sleep 0.1; end
64
+ assert @context.state.instance_of?(IRC::Client::UnregisteredState)
65
+ end
66
+
67
+ # The context should be connected now.
68
+ assert @context.connected?
69
+
70
+ # Wait until the connection is registered.
71
+ Timeout::timeout(5) do
72
+ while @context.state.instance_of?(IRC::Client::UnregisteredState) do sleep 0.1; end
73
+ assert @context.state.instance_of?(IRC::Client::RegisteredState)
74
+ end
75
+
76
+ IRC::Commands::Command.new("JOIN a").send(@context)
77
+ sleep 5
78
+
79
+ # Disconnect and wait until the context is in the disconnected state.
80
+ Timeout::timeout(5) do
81
+ @context.disconnect
82
+ assert @context.state.instance_of?(IRC::Client::DisconnectedState)
83
+ end
84
+
85
+ end
86
+
87
+ def test_join_and_part
88
+
89
+ # The context should be in the disconnected state.
90
+ assert @context.state.instance_of?(IRC::Client::DisconnectedState)
91
+
92
+ # Connect to the server and wait until the context is in the unregistered state.
93
+ Timeout::timeout(IRC::Client::Connection::MAX_CONNECTION_TIMEOUT_IN_SEC) do
94
+ @context.connect(@server)
95
+ while @context.state.instance_of?(IRC::Client::DisconnectedState) do sleep 0.1; end
96
+ assert @context.state.instance_of?(IRC::Client::UnregisteredState)
97
+ end
98
+
99
+ # Wait until the connection is registered.
100
+ Timeout::timeout(5) do
101
+ while @context.state.instance_of?(IRC::Client::UnregisteredState) do sleep 0.1; end
102
+ assert @context.state.instance_of?(IRC::Client::RegisteredState)
103
+ end
104
+
105
+ # Join a channel & wait until the channel is joined and the block was called.
106
+ Timeout::timeout(5) do
107
+ @context.join(@channel)
108
+ while !@context.joined?(@channel) do sleep 0.1 end
109
+ end
110
+
111
+ # Leave the joined channel.
112
+ Timeout::timeout(5) do
113
+ @context.part(@channel)
114
+ while @context.joined?(@channel) do sleep 0.1 end
115
+ end
116
+
117
+ # Disconnect and wait until the context is in the disconnected state.
118
+ Timeout::timeout(5) do
119
+ @context.disconnect
120
+ assert @context.state.instance_of?(IRC::Client::DisconnectedState)
121
+ end
122
+
123
+ end
124
+
125
+
126
+ end