vines 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README +1 -1
  2. data/Rakefile +12 -2
  3. data/conf/config.rb +1 -0
  4. data/lib/vines/config.rb +8 -0
  5. data/lib/vines/contact.rb +2 -4
  6. data/lib/vines/error.rb +1 -1
  7. data/lib/vines/router.rb +26 -18
  8. data/lib/vines/stanza/presence.rb +3 -1
  9. data/lib/vines/stanza.rb +8 -1
  10. data/lib/vines/stream/client/bind.rb +9 -1
  11. data/lib/vines/stream/client/session.rb +146 -0
  12. data/lib/vines/stream/client.rb +19 -78
  13. data/lib/vines/stream/component.rb +6 -2
  14. data/lib/vines/stream/http/auth.rb +22 -0
  15. data/lib/vines/stream/http/bind.rb +32 -0
  16. data/lib/vines/stream/http/bind_restart.rb +36 -0
  17. data/lib/vines/stream/http/ready.rb +25 -0
  18. data/lib/vines/stream/http/request.rb +33 -0
  19. data/lib/vines/stream/http/session.rb +116 -0
  20. data/lib/vines/stream/http/sessions.rb +65 -0
  21. data/lib/vines/stream/http/start.rb +23 -0
  22. data/lib/vines/stream/http.rb +119 -77
  23. data/lib/vines/stream/server.rb +8 -3
  24. data/lib/vines/stream/state.rb +6 -1
  25. data/lib/vines/stream.rb +31 -19
  26. data/lib/vines/user.rb +2 -4
  27. data/lib/vines/version.rb +1 -1
  28. data/lib/vines.rb +10 -4
  29. data/test/config_test.rb +34 -33
  30. data/test/contact_test.rb +42 -0
  31. data/test/error_test.rb +2 -2
  32. data/test/jid_test.rb +7 -7
  33. data/test/kit_test.rb +10 -10
  34. data/test/rake_test_loader.rb +9 -0
  35. data/test/router_test.rb +4 -3
  36. data/test/stanza/iq/roster_test.rb +8 -10
  37. data/test/stanza/iq/session_test.rb +2 -3
  38. data/test/stanza/iq/vcard_test.rb +4 -5
  39. data/test/stanza/message_test.rb +17 -11
  40. data/test/stanza/presence/subscribe_test.rb +3 -4
  41. data/test/storage/couchdb_test.rb +9 -10
  42. data/test/storage/ldap_test.rb +30 -37
  43. data/test/storage/local_test.rb +6 -6
  44. data/test/storage/redis_test.rb +6 -6
  45. data/test/storage/sql_test.rb +5 -5
  46. data/test/storage/storage_tests.rb +11 -11
  47. data/test/storage_test.rb +4 -5
  48. data/test/stream/client/auth_test.rb +15 -16
  49. data/test/stream/client/ready_test.rb +4 -5
  50. data/test/stream/client/session_test.rb +21 -0
  51. data/test/stream/component/handshake_test.rb +6 -7
  52. data/test/stream/component/ready_test.rb +9 -10
  53. data/test/stream/component/start_test.rb +6 -7
  54. data/test/stream/http/auth_test.rb +68 -0
  55. data/test/stream/http/ready_test.rb +56 -0
  56. data/test/stream/http/sessions_test.rb +50 -0
  57. data/test/stream/http/start_test.rb +51 -0
  58. data/test/stream/parser_test.rb +5 -5
  59. data/test/stream/server/outbound/auth_test.rb +12 -13
  60. data/test/stream/server/ready_test.rb +10 -11
  61. data/test/token_bucket_test.rb +7 -7
  62. data/test/user_test.rb +8 -6
  63. metadata +45 -14
  64. data/lib/vines/stream/http/http_request.rb +0 -22
  65. data/lib/vines/stream/http/http_state.rb +0 -139
  66. data/lib/vines/stream/http/http_states.rb +0 -53
data/test/config_test.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vines'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
- class ConfigTest < Test::Unit::TestCase
6
+ class ConfigTest < MiniTest::Unit::TestCase
7
7
  def test_missing_host
8
- assert_raise(RuntimeError) do
8
+ assert_raises(RuntimeError) do
9
9
  Vines::Config.new do
10
10
  # missing hosts
11
11
  end
@@ -13,7 +13,7 @@ class ConfigTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  def test_duplicate_host
16
- assert_raise(RuntimeError) do
16
+ assert_raises(RuntimeError) do
17
17
  Vines::Config.new do
18
18
  host 'wonderland.lit' do
19
19
  storage 'fs' do
@@ -30,7 +30,7 @@ class ConfigTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_duplicate_host_in_one_call
33
- assert_raise(RuntimeError) do
33
+ assert_raises(RuntimeError) do
34
34
  Vines::Config.new do
35
35
  host 'wonderland.lit', 'wonderland.lit' do
36
36
  storage 'fs' do
@@ -42,7 +42,7 @@ class ConfigTest < Test::Unit::TestCase
42
42
  end
43
43
 
44
44
  def test_missing_storage
45
- assert_raise(RuntimeError) do
45
+ assert_raises(RuntimeError) do
46
46
  Vines::Config.new do
47
47
  host 'wonderland.lit' do
48
48
  # missing storage
@@ -52,7 +52,7 @@ class ConfigTest < Test::Unit::TestCase
52
52
  end
53
53
 
54
54
  def test_bad_storage
55
- assert_raise(RuntimeError) do
55
+ assert_raises(RuntimeError) do
56
56
  Vines::Config.new do
57
57
  host 'wonderland.lit' do
58
58
  storage 'bogus' do
@@ -64,7 +64,7 @@ class ConfigTest < Test::Unit::TestCase
64
64
  end
65
65
 
66
66
  def test_duplicate_storage
67
- assert_raise(RuntimeError) do
67
+ assert_raises(RuntimeError) do
68
68
  Vines::Config.new do
69
69
  host 'wonderland.lit' do
70
70
  storage('fs') { dir '.' }
@@ -74,13 +74,11 @@ class ConfigTest < Test::Unit::TestCase
74
74
  end
75
75
  end
76
76
 
77
- def test_good_storage
78
- assert_nothing_raised do
79
- Vines::Config.new do
80
- host 'wonderland.lit' do
81
- storage 'fs' do
82
- dir '.'
83
- end
77
+ def test_good_storage_raises_no_errors
78
+ Vines::Config.new do
79
+ host 'wonderland.lit' do
80
+ storage 'fs' do
81
+ dir '.'
84
82
  end
85
83
  end
86
84
  end
@@ -117,7 +115,7 @@ class ConfigTest < Test::Unit::TestCase
117
115
  end
118
116
  end
119
117
  %w[wonderland.lit verona.lit].each do |domain|
120
- assert_not_nil config.vhosts[domain].ldap
118
+ refute_nil config.vhosts[domain].ldap
121
119
  assert config.vhosts[domain].ldap?
122
120
  end
123
121
  end
@@ -130,7 +128,7 @@ class ConfigTest < Test::Unit::TestCase
130
128
  end
131
129
  end
132
130
  end
133
- assert_not_nil config
131
+ refute_nil config
134
132
  assert_same config, Vines::Config.instance
135
133
  end
136
134
 
@@ -152,13 +150,13 @@ class ConfigTest < Test::Unit::TestCase
152
150
  end
153
151
  client
154
152
  end
155
- assert_not_nil config[:client]
156
- assert_raise(ArgumentError) { config[:server] }
157
- assert_raise(ArgumentError) { config[:bogus] }
153
+ refute_nil config[:client]
154
+ assert_raises(ArgumentError) { config[:server] }
155
+ assert_raises(ArgumentError) { config[:bogus] }
158
156
  end
159
157
 
160
158
  def test_duplicate_client
161
- assert_raise(RuntimeError) do
159
+ assert_raises(RuntimeError) do
162
160
  Vines::Config.new do
163
161
  client
164
162
  client
@@ -167,7 +165,7 @@ class ConfigTest < Test::Unit::TestCase
167
165
  end
168
166
 
169
167
  def test_duplicate_server
170
- assert_raise(RuntimeError) do
168
+ assert_raises(RuntimeError) do
171
169
  Vines::Config.new do
172
170
  server
173
171
  server
@@ -176,7 +174,7 @@ class ConfigTest < Test::Unit::TestCase
176
174
  end
177
175
 
178
176
  def test_duplicate_http
179
- assert_raise(RuntimeError) do
177
+ assert_raises(RuntimeError) do
180
178
  Vines::Config.new do
181
179
  http
182
180
  http
@@ -185,7 +183,7 @@ class ConfigTest < Test::Unit::TestCase
185
183
  end
186
184
 
187
185
  def test_duplicate_component
188
- assert_raise(RuntimeError) do
186
+ assert_raises(RuntimeError) do
189
187
  Vines::Config.new do
190
188
  component
191
189
  component
@@ -201,7 +199,7 @@ class ConfigTest < Test::Unit::TestCase
201
199
  client
202
200
  end
203
201
  port = config.ports.first
204
- assert_not_nil port
202
+ refute_nil port
205
203
  assert_equal Vines::Config::ClientPort, port.class
206
204
  assert_equal '0.0.0.0', port.host
207
205
  assert_equal 5222, port.port
@@ -223,7 +221,7 @@ class ConfigTest < Test::Unit::TestCase
223
221
  end
224
222
  end
225
223
  port = config.ports.first
226
- assert_not_nil port
224
+ refute_nil port
227
225
  assert_equal Vines::Config::ClientPort, port.class
228
226
  assert_equal '0.0.0.1', port.host
229
227
  assert_equal 42, port.port
@@ -254,7 +252,7 @@ class ConfigTest < Test::Unit::TestCase
254
252
  server
255
253
  end
256
254
  port = config.ports.first
257
- assert_not_nil port
255
+ refute_nil port
258
256
  assert !config.s2s?('verona.lit')
259
257
  assert_equal Vines::Config::ServerPort, port.class
260
258
  assert_equal '0.0.0.0', port.host
@@ -276,7 +274,7 @@ class ConfigTest < Test::Unit::TestCase
276
274
  end
277
275
  end
278
276
  port = config.ports.first
279
- assert_not_nil port
277
+ refute_nil port
280
278
  assert config.s2s?('verona.lit')
281
279
  assert config.s2s?('denmark.lit')
282
280
  assert !config.s2s?('bogus')
@@ -297,11 +295,12 @@ class ConfigTest < Test::Unit::TestCase
297
295
  http
298
296
  end
299
297
  port = config.ports.first
300
- assert_not_nil port
298
+ refute_nil port
301
299
  assert_equal Vines::Config::HttpPort, port.class
302
300
  assert_equal '0.0.0.0', port.host
303
301
  assert_equal 5280, port.port
304
302
  assert_equal 131_072, port.max_stanza_size
303
+ assert_equal 5, port.max_resources_per_account
305
304
  assert_equal Vines::Stream::Http, port.stream
306
305
  assert_same config, port.config
307
306
  assert_equal 1, config.ports.size
@@ -314,14 +313,16 @@ class ConfigTest < Test::Unit::TestCase
314
313
  end
315
314
  http '0.0.0.1', 42 do
316
315
  max_stanza_size 60_000
316
+ max_resources_per_account 1
317
317
  end
318
318
  end
319
319
  port = config.ports.first
320
- assert_not_nil port
320
+ refute_nil port
321
321
  assert_equal Vines::Config::HttpPort, port.class
322
322
  assert_equal '0.0.0.1', port.host
323
323
  assert_equal 42, port.port
324
324
  assert_equal 60_000, port.max_stanza_size
325
+ assert_equal 1, port.max_resources_per_account
325
326
  assert_equal Vines::Stream::Http, port.stream
326
327
  assert_same config, port.config
327
328
  assert_equal 1, config.ports.size
@@ -335,7 +336,7 @@ class ConfigTest < Test::Unit::TestCase
335
336
  component
336
337
  end
337
338
  port = config.ports.first
338
- assert_not_nil port
339
+ refute_nil port
339
340
  assert port.components.empty?
340
341
  assert_nil port.password('bogus')
341
342
  assert_equal Vines::Config::ComponentPort, port.class
@@ -359,7 +360,7 @@ class ConfigTest < Test::Unit::TestCase
359
360
  end
360
361
  end
361
362
  port = config.ports.first
362
- assert_not_nil port
363
+ refute_nil port
363
364
  assert_equal 2, port.components.size
364
365
  assert_equal 'secr3t', port.password('tea.wonderland.lit')
365
366
  assert_equal 'passw0rd', port.password('cake.wonderland.lit')
@@ -374,7 +375,7 @@ class ConfigTest < Test::Unit::TestCase
374
375
  end
375
376
 
376
377
  def test_invalid_log_level
377
- assert_raise(RuntimeError) do
378
+ assert_raises(RuntimeError) do
378
379
  config = Vines::Config.new do
379
380
  log 'bogus'
380
381
  host 'wonderland.lit' do
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'vines'
4
+ require 'minitest/autorun'
5
+
6
+ class ContactTest < MiniTest::Unit::TestCase
7
+ def test_equality
8
+ alice = Vines::Contact.new(:jid => 'alice@wonderland.lit')
9
+ alice2 = Vines::Contact.new(:jid => 'alice@wonderland.lit')
10
+ hatter = Vines::Contact.new(:jid => 'hatter@wonderland.lit')
11
+
12
+ assert_nil alice <=> 42
13
+
14
+ assert alice == alice2
15
+ assert alice.eql?(alice2)
16
+ assert alice.hash == alice2.hash
17
+
18
+ refute alice == hatter
19
+ refute alice.eql?(hatter)
20
+ refute alice.hash == hatter.hash
21
+ end
22
+
23
+ def test_initialize_missing_jid
24
+ assert_raises(ArgumentError) { Vines::Contact.new }
25
+ end
26
+
27
+ def test_to_roster_xml_sorts_groups
28
+ contact = Vines::Contact.new(
29
+ :jid => 'a@wonderland.lit',
30
+ :name => "Contact 1",
31
+ :groups => %w[B A])
32
+
33
+ expected = %q{
34
+ <item jid="a@wonderland.lit" name="Contact 1" subscription="none">
35
+ <group>A</group>
36
+ <group>B</group>
37
+ </item>
38
+ }.strip.gsub(/\n/, '').gsub(/\s{2,}/, '')
39
+
40
+ assert_equal expected, contact.to_roster_xml.to_xml(:indent => 0).gsub(/\n/, '')
41
+ end
42
+ end
data/test/error_test.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vines'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
- class ErrorTest < Test::Unit::TestCase
6
+ class ErrorTest < MiniTest::Unit::TestCase
7
7
  def test_sasl_error_without_text
8
8
  expected = %q{<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/></failure>}
9
9
  assert_equal expected, Vines::SaslErrors::TemporaryAuthFailure.new.to_xml
data/test/jid_test.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vines'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
- class JidTest < Test::Unit::TestCase
6
+ class JidTest < MiniTest::Unit::TestCase
7
7
  def test_nil_and_empty_jids
8
8
  [nil, ''].each do |text|
9
- assert_nothing_raised { Vines::JID.new(text) }
9
+ Vines::JID.new(text) # shouldn't raise an error
10
10
  jid = Vines::JID.new(text)
11
11
  assert_nil jid.node
12
12
  assert_nil jid.resource
@@ -17,11 +17,11 @@ class JidTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_jid_too_long_error
20
- assert_nothing_raised { Vines::JID.new('n' * 1023) }
20
+ Vines::JID.new('n' * 1023) # shouldn't raise an error
21
21
  assert_raises(ArgumentError) { Vines::JID.new('n' * 1024) }
22
22
  assert_raises(ArgumentError) { Vines::JID.new('n', 'd' * 1024) }
23
23
  assert_raises(ArgumentError) { Vines::JID.new('n', 'd', 'r' * 1024) }
24
- assert_nothing_raised { Vines::JID.new('n' * 1023, 'd' * 1023, 'r' * 1023) }
24
+ Vines::JID.new('n' * 1023, 'd' * 1023, 'r' * 1023) # shouldn't raise an error
25
25
  end
26
26
 
27
27
  def test_domain_only
@@ -57,7 +57,7 @@ class JidTest < Test::Unit::TestCase
57
57
  assert_equal 'wonderland.lit', jid.domain
58
58
  assert_equal 'alice', jid.node
59
59
  assert_equal 'tea', jid.resource
60
- assert_not_equal jid, jid.bare
60
+ refute_equal jid, jid.bare
61
61
  end
62
62
 
63
63
  def test_parsed_full_jid
@@ -66,6 +66,6 @@ class JidTest < Test::Unit::TestCase
66
66
  assert_equal 'wonderland.lit', jid.domain
67
67
  assert_equal 'alice', jid.node
68
68
  assert_equal 'tea', jid.resource
69
- assert_not_equal jid, jid.bare
69
+ refute_equal jid, jid.bare
70
70
  end
71
71
  end
data/test/kit_test.rb CHANGED
@@ -1,21 +1,21 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vines'
4
- require 'test/unit'
4
+ require 'minitest/autorun'
5
5
 
6
- class KitTest < Test::Unit::TestCase
6
+ class KitTest < MiniTest::Unit::TestCase
7
7
  def test_hmac
8
- assert_equal(128, Vines::Kit.hmac('secret', 'username').length)
9
- assert_equal(Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s1', 'u1'))
10
- assert_not_equal(Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s2', 'u1'))
11
- assert_not_equal(Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s1', 'u2'))
8
+ assert_equal 128, Vines::Kit.hmac('secret', 'username').length
9
+ assert_equal Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s1', 'u1')
10
+ refute_equal Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s2', 'u1')
11
+ refute_equal Vines::Kit.hmac('s1', 'u1'), Vines::Kit.hmac('s1', 'u2')
12
12
  end
13
13
 
14
14
  def test_uuid
15
15
  ids = Array.new(1000) { Vines::Kit.uuid }
16
- assert(ids.all? {|id| !id.nil? })
17
- assert(ids.all? {|id| id.length == 36 })
18
- assert(ids.all? {|id| id.match(/\w{8}-\w{4}-[4]\w{3}-[89ab]\w{3}-\w{12}/) })
19
- assert_equal(ids.length, ids.uniq.length)
16
+ assert ids.all? {|id| !id.nil? }
17
+ assert ids.all? {|id| id.length == 36 }
18
+ assert ids.all? {|id| id.match(/\w{8}-\w{4}-[4]\w{3}-[89ab]\w{3}-\w{12}/) }
19
+ assert_equal ids.length, ids.uniq.length
20
20
  end
21
21
  end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Use the latest MiniTest gem instead of the buggy
4
+ # version included with Ruby 1.9.2.
5
+ gem 'minitest'
6
+
7
+ # Load the test files from the command line.
8
+
9
+ ARGV.each { |f| load f unless f =~ /^-/ }
data/test/router_test.rb CHANGED
@@ -1,10 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vines'
4
- require 'minitest/mock'
5
- require 'test/unit'
4
+ require 'minitest/autorun'
6
5
 
7
- class RouterTest < Test::Unit::TestCase
6
+ class RouterTest < MiniTest::Unit::TestCase
8
7
  def setup
9
8
  @router = Vines::Router.new
10
9
  end
@@ -29,6 +28,7 @@ class RouterTest < Test::Unit::TestCase
29
28
  config.expect(:vhost?, true, ['wonderland.lit'])
30
29
  stream = MiniTest::Mock.new
31
30
  stream.expect(:config, config)
31
+ stream.expect(:stream_type, :client)
32
32
  @router << stream
33
33
 
34
34
  stanza = MiniTest::Mock.new
@@ -46,6 +46,7 @@ class RouterTest < Test::Unit::TestCase
46
46
  config.expect(:vhost?, false, ['wonderland.lit'])
47
47
  stream = MiniTest::Mock.new
48
48
  stream.expect(:config, config)
49
+ stream.expect(:stream_type, :client)
49
50
  @router << stream
50
51
 
51
52
  stanza = MiniTest::Mock.new
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'vines'
4
4
  require 'ext/nokogiri'
5
- require 'minitest/mock'
6
- require 'test/unit'
5
+ require 'minitest/autorun'
7
6
 
8
- class RosterTest < Test::Unit::TestCase
7
+ class RosterTest < MiniTest::Unit::TestCase
9
8
  def setup
10
9
  @stream = MiniTest::Mock.new
11
10
  end
@@ -59,7 +58,7 @@ class RosterTest < Test::Unit::TestCase
59
58
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
60
59
 
61
60
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
62
- assert_raise(Vines::StanzaErrors::Forbidden) { stanza.process }
61
+ assert_raises(Vines::StanzaErrors::Forbidden) { stanza.process }
63
62
  assert @stream.verify
64
63
  end
65
64
 
@@ -70,7 +69,7 @@ class RosterTest < Test::Unit::TestCase
70
69
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
71
70
 
72
71
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
73
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
72
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
74
73
  assert @stream.verify
75
74
  end
76
75
 
@@ -84,7 +83,7 @@ class RosterTest < Test::Unit::TestCase
84
83
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
85
84
 
86
85
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
87
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
86
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
88
87
  assert @stream.verify
89
88
  end
90
89
 
@@ -97,7 +96,7 @@ class RosterTest < Test::Unit::TestCase
97
96
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
98
97
 
99
98
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
100
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
99
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
101
100
  assert @stream.verify
102
101
  end
103
102
 
@@ -116,7 +115,7 @@ class RosterTest < Test::Unit::TestCase
116
115
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
117
116
 
118
117
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
119
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
118
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
120
119
  assert @stream.verify
121
120
  end
122
121
 
@@ -134,7 +133,7 @@ class RosterTest < Test::Unit::TestCase
134
133
  </iq>}.strip.gsub(/\n|\s{2,}/, ''))
135
134
 
136
135
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
137
- assert_raise(Vines::StanzaErrors::NotAcceptable) { stanza.process }
136
+ assert_raises(Vines::StanzaErrors::NotAcceptable) { stanza.process }
138
137
  assert @stream.verify
139
138
  end
140
139
 
@@ -173,7 +172,6 @@ class RosterTest < Test::Unit::TestCase
173
172
 
174
173
  stanza = Vines::Stanza::Iq::Roster.new(node, @stream)
175
174
  stanza.process
176
- assert_nothing_raised { stanza.process }
177
175
  assert @stream.verify
178
176
  assert storage.verify
179
177
  assert router.verify
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'vines'
4
4
  require 'ext/nokogiri'
5
- require 'minitest/mock'
6
- require 'test/unit'
5
+ require 'minitest/autorun'
7
6
 
8
- class SessionTest < Test::Unit::TestCase
7
+ class SessionTest < MiniTest::Unit::TestCase
9
8
  def test_session
10
9
  stream = MiniTest::Mock.new
11
10
  stream.expect(:domain, 'wonderland.lit')
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'vines'
4
4
  require 'ext/nokogiri'
5
- require 'minitest/mock'
6
- require 'test/unit'
5
+ require 'minitest/autorun'
7
6
 
8
- class VcardTest < Test::Unit::TestCase
7
+ class VcardTest < MiniTest::Unit::TestCase
9
8
  def setup
10
9
  @stream = MiniTest::Mock.new
11
10
  end
@@ -105,7 +104,7 @@ class VcardTest < Test::Unit::TestCase
105
104
  @stream.expect(:storage, storage, ['wonderland.lit'])
106
105
 
107
106
  stanza = Vines::Stanza::Iq::Vcard.new(node, @stream)
108
- assert_raise(Vines::StanzaErrors::ItemNotFound) { stanza.process }
107
+ assert_raises(Vines::StanzaErrors::ItemNotFound) { stanza.process }
109
108
  assert @stream.verify
110
109
  assert router.verify
111
110
  assert storage.verify
@@ -122,7 +121,7 @@ class VcardTest < Test::Unit::TestCase
122
121
  @stream.expect(:router, router)
123
122
 
124
123
  stanza = Vines::Stanza::Iq::Vcard.new(node, @stream)
125
- assert_raise(Vines::StanzaErrors::Forbidden) { stanza.process }
124
+ assert_raises(Vines::StanzaErrors::Forbidden) { stanza.process }
126
125
  assert @stream.verify
127
126
  end
128
127
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'vines'
4
4
  require 'ext/nokogiri'
5
- require 'minitest/mock'
6
- require 'test/unit'
5
+ require 'minitest/autorun'
7
6
 
8
- class MessageTest < Test::Unit::TestCase
7
+ class MessageTest < MiniTest::Unit::TestCase
9
8
  def setup
10
9
  @stream = MiniTest::Mock.new
11
10
  end
@@ -13,7 +12,7 @@ class MessageTest < Test::Unit::TestCase
13
12
  def test_bad_type_returns_error
14
13
  node = node('<message type="bogus">hello!</message>')
15
14
  stanza = Vines::Stanza::Message.new(node, @stream)
16
- assert_raise(Vines::StanzaErrors::BadRequest) { stanza.process }
15
+ assert_raises(Vines::StanzaErrors::BadRequest) { stanza.process }
17
16
  end
18
17
 
19
18
  def test_missing_to_address_is_sent_to_sender
@@ -21,16 +20,18 @@ class MessageTest < Test::Unit::TestCase
21
20
  node = node('<message>hello!</message>')
22
21
 
23
22
  recipient = MiniTest::Mock.new
23
+ recipient.expect(:user, alice)
24
+ recipient.expect(:write, nil, [node])
25
+
24
26
  router = MiniTest::Mock.new
25
27
  router.expect(:local?, true, [node])
26
28
  router.expect(:connected_resources, [recipient], [alice.jid.bare])
27
29
 
28
30
  @stream.expect(:router, router)
29
31
  @stream.expect(:user, alice)
30
- @stream.expect(:broadcast, nil, [node, [recipient]])
31
32
 
32
33
  stanza = Vines::Stanza::Message.new(node, @stream)
33
- assert_nothing_raised { stanza.process }
34
+ stanza.process
34
35
  assert @stream.verify
35
36
  assert router.verify
36
37
  assert recipient.verify
@@ -51,7 +52,7 @@ class MessageTest < Test::Unit::TestCase
51
52
  @stream.expect(:storage, storage, [bogus.domain])
52
53
 
53
54
  stanza = Vines::Stanza::Message.new(node, @stream)
54
- assert_nothing_raised { stanza.process }
55
+ stanza.process
55
56
  assert @stream.verify
56
57
  assert router.verify
57
58
  assert storage.verify
@@ -72,26 +73,31 @@ class MessageTest < Test::Unit::TestCase
72
73
  @stream.expect(:storage, storage, [hatter.jid.domain])
73
74
 
74
75
  stanza = Vines::Stanza::Message.new(node, @stream)
75
- assert_raise(Vines::StanzaErrors::ServiceUnavailable) { stanza.process }
76
+ assert_raises(Vines::StanzaErrors::ServiceUnavailable) { stanza.process }
76
77
  assert @stream.verify
77
78
  assert router.verify
78
79
  assert storage.verify
79
80
  end
80
81
 
81
82
  def test_message_to_local_user_in_different_domain_is_delivered
83
+ alice = Vines::User.new(:jid => 'alice@wonderland.lit/tea')
82
84
  romeo = Vines::User.new(:jid => 'romeo@verona.lit/balcony')
83
85
  node = node(%Q{<message to="#{romeo.jid}">hello!</message>})
86
+ expected = node(%Q{<message to="#{romeo.jid}" from="#{alice.jid}">hello!</message>})
84
87
 
85
88
  recipient = MiniTest::Mock.new
89
+ recipient.expect(:user, romeo)
90
+ recipient.expect(:write, nil, [expected])
91
+
86
92
  router = MiniTest::Mock.new
87
93
  router.expect(:local?, true, [node])
88
94
  router.expect(:connected_resources, [recipient], [romeo.jid])
89
95
 
90
96
  @stream.expect(:router, router)
91
- @stream.expect(:broadcast, nil, [node, [recipient]])
97
+ @stream.expect(:user, alice)
92
98
 
93
99
  stanza = Vines::Stanza::Message.new(node, @stream)
94
- assert_nothing_raised { stanza.process }
100
+ stanza.process
95
101
  assert @stream.verify
96
102
  assert router.verify
97
103
  assert recipient.verify
@@ -111,7 +117,7 @@ class MessageTest < Test::Unit::TestCase
111
117
  @stream.expect(:user, alice)
112
118
 
113
119
  stanza = Vines::Stanza::Message.new(node, @stream)
114
- assert_nothing_raised { stanza.process }
120
+ stanza.process
115
121
  assert @stream.verify
116
122
  assert router.verify
117
123
  end
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'vines'
4
4
  require 'ext/nokogiri'
5
- require 'minitest/mock'
6
- require 'test/unit'
5
+ require 'minitest/autorun'
7
6
 
8
- class SubscribeTest < Test::Unit::TestCase
7
+ class SubscribeTest < MiniTest::Unit::TestCase
9
8
  def test_outbound_subscribe_to_local_jid_but_missing_contact
10
9
  alice = Vines::JID.new('alice@wonderland.lit/tea')
11
10
  hatter = Vines::JID.new('hatter@wonderland.lit')
@@ -22,7 +21,7 @@ class SubscribeTest < Test::Unit::TestCase
22
21
  storage.expect(:find_user, nil, [hatter])
23
22
 
24
23
  recipient = MiniTest::Mock.new
25
- recipient.expect(:user, Vines::User.new(:jid => hatter))
24
+ recipient.expect(:user, user)
26
25
  def recipient.nodes; @nodes; end
27
26
  def recipient.write(node)
28
27
  @nodes ||= []
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'storage_tests'
4
4
  require 'vines'
5
- require 'test/unit'
5
+ require 'minitest/autorun'
6
6
 
7
- class CouchDBTest < Test::Unit::TestCase
7
+ class CouchDBTest < MiniTest::Unit::TestCase
8
8
  include StorageTests
9
9
 
10
10
  URL = 'http://localhost:5984/xmpp_testcase'.freeze
@@ -88,14 +88,13 @@ class CouchDBTest < Test::Unit::TestCase
88
88
 
89
89
  def test_init
90
90
  EMLoop.new do
91
- assert_raise(RuntimeError) { Vines::Storage::CouchDB.new {} }
92
- assert_raise(RuntimeError) { Vines::Storage::CouchDB.new { host 'localhost' } }
93
- assert_nothing_raised do
94
- Vines::Storage::CouchDB.new do
95
- host 'localhost'
96
- port '5984'
97
- database 'test'
98
- end
91
+ assert_raises(RuntimeError) { Vines::Storage::CouchDB.new {} }
92
+ assert_raises(RuntimeError) { Vines::Storage::CouchDB.new { host 'localhost' } }
93
+ # shouldn't raise an error
94
+ Vines::Storage::CouchDB.new do
95
+ host 'localhost'
96
+ port '5984'
97
+ database 'test'
99
98
  end
100
99
  end
101
100
  end