skates 0.5.0 → 0.5.3
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.
- data/lib/skates/base/view.rb +1 -1
- data/lib/skates/client_connection.rb +1 -1
- data/lib/skates/component_connection.rb +1 -1
- data/lib/skates/xmpp_connection.rb +4 -2
- data/lib/skates/xmpp_parser.rb +2 -2
- metadata +14 -38
- data/spec/bin/skates_spec.rb +0 -0
- data/spec/em_mock.rb +0 -42
- data/spec/lib/skates/base/controller_spec.rb +0 -205
- data/spec/lib/skates/base/stanza_spec.rb +0 -120
- data/spec/lib/skates/base/view_spec.rb +0 -105
- data/spec/lib/skates/client_connection_spec.rb +0 -309
- data/spec/lib/skates/component_connection_spec.rb +0 -144
- data/spec/lib/skates/generator_spec.rb +0 -10
- data/spec/lib/skates/router/dsl_spec.rb +0 -46
- data/spec/lib/skates/router_spec.rb +0 -252
- data/spec/lib/skates/runner_spec.rb +0 -233
- data/spec/lib/skates/xmpp_connection_spec.rb +0 -222
- data/spec/lib/skates/xmpp_parser_spec.rb +0 -469
- data/spec/spec_helper.rb +0 -37
- data/test/skates_test.rb +0 -7
- data/test/test_helper.rb +0 -10
@@ -1,105 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
-
|
3
|
-
describe Skates::Base::View do
|
4
|
-
describe :initialize do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@view = Skates::Base::View.new("/a/path/to/views/file", {:a => "a", :b => 123, :c => {:d => "d", :e => "123"}})
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should assign @view_template to path" do
|
11
|
-
@view.view_template == "/a/path/to/views/file"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should assign any variable passed in hash" do
|
15
|
-
{:a => "a", :b => 123, :c => {:d => "d", :e => "123"}}.each do |key, value|
|
16
|
-
@view.instance_variable_get("@#{key}").should == value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe :evaluate do
|
22
|
-
before(:each) do
|
23
|
-
@view_template = "/a/path/to/views/file"
|
24
|
-
@view = Skates::Base::View.new(@view_template, {:a => "a", :b => 123, :c => {:d => "d", :e => "123"}})
|
25
|
-
@xml_string = <<-eoxml
|
26
|
-
xml.message(:to => "you", :from => "me", :type => :chat) do
|
27
|
-
xml.body("salut")
|
28
|
-
end
|
29
|
-
eoxml
|
30
|
-
Skates.views.stub!(:[]).with(@view_template).and_return(@xml_string)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should read the template file" do
|
34
|
-
Skates.views.should_receive(:[]).twice.with(@view_template).and_return(@xml_string)
|
35
|
-
@view.evaluate
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should raise an error if the view file couldn't be found" do
|
39
|
-
Skates.views.stub!(:[]).with(@view_template).and_raise(nil)
|
40
|
-
lambda {
|
41
|
-
@view.evaluate
|
42
|
-
}.should raise_error(Skates::Base::ViewFileNotFound)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should return a Nokogiri NodeSet" do
|
46
|
-
Skates.views.stub!(:[]).with(@view_template).and_return(@xml_string)
|
47
|
-
@view.evaluate.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should call eval on the view file" do
|
51
|
-
Skates.views.stub!(:[]).with(@view_template).and_return(@xml_string)
|
52
|
-
@view.should_receive(:eval).with(@xml_string, an_instance_of(Binding), @view_template, 1)
|
53
|
-
@view.evaluate
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should be able to access context's variables" do
|
57
|
-
@view = Skates::Base::View.new("/a/path/to/views/file", {:a => "a", :b => 123, :c => {:d => "d", :e => "123"}})
|
58
|
-
@view.instance_variable_get("@a").should == "a"
|
59
|
-
@view.instance_variable_get("@b").should == 123
|
60
|
-
@view.instance_variable_get("@c").should == {:e=>"123", :d=>"d"}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe :render do
|
65
|
-
before(:each) do
|
66
|
-
@view_template = "/a/path/to/views/file"
|
67
|
-
@view = Skates::Base::View.new(@view_template, {:a => "a", :b => 123, :c => {:d => "d", :e => "123"}})
|
68
|
-
|
69
|
-
@xml_string = <<-eoxml
|
70
|
-
xml.message(:to => "you", :from => "me", :type => :chat) do |message|
|
71
|
-
message.body("salut")
|
72
|
-
render(message, {:partial => "partial", :locals => {:subtitle => "bonjour monde"}})
|
73
|
-
render(message, {:partial => "../other_views/partial", :locals => {:subtitle => "bonjour monde", :name => "Joe"}})
|
74
|
-
end
|
75
|
-
eoxml
|
76
|
-
|
77
|
-
@partial_string = <<-eoxml
|
78
|
-
xml.title("hello word")
|
79
|
-
xml.subtitle(subtitle)
|
80
|
-
eoxml
|
81
|
-
|
82
|
-
@partial_in_annother_controller_string = <<-eoxml
|
83
|
-
xml.name(name)
|
84
|
-
eoxml
|
85
|
-
|
86
|
-
Skates.views.stub!(:[]).with(@view_template).and_return(@xml_string)
|
87
|
-
Skates.views.stub!(:[]).with("/a/path/to/views/partial.xml.builder").and_return(@partial_string)
|
88
|
-
Skates.views.stub!(:[]).with("/a/path/to/other_views/partial.xml.builder").and_return(@partial_in_annother_controller_string)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should render the partial in the right context" do
|
92
|
-
@view.evaluate.xpath("//message/title").text.should == "hello word"
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should allocate the locals variables" do
|
96
|
-
@view.evaluate.xpath("//message/subtitle").text.should == "bonjour monde"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should cleanup the path so only canonical paths are used" do
|
100
|
-
@view.evaluate.xpath("//message/name").text.should == "Joe"
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
@@ -1,309 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../../em_mock'
|
3
|
-
|
4
|
-
describe Skates::ClientConnection do
|
5
|
-
|
6
|
-
include SkatesSpecHelper
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
@params = {"jid" => "jid@server.tld", "password" => "password"}
|
10
|
-
@client = Skates::ClientConnection.connect(@params.merge({"host" => "0.0.0.0", "port" => 5222}), handler_mock)
|
11
|
-
@client.stub!(:send_xml).and_return(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "initialize" do
|
15
|
-
it "should set the state to :wait_for_stream" do
|
16
|
-
@client.instance_variable_get("@state").should == :wait_for_stream
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "connect" do
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "when resolving the hostname" do
|
24
|
-
before(:each) do
|
25
|
-
@params.delete("host")
|
26
|
-
@params.delete("port")
|
27
|
-
@srv = [
|
28
|
-
mock(Resolv::DNS::Resource, :priority => 10, :target => "12.13.14.15", :port => 1234, :address => "12.13.14.15"),
|
29
|
-
mock(Resolv::DNS::Resource, :priority => 3, :target => "12.13.14.16", :port => 4567, :address => "12.13.14.16"),
|
30
|
-
mock(Resolv::DNS::Resource, :priority => 100, :target => "12.13.14.17", :port => 8910, :address => "12.13.14.17")
|
31
|
-
]
|
32
|
-
@mock_dns = mock(Object)
|
33
|
-
Resolv::DNS.stub!(:open).and_yield(@mock_dns)
|
34
|
-
@mock_dns.stub!(:getresources).and_return(@srv)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should get resources assiated with _xmpp-client._tcp.host.tld}" do
|
38
|
-
Resolv::DNS.should_receive(:open).and_yield(@mock_dns)
|
39
|
-
@mock_dns.should_receive(:getresources).with("server.tld", Resolv::DNS::Resource::IN::SRV).and_return(@srv)
|
40
|
-
Skates::ClientConnection.resolve("server.tld")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should call the block with the highest priority" do
|
44
|
-
Skates::ClientConnection.resolve("xmpp.server.tld") do |params|
|
45
|
-
params["host"].should == "12.13.14.16"
|
46
|
-
params["port"].should == 4567
|
47
|
-
true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should call the block as many times as needed if they're not connecting" do
|
52
|
-
conn = mock(Skates::ClientConnection, :_connect => false)
|
53
|
-
conn.should_receive(:_connect).exactly(3).times
|
54
|
-
Skates::ClientConnection.resolve("xmpp.server.tld") do |ip, port|
|
55
|
-
conn._connect(ip, port)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "stream_stanza" do
|
61
|
-
it "should be of the right form" do
|
62
|
-
@client.stream_stanza.should == "<?xml version=\"1.0\"?>\n<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"server.tld\" version=\"1.0\">\n "
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "connection_completed" do
|
67
|
-
it "should send_xml the stream_stanza" do
|
68
|
-
@client.should_receive(:send_xml).with(@client.stream_stanza)
|
69
|
-
@client.connection_completed
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "receive_stanza" do
|
74
|
-
before(:each) do
|
75
|
-
@doc = Nokogiri::XML::Document.new
|
76
|
-
end
|
77
|
-
describe "when connected" do
|
78
|
-
before(:each) do
|
79
|
-
@client.instance_variable_set("@state", :connected)
|
80
|
-
end
|
81
|
-
it "should call super"
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "when wait_for_stream_authenticated" do
|
85
|
-
before(:each) do
|
86
|
-
@client.instance_variable_set("@state", :wait_for_stream_authenticated)
|
87
|
-
@stanza = Nokogiri::XML::Node.new("stream", @doc)
|
88
|
-
@stanza["id"] = "123"
|
89
|
-
end
|
90
|
-
it "should change state to wait_for_bind if the stanza is stream with an id" do
|
91
|
-
@client.receive_stanza(@stanza)
|
92
|
-
@client.instance_variable_get("@state").should == :wait_for_bind
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "when wait_for_stream" do
|
97
|
-
before(:each) do
|
98
|
-
@client.instance_variable_set("@state", :wait_for_stream)
|
99
|
-
@stanza = Nokogiri::XML::Node.new("stream", @doc)
|
100
|
-
@stanza["id"] = "123"
|
101
|
-
end
|
102
|
-
it "should change state to wait_for_auth_mechanisms if the stanza is stream with an id" do
|
103
|
-
@client.receive_stanza(@stanza)
|
104
|
-
@client.instance_variable_get("@state").should == :wait_for_auth_mechanisms
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "when wait_for_auth_mechanisms" do
|
109
|
-
before(:each) do
|
110
|
-
@client.instance_variable_set("@state", :wait_for_auth_mechanisms)
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "if the stanza is features" do
|
114
|
-
before(:each) do
|
115
|
-
@stanza = Nokogiri::XML::Node.new("features", @doc)
|
116
|
-
@stanza["id"] = "123"
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "if the stanza has startls" do
|
120
|
-
before(:each) do
|
121
|
-
@stanza.add_child(Nokogiri::XML::Node.new("starttls", @doc))
|
122
|
-
end
|
123
|
-
it "should send start tls" do
|
124
|
-
@client.should_receive(:send_xml).with('<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>')
|
125
|
-
@client.receive_stanza(@stanza)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "if the stanza has mechanisms" do
|
130
|
-
before(:each) do
|
131
|
-
mechanisms = Nokogiri::XML::Node.new("mechanisms", @doc)
|
132
|
-
mechanism = Nokogiri::XML::Node.new("mechanism", @doc)
|
133
|
-
mechanism.content = "PLAIN"
|
134
|
-
mechanisms.add_child(mechanism)
|
135
|
-
@stanza.add_child(mechanisms)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should send authentication" do
|
139
|
-
@client.should_receive(:send_xml).with("<auth mechanism=\"PLAIN\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">amlkQHNlcnZlci50bGQAamlkAHBhc3N3b3Jk</auth>")
|
140
|
-
@client.receive_stanza(@stanza)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe "when wait_for_success" do
|
148
|
-
before(:each) do
|
149
|
-
@client.instance_variable_set("@state", :wait_for_success)
|
150
|
-
end
|
151
|
-
describe "when stanza is success" do
|
152
|
-
before(:each) do
|
153
|
-
@stanza = Nokogiri::XML::Node.new("success", @doc)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should reset the parser" do
|
157
|
-
@client.instance_variable_get("@parser").should_receive(:reset)
|
158
|
-
@client.receive_stanza(@stanza)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should send stream_stanza" do
|
162
|
-
@client.should_receive(:send_xml).with("<?xml version=\"1.0\"?>\n<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"server.tld\" version=\"1.0\">\n ")
|
163
|
-
@client.receive_stanza(@stanza)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should change state to wait_for_stream_authenticated" do
|
167
|
-
@client.receive_stanza(@stanza)
|
168
|
-
@client.instance_variable_get("@state").should == :wait_for_stream_authenticated
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
describe "when stanza is failure" do
|
173
|
-
before(:each) do
|
174
|
-
@stanza = Nokogiri::XML::Node.new("failure", @doc)
|
175
|
-
end
|
176
|
-
it "should raise AuthenticationError if stanza has bad-auth" do
|
177
|
-
@stanza.add_child(Nokogiri::XML::Node.new("bad-auth", @doc))
|
178
|
-
lambda {
|
179
|
-
@client.receive_stanza(@stanza)
|
180
|
-
}.should raise_error(Skates::AuthenticationError)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should raise AuthenticationError if stanza has not-authorized" do
|
184
|
-
@stanza.add_child(Nokogiri::XML::Node.new("not-authorized", @doc))
|
185
|
-
lambda {
|
186
|
-
@client.receive_stanza(@stanza)
|
187
|
-
}.should raise_error(Skates::AuthenticationError)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "when wait_for_bind" do
|
193
|
-
before(:each) do
|
194
|
-
@client.instance_variable_set("@state", :wait_for_bind)
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "if stanza is features" do
|
198
|
-
before(:each) do
|
199
|
-
@stanza = Nokogiri::XML::Node.new("features", @doc)
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "if stanza has bind" do
|
203
|
-
before(:each) do
|
204
|
-
bind = Nokogiri::XML::Node.new("bind", @doc)
|
205
|
-
@stanza.add_child(bind)
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should send_xml with the bind iq" do
|
209
|
-
@client.should_receive(:binding_iq_id).twice.and_return(123)
|
210
|
-
@client.should_receive(:send_xml).with("<iq type=\"set\" id=\"123\">\n <bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">\n <resource>skates_client_123</resource>\n </bind>\n</iq>")
|
211
|
-
@client.receive_stanza(@stanza)
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should set the state to :wait_for_confirmed_binding" do
|
215
|
-
@client.receive_stanza(@stanza)
|
216
|
-
@client.instance_variable_get("@state").should == :wait_for_confirmed_binding
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe "when wait_for_confirmed_binding" do
|
223
|
-
before(:each) do
|
224
|
-
@client.instance_variable_set("@state", :wait_for_confirmed_binding)
|
225
|
-
end
|
226
|
-
describe "if stanza is iq with type=result and the righ binding_iq_id" do
|
227
|
-
before(:each) do
|
228
|
-
binding_iq_id = 123
|
229
|
-
@stanza = Nokogiri::XML::Node.new("iq", @doc)
|
230
|
-
@stanza["type"] = "result"
|
231
|
-
@stanza["id"] = binding_iq_id.to_s
|
232
|
-
@client.stub!(:binding_iq_id).and_return(binding_iq_id)
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should send_xml with the session iq" do
|
236
|
-
@client.should_receive(:session_iq_id).and_return(123)
|
237
|
-
@client.should_receive(:send_xml).with("<iq type=\"set\" id=\"123\">\n <session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>\n</iq>")
|
238
|
-
@client.receive_stanza(@stanza)
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should set the state to :wait_for_confirmed_session" do
|
242
|
-
@client.receive_stanza(@stanza)
|
243
|
-
@client.instance_variable_get("@state").should == :wait_for_confirmed_session
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "when wait_for_confirmed_session" do
|
250
|
-
before(:each) do
|
251
|
-
@client.instance_variable_set("@state", :wait_for_confirmed_session)
|
252
|
-
end
|
253
|
-
|
254
|
-
describe "if stanza is iq with type=result and the righ session_iq_id" do
|
255
|
-
before(:each) do
|
256
|
-
session_iq_id = 123
|
257
|
-
@stanza = Nokogiri::XML::Node.new("iq", @doc)
|
258
|
-
@stanza["type"] = "result"
|
259
|
-
@stanza["id"] = session_iq_id.to_s
|
260
|
-
@client.stub!(:session_iq_id).and_return(session_iq_id)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should send_xml the initial presence" do
|
264
|
-
@client.should_receive(:send_xml).with("<presence/>")
|
265
|
-
@client.receive_stanza(@stanza)
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should set the state to :connected" do
|
269
|
-
@client.receive_stanza(@stanza)
|
270
|
-
@client.instance_variable_get("@state").should == :connected
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "when wait_for_proceed" do
|
276
|
-
before(:each) do
|
277
|
-
@client.instance_variable_set("@state", :wait_for_proceed)
|
278
|
-
@client.stub!(:start_tls).and_return(true)
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should start_tls" do
|
282
|
-
@client.should_receive(:start_tls)
|
283
|
-
@client.receive_stanza(@stanza)
|
284
|
-
end
|
285
|
-
|
286
|
-
it "reset the parser" do
|
287
|
-
@client.instance_variable_get("@parser").should_receive(:reset)
|
288
|
-
@client.receive_stanza(@stanza)
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should set the state to :wait_for_stream" do
|
292
|
-
@client.receive_stanza(@stanza)
|
293
|
-
@client.instance_variable_get("@state").should == :wait_for_stream
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should send the stream stanza" do
|
297
|
-
@client.should_receive(:send_xml).with("<?xml version=\"1.0\"?>\n<stream:stream xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"server.tld\" version=\"1.0\">\n ")
|
298
|
-
@client.receive_stanza(@stanza)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
describe "stream_namespace" do
|
304
|
-
it "should return jabber:client" do
|
305
|
-
@client.stream_namespace.should == "jabber:client"
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../../em_mock'
|
3
|
-
|
4
|
-
describe Skates::ComponentConnection do
|
5
|
-
|
6
|
-
include SkatesSpecHelper
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
@params = {"jid" => "jid@server", "password" => "password", "port" => 1234, "host" => "0.0.0.0"}
|
10
|
-
@component = Skates::ComponentConnection.connect(@params, handler_mock)
|
11
|
-
@component.stub!(:send_xml).and_return(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "initialize" do
|
15
|
-
it "should set the state to :wait_for_stream" do
|
16
|
-
@component.instance_variable_get("@state").should == :wait_for_stream
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "connection_completed" do
|
21
|
-
it "should send a <stream> element that initiates the communication" do
|
22
|
-
@component.should_receive(:send_xml).with("<?xml version=\"1.0\"?>\n<stream:stream xmlns=\"jabber:component:accept\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"jid@server\">\n ")
|
23
|
-
@component.connection_completed
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "receive_stanza" do
|
28
|
-
|
29
|
-
before(:each) do
|
30
|
-
@component.instance_variable_set("@connected", true)
|
31
|
-
@doc = Nokogiri::XML::Document.new
|
32
|
-
@stanza = Nokogiri::XML::Node.new("presence", @doc)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "when connected" do
|
36
|
-
before(:each) do
|
37
|
-
@component.instance_variable_set("@state", :connected)
|
38
|
-
end
|
39
|
-
it "should call the receive_stanza on super"
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "when waiting for stream" do
|
43
|
-
before(:each) do
|
44
|
-
@component.connection_completed
|
45
|
-
@component.instance_variable_set("@state", :wait_for_stream)
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "if the stanza is stream" do
|
49
|
-
before(:each) do
|
50
|
-
@stanza = Nokogiri::XML::Node.new("stream", @doc)
|
51
|
-
@stanza["xmlns:stream"] = 'http://etherx.jabber.org/streams'
|
52
|
-
@stanza["xmlns"] = 'jabber:component:accept'
|
53
|
-
@stanza["from"] = 'plays.shakespeare.lit'
|
54
|
-
@stanza["id"] = "1234"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should send a handshake" do
|
58
|
-
@component.should_receive(:handshake)
|
59
|
-
@component.receive_stanza(@stanza)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should change state to wait_for_handshake" do
|
63
|
-
@component.receive_stanza(@stanza)
|
64
|
-
@component.instance_variable_get("@state").should == :wait_for_handshake
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "if the stanza is not stream or deosn't have an id" do
|
70
|
-
it "should raise an error" do
|
71
|
-
lambda {@component.receive_stanza(Nokogiri::XML::Node.new("else", @doc))}.should raise_error
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "when waiting for handshake" do
|
78
|
-
before(:each) do
|
79
|
-
@component.instance_variable_set("@state", :wait_for_handshake)
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "if we actually get a handshake stanza" do
|
83
|
-
|
84
|
-
before(:each) do
|
85
|
-
@handshake = Nokogiri::XML::Node.new("handshake", @doc)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should set the status as connected" do
|
89
|
-
@component.receive_stanza(@handshake)
|
90
|
-
@component.instance_variable_get("@state").should == :connected
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should call the connection callback" do
|
94
|
-
handler_mock.should_receive(:on_connected).with(@component)
|
95
|
-
@component.receive_stanza(@handshake)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "if we receive a stream:error" do
|
100
|
-
it "should raise an Authentication Error" do
|
101
|
-
lambda {@component.receive_stanza(Nokogiri::XML::Node.new("error", @doc))}.should raise_error(Skates::AuthenticationError)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "if we receive something else" do
|
106
|
-
it "should raise an error" do
|
107
|
-
lambda {@component.receive_stanza(Nokogiri::XML::Node.new("else", @doc))}.should raise_error
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "stream_namespace" do
|
116
|
-
it "should return jabber:component:accept" do
|
117
|
-
@component.stream_namespace.should == 'jabber:component:accept'
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "handshake" do
|
122
|
-
it "should build a handshake Element with the password and the id of the stanza" do
|
123
|
-
@component.connection_completed
|
124
|
-
doc = Nokogiri::XML::Document.new
|
125
|
-
stanza = Nokogiri::XML::Node.new("stream", doc)
|
126
|
-
stanza["xmlns:stream"] = 'http://etherx.jabber.org/streams'
|
127
|
-
stanza["xmlns"] = 'jabber:component:accept'
|
128
|
-
stanza["from"] = 'plays.shakespeare.lit'
|
129
|
-
stanza["id"] = "1234"
|
130
|
-
@component.__send__(:handshake, stanza).xpath("//handshake").first.content.should == Digest::SHA1::hexdigest(stanza.attributes['id'].content + @params["password"])
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "when resolving" do
|
136
|
-
it "should resolve records" do
|
137
|
-
Skates::ComponentConnection.resolve("xmpp2.superfeedr.com") do |res|
|
138
|
-
res["host"].should == "173.255.193.75"
|
139
|
-
true
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|