ruby-net-nntp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,26 @@
1
- 2007-05-17 08:09 +0200 Anton 'tony' Bangratz <tony@twincode.net> (702e55388bb4 [tip])
1
+ 2007-06-28 14:52 +0200 Anton 'tony' Bangratz <anton.bangratz@gmail.com> (96257e85a815 [tip])
2
+
3
+ * lib/net/nntp.rb, tags:
4
+ branch merge from tests, added documentation, added nntp.close
5
+
6
+ 2007-06-28 14:34 +0200 Anton 'tony' Bangratz <anton.bangratz@gmail.com> (1ca49077563a)
7
+
8
+ * lib/net/nntp.rb, script/console, tags:
9
+ bugfix for last, next, xover, grouplist
10
+ - last and next commands don't hang anymore
11
+ - xover doesn't hang and can be called without parameters, or with
12
+ groupname only
13
+ - grouplist actually returns data
14
+
15
+ 2007-05-21 11:16 +0200 Anton 'tony' Bangratz <tony@twincode.net> (168baa3c37eb)
16
+
17
+ * lib/net/nntp.rb, tags, test/functional/test_nntp.rb,
18
+ test/mock/mock_socket.rb:
19
+ - added more tests for over/xover
20
+ - completed help (mock)
21
+ - added dummy functions for over/xover selections
22
+
23
+ 2007-05-17 08:09 +0200 Anton 'tony' Bangratz <tony@twincode.net> (702e55388bb4)
2
24
 
3
25
  * .hgtags:
4
26
  tags fix
data/lib/net/nntp.rb CHANGED
@@ -9,7 +9,7 @@ require 'net/nntp_article'
9
9
 
10
10
  module Net
11
11
  class NNTP
12
- VERSION = "0.0.2"
12
+ VERSION = "0.0.3"
13
13
  include Timeout # :nodoc:
14
14
 
15
15
  # Error to indicate that NNTP Command failed gracefully
@@ -34,6 +34,11 @@ module Net
34
34
  @welcome = @socket.recv 1024
35
35
  end
36
36
 
37
+ # Closes connection. If not reconnected, subsequent calls of commands raise exceptions
38
+ def close
39
+ @socket.close unless socket.closed?
40
+ end
41
+
37
42
  # Uses authinfo commands to authenticate. Timeout for first command is set to 10 seconds.
38
43
  #
39
44
  # Returns true on success, false on failure.
@@ -88,15 +93,23 @@ module Net
88
93
  end
89
94
 
90
95
  # Issues 'XOVER' command to NNTP Server, and returns raw response. Checks if group has been selected, selects group
91
- # otherwise.
96
+ # otherwise. If no group is selected nor given, raises error.
97
+ # Parameter 'rest' can be in the form of :from => number, :to => number or :messageid => 'messageid',
98
+ # if not set, a 'next' command is issued to the server prior to the xover command
92
99
  #
93
- def xover(groupname, rest)
100
+ def xover(groupname=nil, rest=nil)
101
+ raise CommandFailedError, 'No group selected' unless @group || groupname
94
102
  group(groupname) unless (@group && @group.name == groupname)
103
+ self.next unless rest
95
104
  prefix = "xover"
96
105
  suffix = numbers_or_id(rest)
97
106
  cmd = [prefix, suffix].join ' '
98
107
  send_cmd(cmd)
99
- read_response()
108
+ response = nil
109
+ timeout(10) do
110
+ response = read_response()
111
+ end
112
+ response
100
113
  end
101
114
 
102
115
  # Issues 'LISTGROUP' command to NNTP Server, and returns raw response. Checks if group has been selected, selects group
@@ -126,6 +139,7 @@ module Net
126
139
  @overview_format = Net::NNTP.parse_overview_format list.join
127
140
  else
128
141
  create_grouplist(list)
142
+ list
129
143
  end
130
144
 
131
145
  when '501', '503', '500'
@@ -208,7 +222,7 @@ module Net
208
222
  def last_or_next(cmd)
209
223
  raise ProtocolError, "No group selected" unless @group
210
224
  send_cmd(cmd)
211
- response = read_response()[0]
225
+ response = @socket.recv(1024)
212
226
  code = response[0..2]
213
227
  article = @group.articles.create
214
228
  case code
@@ -6,244 +6,250 @@ require 'mock/mock_socket'
6
6
 
7
7
 
8
8
  module TestNet
9
- class TestNNTP < Test::Unit::TestCase
10
-
11
- def setup
12
- nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
13
- end
14
-
15
- def test_new
16
- host = 'localhost'
17
- port = '119'
18
- assert_nothing_raised do
19
- @nntp = Net::NNTP.new(host)
20
- end
21
- assert_nothing_raised do
22
- nntp_new(host, port)
23
- end
24
- end
25
-
26
- def test_connect
27
- assert_nothing_raised do
28
- @nntp.connect
29
- end
30
- end
31
-
32
- def test_help
33
- help = @nntp.help.join
34
- assert_equal '100', help[0..2]
35
- assert_equal 39, help.length
36
- end
37
-
38
- def test_authenticate
39
- assert_nothing_raised do
40
- assert nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
41
- end
42
- end
43
-
44
- def test_group
45
- assert_nothing_raised do
46
- group = @nntp.group('at.linux')
47
- assert_kind_of Net::NNTP::Group, group
48
- assert_equal 'at.linux', group.name
49
- assert_equal 12, group.article_count
50
- assert_equal 1363, group.article_first
51
- assert_equal 1375, group.article_last
52
- end
53
- end
54
-
55
- def test_xhdr
56
- headers = @nntp.xhdr('at.linux', 'subject', :from => 1363, :to => 1375)
57
- assert_equal 15, headers.length
58
- assert_equal '221', headers[0][0..2]
59
- assert_equal "1364", headers[2].split[0]
60
- header = @nntp.xhdr('at.linux', 'subject', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>").join
61
- assert_equal 49, header.length
62
- assert_equal "1375", header.split[0]
63
- end
64
-
65
- def test_xhdr_fails
66
- header = @nntp.xhdr('at.linux', '', {}).join
67
- assert_equal '502', header[0..2]
68
- assert_raise(Net::NNTP::CommandFailedError) do
69
- header = @nntp.xhdr('at.xxx', 'subject', {})
70
- end
71
- end
72
-
73
-
74
- def test_group_fails
75
- assert_raise(Net::NNTP::CommandFailedError) do
76
- group = @nntp.group('at.xxx')
77
- end
78
- end
79
-
80
- def test_xover
81
- overviews = @nntp.xover('at.linux', :from => 1363, :to => 1375)
82
- assert_equal 15, overviews.length
83
- assert_equal '224', overviews[0][0..2]
84
- end
85
-
86
- def test_xover_fails
87
- over = @nntp.xover('at.linux', :from => 1363, :to => 1375)
88
- over = @nntp.xover('at.linux', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>").join
89
- assert_equal '502', over[0..2]
90
- assert_raises(Net::NNTP::CommandFailedError) do
91
- over = @nntp.xover('at.xxx', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>")
92
- end
93
- end
94
-
95
- def test_listgroup
96
- list = @nntp.listgroup('at.linux')
97
- assert_equal 15, list.length
98
- match = /(\d{3}).*for\s+(\S+)\s/.match(list[0])
99
- assert_equal "211", match[1]
100
- assert_equal "at.linux", match[2]
101
- assert_equal "1365\r\n", list[3]
102
- end
103
-
104
- def test_list
105
- assert_respond_to @nntp, :list
106
- assert_nothing_raised do
107
- @nntp.list('overview.fmt')
108
- assert_equal 9, @nntp.overview_format.length
109
- @nntp.list()
110
- assert_not_equal 0, @nntp.grouplist.length
111
- assert_not_nil @nntp.grouplist
112
- assert_equal 'at.test', @nntp.grouplist['at.test'].name
113
- @nntp.list('active')
114
- assert_equal 'at.test', @nntp.grouplist['at.test'].name
115
- @nntp.list('active.times')
116
- @nntp.list('active.times', 'at.*')
117
- end
118
- assert_raise Net::NNTP::CommandFailedError do
119
- @nntp.list('distrib.pat', 'at.*')
120
- end
121
- end
122
-
123
- def test_article
124
- assert_raises Net::NNTP::CommandFailedError do
125
- article = @nntp.article
126
- end
127
- article = @nntp.article("<5d6be$4625ae23$51df8a12$32566@news.inode.at>")
128
- response, id, msgid = article[0].split
129
- assert_equal '220', response
130
- assert_equal '1392', id
131
- assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
132
- group = @nntp.group 'at.linux'
133
- article = @nntp.article '1392'
134
- response, id, msgid = article[0].split
135
- assert_equal '220', response
136
- assert_equal '1392', id
137
- assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
138
- end
139
-
140
- def test_head
141
- nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
142
- assert_nothing_raised do
143
- assert_respond_to @nntp, :head
144
- end
145
- assert_raise Net::NNTP::CommandFailedError do
146
- head = @nntp.head
147
- end
148
- @nntp.group 'at.linux'
149
- @io = [
150
- "221 1430 <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net> article retrieved - head follows\r\n",
151
- "Path: vietwist00.chello.at!newsfeed02.chello.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail\r\n",
152
- "Message-ID: <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>\r\n",
153
- "From: Gerhard Engler <gerhard.engler@gmx.de>\r\n",
154
- "Newsgroups: at.linux\r\n",
155
- "Subject: Re: udev_node_mknod: /dev/capi Operation not permitted\r\n",
156
- "Date: Tue, 24 Apr 2007 14:39:11 +0200\r\n",
157
- "References: <4629ee10$0$10187$9b4e6d93@newsspool4.arcor-online.net> <slrnf2np7k.a8e.tom-usenet@eristoteles.iwoars.net>\r\n",
158
- "Lines: 26\r\n",
159
- "User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)\r\n",
160
- "MIME-Version: 1.0\r\n",
161
- "In-Reply-To: <slrnf2np7k.a8e.tom-usenet@eristoteles.iwoars.net>\r\n",
162
- "Content-Type: text/plain; charset=ISO-8859-15; format=flowed\r\n",
163
- "Content-Transfer-Encoding: 7bit\r\n",
164
- "Organization: Arcor\r\n",
165
- "NNTP-Posting-Date: 24 Apr 2007 14:39:11 CEST\r\n",
166
- "NNTP-Posting-Host: 6cf11d8c.newsspool1.arcor-online.net\r\n",
167
- "X-Trace: DXC=Cd=D_AR>:`a^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRaFl8W>\BH3Yb7K@fQgPi`FgUTEAfnAR\Ta@JWJ8E:^d<ob]cIfD6hVgh<SdIn0f]3?i\r\n",
168
- "X-Complaints-To: usenet-abuse@arcor.de\r\n",
169
- "Xref: sensor.twincode.net at.linux:1430\r\n",
170
- ".\r\n"
171
- ]
172
- head = @nntp.head
173
- assert_kind_of Array, head
174
- response, id, msgid = head[0].split
175
- assert_equal '221', response
176
- assert_equal '1430', id
177
- assert_equal '<462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>', msgid
178
- end
179
-
180
- def test_body
181
- assert_raises Net::NNTP::CommandFailedError do
182
- body = @nntp.body
183
- end
184
- body = @nntp.body("<5d6be$4625ae23$51df8a12$32566@news.inode.at>")
185
- response, id, msgid = body[0].split
186
- assert_equal '222', response
187
- assert_equal '1392', id
188
- assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
189
- group = @nntp.group 'at.linux'
190
- body = @nntp.body '1392'
191
- response, id, msgid = body[0].split
192
- assert_equal '222', response
193
- assert_equal '1392', id
194
- assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
195
- end
196
-
197
- def test_stat
198
- assert_nothing_raised do
199
- assert_respond_to @nntp, :stat
200
- end
201
- end
202
-
203
- def test_last
204
- assert_raise Net::NNTP::ProtocolError do
205
- last = @nntp.last
206
- end
207
- @nntp.group 'at.linux'
208
- assert_raise Net::NNTP::CommandFailedError do
209
- last = @nntp.last
210
- end
211
- @nntp.next
212
- @nntp.next
213
- last = @nntp.last
214
- assert_kind_of String, last
215
- response, article, msgid, rest = last.split
216
- assert_equal "223", response
217
- assert_equal "1363", article
218
- end
219
-
220
- def test_next
221
- assert_raise Net::NNTP::ProtocolError do
222
- anext = @nntp.next
223
- end
224
- @nntp.group 'at.linux'
225
- anext = @nntp.next
226
- assert_kind_of String, anext
227
- response, article, msgid, rest = anext.split
228
- assert_equal "223", response
229
- assert_equal "1363", article
230
- assert_equal "<example.msgid@fake.host>", msgid
231
- anext = @nntp.next
232
- response, article, msgid, rest = anext.split
233
- assert_equal "1364", article
234
- end
235
-
236
- private
237
- def nntp_new(host, port=119)
238
- @nntp = Net::NNTP.new(host, port)
239
- end
240
- def nntp_connect_and_auth(host, port, user, pass)
241
- @nntp = Net::NNTP.new(host, port)
242
- @nntp.instance_variable_set :@socket_class, MockSocket
243
- @nntp.connect
244
- @nntp.socket.activate
245
- @nntp.authenticate(user, pass)
246
- end
9
+ class TestNNTP < Test::Unit::TestCase
10
+
11
+ def setup
12
+ nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
13
+ end
14
+
15
+ def test_new
16
+ host = 'localhost'
17
+ port = '119'
18
+ assert_nothing_raised do
19
+ @nntp = Net::NNTP.new(host)
20
+ end
21
+ assert_nothing_raised do
22
+ nntp_new(host, port)
23
+ end
24
+ end
25
+
26
+ def test_connect
27
+ assert_nothing_raised do
28
+ @nntp.connect
29
+ end
30
+ end
31
+
32
+ def test_help
33
+ help = @nntp.help.join
34
+ assert_equal '100', help[0..2]
35
+ assert_equal 473, help.length
36
+ end
37
+
38
+ def test_authenticate
39
+ assert_nothing_raised do
40
+ assert nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
41
+ end
42
+ end
43
+
44
+ def test_group
45
+ assert_nothing_raised do
46
+ group = @nntp.group('at.linux')
47
+ assert_kind_of Net::NNTP::Group, group
48
+ assert_equal 'at.linux', group.name
49
+ assert_equal 12, group.article_count
50
+ assert_equal 1363, group.article_first
51
+ assert_equal 1375, group.article_last
52
+ end
53
+ end
54
+
55
+ def test_xhdr
56
+ headers = @nntp.xhdr('at.linux', 'subject', :from => 1363, :to => 1375)
57
+ assert_equal 15, headers.length
58
+ assert_equal '221', headers[0][0..2]
59
+ assert_equal "1364", headers[2].split[0]
60
+ header = @nntp.xhdr('at.linux', 'subject', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>").join
61
+ assert_equal 49, header.length
62
+ assert_equal "1375", header.split[0]
63
+ end
64
+
65
+ def test_xhdr_fails
66
+ header = @nntp.xhdr('at.linux', '', {}).join
67
+ assert_equal '502', header[0..2]
68
+ assert_raise(Net::NNTP::CommandFailedError) do
69
+ header = @nntp.xhdr('at.xxx', 'subject', {})
70
+ end
71
+ end
72
+
73
+
74
+ def test_group_fails
75
+ assert_raise(Net::NNTP::CommandFailedError) do
76
+ group = @nntp.group('at.xxx')
77
+ end
78
+ end
79
+
80
+ def test_xover
81
+ overviews = @nntp.xover('at.linux', :from => 1363, :to => 1375)
82
+ assert_equal 15, overviews.length
83
+ assert_equal '224', overviews[0][0..2]
84
+ end
85
+
86
+ def test_over_or_xover
87
+ assert @nntp.has_xover?
88
+ assert @nntp.has_over?
89
+ end
90
+
91
+ def test_xover_fails
92
+ over = @nntp.xover('at.linux', :from => 1363, :to => 1375)
93
+ over = @nntp.xover('at.linux', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>").join
94
+ assert_equal '502', over[0..2]
95
+ assert_raises(Net::NNTP::CommandFailedError) do
96
+ over = @nntp.xover('at.xxx', :message_id => "<slrnf26akq.ci5.hjp-usenet2@zeno.hjp.at>")
97
+ end
98
+ end
99
+
100
+ def test_listgroup
101
+ list = @nntp.listgroup('at.linux')
102
+ assert_equal 15, list.length
103
+ match = /(\d{3}).*f\or\s+(\S+)\s/.match(list[0])
104
+ assert_equal "211", match[1]
105
+ assert_equal "at.linux", match[2]
106
+ assert_equal "1365\r\n", list[3]
107
+ end
108
+
109
+ def test_list
110
+ assert_respond_to @nntp, :list
111
+ assert_nothing_raised do
112
+ @nntp.list('overview.fmt')
113
+ assert_equal 9, @nntp.overview_format.length
114
+ @nntp.list()
115
+ assert_not_equal 0, @nntp.grouplist.length
116
+ assert_not_nil @nntp.grouplist
117
+ assert_equal 'at.test', @nntp.grouplist['at.test'].name
118
+ @nntp.list('active')
119
+ assert_equal 'at.test', @nntp.grouplist['at.test'].name
120
+ @nntp.list('active.times')
121
+ @nntp.list('active.times', 'at.*')
122
+ end
123
+ assert_raise Net::NNTP::CommandFailedError do
124
+ @nntp.list('distrib.pat', 'at.*')
125
+ end
126
+ end
127
+
128
+ def test_article
129
+ assert_raises Net::NNTP::CommandFailedError do
130
+ article = @nntp.article
131
+ end
132
+ article = @nntp.article("<5d6be$4625ae23$51df8a12$32566@news.inode.at>")
133
+ response, id, msgid = article[0].split
134
+ assert_equal '220', response
135
+ assert_equal '1392', id
136
+ assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
137
+ group = @nntp.group 'at.linux'
138
+ article = @nntp.article '1392'
139
+ response, id, msgid = article[0].split
140
+ assert_equal '220', response
141
+ assert_equal '1392', id
142
+ assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
143
+ end
144
+
145
+ def test_head
146
+ nntp_connect_and_auth('localhost', 119, 'dummy', 'test')
147
+ assert_nothing_raised do
148
+ assert_respond_to @nntp, :head
149
+ end
150
+ assert_raise Net::NNTP::CommandFailedError do
151
+ head = @nntp.head
152
+ end
153
+ @nntp.group 'at.linux'
154
+ @io = [
155
+ "221 1430 <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net> article retrieved - head follows\r\n",
156
+ "Path: vietwist00.chello.at!newsfeed02.chello.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail\r\n",
157
+ "Message-ID: <462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>\r\n",
158
+ "From: Gerhard Engler <gerhard.engler@gmx.de>\r\n",
159
+ "Newsgroups: at.linux\r\n",
160
+ "Subject: Re: udev_node_mknod: /dev/capi Operation not permitted\r\n",
161
+ "Date: Tue, 24 Apr 2007 14:39:11 +0200\r\n",
162
+ "References: <4629ee10$0$10187$9b4e6d93@newsspool4.arcor-online.net> <slrnf2np7k.a8e.tom-usenet@eristoteles.iwoars.net>\r\n",
163
+ "Lines: 26\r\n",
164
+ "User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)\r\n",
165
+ "MIME-Version: 1.0\r\n",
166
+ "In-Reply-To: <slrnf2np7k.a8e.tom-usenet@eristoteles.iwoars.net>\r\n",
167
+ "Content-Type: text/plain; charset=ISO-8859-15; format=flowed\r\n",
168
+ "Content-Transfer-Encoding: 7bit\r\n",
169
+ "Organization: Arcor\r\n",
170
+ "NNTP-Posting-Date: 24 Apr 2007 14:39:11 CEST\r\n",
171
+ "NNTP-Posting-Host: 6cf11d8c.newsspool1.arcor-online.net\r\n",
172
+ "X-Trace: DXC=Cd=D_AR>:`a^Y=RbYBPl4`ic==]BZ:afn4Fo<]lROoRaFl8W>\BH3Yb7K@fQgPi`FgUTEAfnAR\Ta@JWJ8E:^d<ob]cIfD6hVgh<SdIn0f]3?i\r\n",
173
+ "X-Complaints-To: usenet-abuse@arcor.de\r\n",
174
+ "Xref: sensor.twincode.net at.linux:1430\r\n",
175
+ ".\r\n"
176
+ ]
177
+ head = @nntp.head
178
+ assert_kind_of Array, head
179
+ response, id, msgid = head[0].split
180
+ assert_equal '221', response
181
+ assert_equal '1430', id
182
+ assert_equal '<462dfa6f$0$23135$9b4e6d93@newsspool1.arcor-online.net>', msgid
183
+ end
184
+
185
+ def test_body
186
+ assert_raises Net::NNTP::CommandFailedError do
187
+ body = @nntp.body
188
+ end
189
+ body = @nntp.body("<5d6be$4625ae23$51df8a12$32566@news.inode.at>")
190
+ response, id, msgid = body[0].split
191
+ assert_equal '222', response
192
+ assert_equal '1392', id
193
+ assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
194
+ group = @nntp.group 'at.linux'
195
+ body = @nntp.body '1392'
196
+ response, id, msgid = body[0].split
197
+ assert_equal '222', response
198
+ assert_equal '1392', id
199
+ assert_equal "<5d6be$4625ae23$51df8a12$32566@news.inode.at>", msgid
200
+ end
201
+
202
+ def test_stat
203
+ assert_nothing_raised do
204
+ assert_respond_to @nntp, :stat
205
+ end
206
+ end
207
+
208
+ def test_last
209
+ assert_raise Net::NNTP::ProtocolError do
210
+ last = @nntp.last
211
+ end
212
+ @nntp.group 'at.linux'
213
+ assert_raise Net::NNTP::CommandFailedError do
214
+ last = @nntp.last
215
+ end
216
+ @nntp.next
217
+ @nntp.next
218
+ last = @nntp.last
219
+ assert_kind_of String, last
220
+ response, article, msgid, rest = last.split
221
+ assert_equal "223", response
222
+ assert_equal "1363", article
223
+ end
224
+
225
+ def test_next
226
+ assert_raise Net::NNTP::ProtocolError do
227
+ anext = @nntp.next
228
+ end
229
+ @nntp.group 'at.linux'
230
+ anext = @nntp.next
231
+ assert_kind_of String, anext
232
+ response, article, msgid, rest = anext.split
233
+ assert_equal "223", response
234
+ assert_equal "1363", article
235
+ assert_equal "<example.msgid@fake.host>", msgid
236
+ anext = @nntp.next
237
+ response, article, msgid, rest = anext.split
238
+ assert_equal "1364", article
239
+ end
240
+
241
+ private
242
+ def nntp_new(host, port=119)
243
+ @nntp = Net::NNTP.new(host, port)
244
+ end
245
+ def nntp_connect_and_auth(host, port, user, pass)
246
+ @nntp = Net::NNTP.new(host, port)
247
+ @nntp.instance_variable_set :@socket_class, MockSocket
248
+ @nntp.connect
249
+ @nntp.socket.activate
250
+ @nntp.authenticate(user, pass)
251
+ end
252
+ end
247
253
  end
248
254
 
249
- end
255
+
@@ -114,7 +114,29 @@ class MockSocket < Test::Unit::MockObject( TCPSocket )
114
114
  @io = ["501 Bad Command Usage"]
115
115
  end
116
116
  when "help\r\n" then
117
- @io = ["100 Legal commands on THIS server:\r\n", ".\r\n"]
117
+ @io = [
118
+ "100 Legal commands on THIS server:\r\n",
119
+ "ARTICLE [<Message-ID>|<Number>]\r\n",
120
+ "BODY [<Message-ID>|<Number>]\r\n",
121
+ "DATE\r\n",
122
+ "GROUP <Newsgroup>\r\n",
123
+ "HDR <Header> <Message-ID>|<Range>\r\n",
124
+ "HEAD [<Message-ID>|<Number>]\r\n",
125
+ "HELP\r\n",
126
+ "LAST\r\n",
127
+ "LIST [ACTIVE|NEWSGROUPS] [<Wildmat>]]\r\n",
128
+ "LIST [ACTIVE.TIMES|EXTENSIONS|OVERVIEW.FMT]\r\n",
129
+ "LISTGROUP <Newsgroup>\r\n",
130
+ "MODE READER\r\n",
131
+ "NEWGROUPS <yymmdd> <hhmmss> [GMT]\r\n",
132
+ "NEXT\r\n",
133
+ "POST\r\n",
134
+ "OVER <Range>\r\n",
135
+ "SLAVE\r\n",
136
+ "STAT [<Message-ID>|<Number>]\r\n",
137
+ "XHDR <Header> <Message-ID>|<Range>\r\n",
138
+ "XOVER <Range>\r\n",
139
+ ".\r\n"]
118
140
  when /^next/i
119
141
  if @group_selected
120
142
  if @last_article
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ruby-net-nntp
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-05-17 00:00:00 +02:00
6
+ version: 0.0.3
7
+ date: 2007-06-28 00:00:00 +02:00
8
8
  summary: Net::XXX style NNTP Library for easy access.
9
9
  require_paths:
10
10
  - lib
@@ -30,9 +30,9 @@ authors:
30
30
  - Anton Bangratz
31
31
  files:
32
32
  - lib/net
33
- - lib/net/nntp.rb
34
33
  - lib/net/nntp_article.rb
35
34
  - lib/net/nntp_group.rb
35
+ - lib/net/nntp.rb
36
36
  - test/functional
37
37
  - test/functional/test_nntp.rb
38
38
  - test/mock