jabber4r-revive 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -4
  2. data/.rspec +3 -3
  3. data/.travis.yml +7 -7
  4. data/CHANGELOG +11 -1
  5. data/Gemfile +3 -3
  6. data/README.md +29 -29
  7. data/Rakefile +70 -70
  8. data/jabber4r-revive.gemspec +25 -25
  9. data/lib/jabber4r.rb +38 -33
  10. data/lib/jabber4r/bosh.rb +21 -0
  11. data/lib/jabber4r/bosh/authentication.rb +13 -0
  12. data/lib/jabber4r/bosh/authentication/non_sasl.rb +219 -0
  13. data/lib/jabber4r/bosh/authentication/sasl.rb +239 -0
  14. data/lib/jabber4r/bosh/session.rb +144 -0
  15. data/lib/jabber4r/connection.rb +259 -258
  16. data/lib/jabber4r/debugger.rb +60 -60
  17. data/lib/jabber4r/jid.rb +20 -19
  18. data/lib/jabber4r/protocol.rb +249 -257
  19. data/lib/jabber4r/protocol/authentication.rb +14 -0
  20. data/lib/jabber4r/protocol/authentication/non_sasl.rb +138 -0
  21. data/lib/jabber4r/protocol/authentication/sasl.rb +88 -0
  22. data/lib/jabber4r/protocol/iq.rb +259 -259
  23. data/lib/jabber4r/protocol/message.rb +245 -245
  24. data/lib/jabber4r/protocol/parsed_xml_element.rb +207 -207
  25. data/lib/jabber4r/protocol/presence.rb +160 -160
  26. data/lib/jabber4r/protocol/xml_element.rb +143 -143
  27. data/lib/jabber4r/rexml_1.8_patch.rb +15 -15
  28. data/lib/jabber4r/roster.rb +38 -38
  29. data/lib/jabber4r/session.rb +615 -615
  30. data/lib/jabber4r/version.rb +10 -3
  31. data/spec/lib/jabber4r/bosh/authentication/non_sasl_spec.rb +79 -0
  32. data/spec/lib/jabber4r/bosh/authentication/sasl_spec.rb +42 -0
  33. data/spec/lib/jabber4r/bosh/session_spec.rb +406 -0
  34. data/spec/lib/jabber4r/bosh_spec.rb +0 -0
  35. data/spec/lib/jabber4r/connection_spec.rb +174 -174
  36. data/spec/lib/jabber4r/debugger_spec.rb +35 -35
  37. data/spec/lib/jabber4r/jid_spec.rb +197 -197
  38. data/spec/lib/jabber4r/protocol/authentication/non_sasl_spec.rb +79 -0
  39. data/spec/lib/jabber4r/protocol/authentication/sasl_spec.rb +42 -0
  40. data/spec/spec_helper.rb +11 -11
  41. data/spec/support/mocks/tcp_socket_mock.rb +8 -8
  42. metadata +61 -45
  43. data/Gemfile.lock +0 -45
  44. data/lib/jabber4r/bosh_session.rb +0 -224
  45. data/spec/lib/jabber4r/bosh_session_spec.rb +0 -150
File without changes
@@ -1,174 +1,174 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Jabber::Connection do
5
- let(:socket) { TCPSocketMock.new }
6
- let(:connection) { described_class.new "localhost" }
7
-
8
- before { TCPSocket.stub(:new).and_return socket }
9
-
10
- describe "#connect" do
11
- before { connection.connect }
12
-
13
- it { expect(connection).to be_connected }
14
- it { expect(connection.poll_thread).to be_alive }
15
- it { expect(connection.parser_thread).to be_alive }
16
- it { expect(connection.socket).not_to be_closed }
17
- end
18
-
19
- describe "#close" do
20
- before { connection.connect }
21
- before { connection.close; sleep 0.01 }
22
-
23
- it { expect(connection).to be_disconnected }
24
- it { expect(connection.poll_thread).not_to be_alive }
25
- it { expect(connection.parser_thread).not_to be_alive }
26
- it { expect(connection.socket).to be_closed }
27
- end
28
-
29
- describe "#add_filter" do
30
- context "when filter name and block is given" do
31
- before { connection.add_filter("hello") { 1 } }
32
-
33
- it { expect(connection.filters).to have_key "hello" }
34
- end
35
-
36
- context "when only filter name give" do
37
- it { expect { connection.add_filter("hello") }.to raise_error ArgumentError }
38
- end
39
- end
40
-
41
- describe "#remove_filter" do
42
- before { connection.add_filter("hello") { 1 } }
43
- it { expect(connection.filters).to have_key "hello" }
44
-
45
- it "should remove filter" do
46
- connection.remove_filter("hello")
47
- expect(connection.filters).not_to have_key "hello"
48
- end
49
- end
50
-
51
- describe "#send" do
52
- let(:handler) { proc { 1 } }
53
-
54
- before { connection.connect }
55
- before { Thread.stub(:current).and_return "current" }
56
-
57
- context "when own handler is given" do
58
- before { connection.send("hello", handler) }
59
-
60
- it { expect(connection.handlers).to have_key "current" }
61
- it { expect(connection.handlers["current"]).to eq handler }
62
-
63
- describe "socket" do
64
- it { expect(socket.to_s).to eq "hello" }
65
- end
66
- end
67
-
68
- context "when only block is given" do
69
- before { connection.send("hello") { 1 } }
70
-
71
- it { expect(connection.handlers).to have_key "current" }
72
- end
73
-
74
- context "when handler and block are given" do
75
- before { connection.send("hello", handler) { 1 } }
76
-
77
- it { expect(connection.handlers).to have_key "current" }
78
- it { expect(connection.handlers["current"]).to eq handler }
79
- end
80
-
81
- context "when no handlers and block are given" do
82
- before { connection.send("hello") }
83
-
84
- it { expect(connection.handlers).to be_empty }
85
- end
86
- end
87
-
88
- describe "#receive" do
89
- let(:thread) { double("Pseudo thread", alive?: true) }
90
- let(:element) { double("XML Element", element_consumed?: false) }
91
-
92
- let(:consume) { ->(element) { element.stub(:element_consumed?).and_return true } }
93
- let(:skip) { ->(element) { element.stub(:element_consumed?).and_return false } }
94
-
95
- before { connection.stub :register_parsing_thread }
96
- before { connection.stub :register_polling_thread }
97
-
98
- context "when handlers are not empty" do
99
- context "when filters are empty" do
100
- before do
101
- thread.should_receive(:wakeup)
102
- connection.stub(:handlers).and_return({thread => consume})
103
-
104
- connection.receive(element)
105
- end
106
-
107
- it { expect(connection.handlers).to be_empty }
108
- it { expect(connection.filters).to be_empty }
109
- end
110
-
111
- context "when filters are not empty" do
112
- context "when handler consume element" do
113
- before do
114
- thread.should_receive(:wakeup)
115
- skip.should_not_receive(:call)
116
-
117
- connection.stub(:handlers).and_return({thread => consume})
118
- connection.stub(:filters).and_return({f1: skip})
119
-
120
- connection.receive(element)
121
- end
122
-
123
- it { expect(connection.handlers).to be_empty }
124
- it { expect(connection.filters).not_to be_empty }
125
- end
126
-
127
- context "when handler doesn't consume element" do
128
- before do
129
- thread.should_not_receive(:wakeup)
130
- consume.should_receive(:call).and_call_original
131
-
132
- connection.stub(:handlers).and_return({thread => skip})
133
- connection.stub(:filters).and_return({f1: consume})
134
-
135
- connection.receive(element)
136
- end
137
-
138
- it { expect(connection.handlers).not_to be_empty }
139
- it { expect(connection.filters).not_to be_empty }
140
- end
141
- end
142
- end
143
-
144
- context "when handlers are empty" do
145
- context "when filters are empty" do
146
- before do
147
- thread.should_not_receive(:wakeup)
148
- connection.should_receive(:wait_for_consume?).and_return false
149
-
150
- connection.receive(element)
151
- end
152
-
153
- it { expect(connection.handlers).to be_empty }
154
- it { expect(connection.filters).to be_empty }
155
- end
156
-
157
- context "when filters are not empty" do
158
- before do
159
- thread.should_not_receive(:wakeup)
160
- consume.should_receive(:call).and_call_original
161
-
162
- connection.stub(:filters).and_return({f1: consume})
163
-
164
- connection.receive(element)
165
- end
166
-
167
- it { expect(connection.handlers).to be_empty }
168
- it { expect(connection.filters).not_to be_empty }
169
- end
170
- end
171
-
172
- # TODO : When socket is empty?
173
- end
174
- end
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Jabber::Connection do
5
+ let(:socket) { TCPSocketMock.new }
6
+ let(:connection) { described_class.new "localhost" }
7
+
8
+ before { TCPSocket.stub(:new).and_return socket }
9
+
10
+ describe "#connect" do
11
+ before { connection.connect }
12
+
13
+ it { expect(connection).to be_connected }
14
+ it { expect(connection.poll_thread).to be_alive }
15
+ it { expect(connection.parser_thread).to be_alive }
16
+ it { expect(connection.socket).not_to be_closed }
17
+ end
18
+
19
+ describe "#close" do
20
+ before { connection.connect }
21
+ before { connection.close; sleep 0.01 }
22
+
23
+ it { expect(connection).to be_disconnected }
24
+ it { expect(connection.poll_thread).not_to be_alive }
25
+ it { expect(connection.parser_thread).not_to be_alive }
26
+ it { expect(connection.socket).to be_closed }
27
+ end
28
+
29
+ describe "#add_filter" do
30
+ context "when filter name and block is given" do
31
+ before { connection.add_filter("hello") { 1 } }
32
+
33
+ it { expect(connection.filters).to have_key "hello" }
34
+ end
35
+
36
+ context "when only filter name give" do
37
+ it { expect { connection.add_filter("hello") }.to raise_error ArgumentError }
38
+ end
39
+ end
40
+
41
+ describe "#remove_filter" do
42
+ before { connection.add_filter("hello") { 1 } }
43
+ it { expect(connection.filters).to have_key "hello" }
44
+
45
+ it "should remove filter" do
46
+ connection.remove_filter("hello")
47
+ expect(connection.filters).not_to have_key "hello"
48
+ end
49
+ end
50
+
51
+ describe "#send" do
52
+ let(:handler) { proc { 1 } }
53
+
54
+ before { connection.connect }
55
+ before { Thread.stub(:current).and_return "current" }
56
+
57
+ context "when own handler is given" do
58
+ before { connection.send("hello", handler) }
59
+
60
+ it { expect(connection.handlers).to have_key "current" }
61
+ it { expect(connection.handlers["current"]).to eq handler }
62
+
63
+ describe "socket" do
64
+ it { expect(socket.to_s).to eq "hello" }
65
+ end
66
+ end
67
+
68
+ context "when only block is given" do
69
+ before { connection.send("hello") { 1 } }
70
+
71
+ it { expect(connection.handlers).to have_key "current" }
72
+ end
73
+
74
+ context "when handler and block are given" do
75
+ before { connection.send("hello", handler) { 1 } }
76
+
77
+ it { expect(connection.handlers).to have_key "current" }
78
+ it { expect(connection.handlers["current"]).to eq handler }
79
+ end
80
+
81
+ context "when no handlers and block are given" do
82
+ before { connection.send("hello") }
83
+
84
+ it { expect(connection.handlers).to be_empty }
85
+ end
86
+ end
87
+
88
+ describe "#receive" do
89
+ let(:thread) { double("Pseudo thread", alive?: true) }
90
+ let(:element) { double("XML Element", element_consumed?: false) }
91
+
92
+ let(:consume) { ->(element) { element.stub(:element_consumed?).and_return true } }
93
+ let(:skip) { ->(element) { element.stub(:element_consumed?).and_return false } }
94
+
95
+ before { connection.stub :register_parsing_thread }
96
+ before { connection.stub :register_polling_thread }
97
+
98
+ context "when handlers are not empty" do
99
+ context "when filters are empty" do
100
+ before do
101
+ thread.should_receive(:wakeup)
102
+ connection.stub(:handlers).and_return({thread => consume})
103
+
104
+ connection.receive(element)
105
+ end
106
+
107
+ it { expect(connection.handlers).to be_empty }
108
+ it { expect(connection.filters).to be_empty }
109
+ end
110
+
111
+ context "when filters are not empty" do
112
+ context "when handler consume element" do
113
+ before do
114
+ thread.should_receive(:wakeup)
115
+ skip.should_not_receive(:call)
116
+
117
+ connection.stub(:handlers).and_return({thread => consume})
118
+ connection.stub(:filters).and_return({f1: skip})
119
+
120
+ connection.receive(element)
121
+ end
122
+
123
+ it { expect(connection.handlers).to be_empty }
124
+ it { expect(connection.filters).not_to be_empty }
125
+ end
126
+
127
+ context "when handler doesn't consume element" do
128
+ before do
129
+ thread.should_not_receive(:wakeup)
130
+ consume.should_receive(:call).and_call_original
131
+
132
+ connection.stub(:handlers).and_return({thread => skip})
133
+ connection.stub(:filters).and_return({f1: consume})
134
+
135
+ connection.receive(element)
136
+ end
137
+
138
+ it { expect(connection.handlers).not_to be_empty }
139
+ it { expect(connection.filters).not_to be_empty }
140
+ end
141
+ end
142
+ end
143
+
144
+ context "when handlers are empty" do
145
+ context "when filters are empty" do
146
+ before do
147
+ thread.should_not_receive(:wakeup)
148
+ connection.should_receive(:wait_for_consume?).and_return false
149
+
150
+ connection.receive(element)
151
+ end
152
+
153
+ it { expect(connection.handlers).to be_empty }
154
+ it { expect(connection.filters).to be_empty }
155
+ end
156
+
157
+ context "when filters are not empty" do
158
+ before do
159
+ thread.should_not_receive(:wakeup)
160
+ consume.should_receive(:call).and_call_original
161
+
162
+ connection.stub(:filters).and_return({f1: consume})
163
+
164
+ connection.receive(element)
165
+ end
166
+
167
+ it { expect(connection.handlers).to be_empty }
168
+ it { expect(connection.filters).not_to be_empty }
169
+ end
170
+ end
171
+
172
+ # TODO : When socket is empty?
173
+ end
174
+ end
@@ -1,36 +1,36 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Jabber::Debugger do
5
- let(:debugger) { described_class.clone.instance }
6
- before { described_class.stub(:instance).and_return debugger }
7
-
8
- describe "#initialize" do
9
- it { expect(described_class).not_to be_enabled }
10
- end
11
-
12
- describe "#enable" do
13
- before { described_class.enable! }
14
-
15
- it { expect(described_class).to be_enabled }
16
- end
17
-
18
- describe "#disable" do
19
- before { described_class.disable! }
20
-
21
- it { expect(described_class).not_to be_enabled }
22
- end
23
-
24
- describe "#logger=" do
25
- let(:logger) { double("Logger") }
26
-
27
- before { described_class.logger = logger }
28
- it { expect(debugger.logger).to eq logger }
29
- end
30
-
31
- describe "generated methods" do
32
- it { expect(described_class).to respond_to :warn }
33
- it { expect(described_class).to respond_to :info }
34
- it { expect(described_class).to respond_to :debug }
35
- end
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Jabber::Debugger do
5
+ let(:debugger) { described_class.clone.instance }
6
+ before { described_class.stub(:instance).and_return debugger }
7
+
8
+ describe "#initialize" do
9
+ it { expect(described_class).not_to be_enabled }
10
+ end
11
+
12
+ describe "#enable" do
13
+ before { described_class.enable! }
14
+
15
+ it { expect(described_class).to be_enabled }
16
+ end
17
+
18
+ describe "#disable" do
19
+ before { described_class.disable! }
20
+
21
+ it { expect(described_class).not_to be_enabled }
22
+ end
23
+
24
+ describe "#logger=" do
25
+ let(:logger) { double("Logger") }
26
+
27
+ before { described_class.logger = logger }
28
+ it { expect(debugger.logger).to eq logger }
29
+ end
30
+
31
+ describe "generated methods" do
32
+ it { expect(described_class).to respond_to :warn }
33
+ it { expect(described_class).to respond_to :info }
34
+ it { expect(described_class).to respond_to :debug }
35
+ end
36
36
  end
@@ -1,198 +1,198 @@
1
- # coding: utf-8
2
- require "spec_helper"
3
-
4
- describe Jabber::JID do
5
- describe "#initialize" do
6
- context "when need parse jid from string" do
7
- context "when only node given" do
8
- it { expect { described_class.new "user" }.to raise_error ArgumentError }
9
- end
10
-
11
- context "when node and host given" do
12
- subject { described_class.new "user@localhost" }
13
-
14
- its(:node) { should eq "user" }
15
- its(:host) { should eq "localhost" }
16
- its(:resource) { should be_nil }
17
- end
18
-
19
- context "when node, host and resource given" do
20
- subject { described_class.new "user@localhost/attach" }
21
-
22
- its(:node) { should eq "user" }
23
- its(:host) { should eq "localhost" }
24
- its(:resource) { should eq "attach" }
25
- end
26
-
27
- context "when empty string given" do
28
- it { expect { described_class.new "" }.to raise_error ArgumentError }
29
- end
30
- end
31
-
32
- context "when extra arguments given" do
33
- context "when only host given" do
34
- subject { described_class.new "user", "localhost" }
35
-
36
- its(:node) { should eq "user" }
37
- its(:host) { should eq "localhost" }
38
- end
39
-
40
- context "when host and resource given" do
41
- subject { described_class.new "user", "localhost", "attach" }
42
-
43
- its(:node) { should eq "user" }
44
- its(:host) { should eq "localhost" }
45
- its(:resource) { should eq "attach" }
46
- end
47
-
48
- context "when node is fully loaded and host, resource given" do
49
- subject { described_class.new "user@example.com/bind", "localhost", "attach" }
50
-
51
- its(:node) { should eq "user" }
52
- its(:host) { should eq "localhost" }
53
- its(:resource) { should eq "attach" }
54
- end
55
- end
56
- end
57
-
58
- describe "#strip" do
59
- subject { described_class.new(args).strip }
60
-
61
- context "when JID has no resource" do
62
- let(:args) { "strech@localhost" }
63
-
64
- its(:to_s) { should eq "strech@localhost" }
65
- end
66
-
67
- context "when JID has no resource" do
68
- let(:args) { "strech@localhost/pewpew" }
69
-
70
- its(:to_s) { should eq "strech@localhost" }
71
- end
72
- end
73
-
74
- describe "#strip!" do
75
- subject { described_class.new(args).strip! }
76
-
77
- context "when JID has no resource" do
78
- let(:args) { "strech@localhost" }
79
-
80
- its(:to_s) { should eq "strech@localhost" }
81
- its(:resource) { should be_nil }
82
- end
83
-
84
- context "when JID has no resource" do
85
- let(:args) { "strech@localhost/pewpew" }
86
-
87
- its(:to_s) { should eq "strech@localhost" }
88
- its(:resource) { should be_nil }
89
- end
90
- end
91
-
92
- describe "#hash" do
93
- let(:hash) { "strech@pewpew/one".hash }
94
- subject { described_class.new "strech@pewpew/one" }
95
-
96
- its(:hash) { should eq hash }
97
- end
98
-
99
- describe "#to_s" do
100
- context "when only host and domain exists" do
101
- subject { described_class.new("strech", "localhost").to_s }
102
-
103
- it { should eq "strech@localhost" }
104
- end
105
-
106
- context "when only host and domain exists" do
107
- subject { described_class.new("strech", "localhost", "attach-resource").to_s }
108
-
109
- it { should eq "strech@localhost/attach-resource" }
110
- end
111
- end
112
-
113
- describe "#==" do
114
- subject { jid1 == jid2 }
115
-
116
- context "when jids are equal" do
117
- let(:jid1) { described_class.new "strech@localhost" }
118
- let(:jid2) { described_class.new "strech@localhost" }
119
-
120
- it { should be_true }
121
- end
122
-
123
- context "when jids are not equal" do
124
- let(:jid1) { described_class.new "strech@localhost" }
125
- let(:jid2) { described_class.new "strech@localhost/resource1" }
126
-
127
- it { should be_false }
128
- end
129
- end
130
-
131
- describe "#same?" do
132
- subject { jid1.same? jid2 }
133
-
134
- context "when jids are equal" do
135
- context "when jid1 and jid2 has no resource" do
136
- let(:jid1) { described_class.new "strech@localhost" }
137
- let(:jid2) { described_class.new "strech@localhost" }
138
-
139
- it { should be_true }
140
- end
141
-
142
- context "when jid1 has resource, but jid2 not" do
143
- let(:jid1) { described_class.new "strech@localhost/pewpew" }
144
- let(:jid2) { described_class.new "strech@localhost" }
145
-
146
- it { should be_true }
147
- end
148
-
149
- context "when jid1 and jid2 has resources" do
150
- let(:jid1) { described_class.new "strech@localhost/pewpew" }
151
- let(:jid2) { described_class.new "strech@localhost/hola" }
152
-
153
- it { should be_true }
154
- end
155
- end
156
-
157
- context "when jids are not equal" do
158
- context "when jid1 and jid2 has no resource" do
159
- let(:jid1) { described_class.new "strech@localhost" }
160
- let(:jid2) { described_class.new "strech@gmail.com" }
161
-
162
- it { should be_false }
163
- end
164
-
165
- context "when jid1 has resource, but jid2 not" do
166
- let(:jid1) { described_class.new "strech@localhost/pewpew" }
167
- let(:jid2) { described_class.new "strech@gmail.com" }
168
-
169
- it { should be_false }
170
- end
171
-
172
- context "when jid1 and jid2 has resources" do
173
- let(:jid1) { described_class.new "strech@localhost/pewpew" }
174
- let(:jid2) { described_class.new "strech@gmail.com/hola" }
175
-
176
- it { should be_false }
177
- end
178
- end
179
- end
180
-
181
- describe "::to_jid" do
182
- subject { Jabber::JID.to_jid jid }
183
-
184
- context "when jid is a Jabber::JID" do
185
- let(:jid) { described_class.new "strech@localhost" }
186
-
187
- its(:object_id) { should eq jid.object_id }
188
- its(:to_s) { should eq "strech@localhost" }
189
- end
190
-
191
- context "when jid is a String" do
192
- let(:jid) { "strech@localhost/resource" }
193
-
194
- its(:object_id) { should_not eq jid.object_id }
195
- its(:to_s) { should eq "strech@localhost/resource" }
196
- end
197
- end
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Jabber::JID do
5
+ describe "#initialize" do
6
+ context "when need parse jid from string" do
7
+ context "when only node given" do
8
+ it { expect { described_class.new "user" }.to raise_error ArgumentError }
9
+ end
10
+
11
+ context "when node and domain given" do
12
+ subject { described_class.new "user@localhost" }
13
+
14
+ its(:node) { should eq "user" }
15
+ its(:domain) { should eq "localhost" }
16
+ its(:resource) { should be_nil }
17
+ end
18
+
19
+ context "when node, domain and resource given" do
20
+ subject { described_class.new "user@localhost/attach" }
21
+
22
+ its(:node) { should eq "user" }
23
+ its(:domain) { should eq "localhost" }
24
+ its(:resource) { should eq "attach" }
25
+ end
26
+
27
+ context "when empty string given" do
28
+ it { expect { described_class.new "" }.to raise_error ArgumentError }
29
+ end
30
+ end
31
+
32
+ context "when extra arguments given" do
33
+ context "when only domain given" do
34
+ subject { described_class.new "user", "localhost" }
35
+
36
+ its(:node) { should eq "user" }
37
+ its(:domain) { should eq "localhost" }
38
+ end
39
+
40
+ context "when domain and resource given" do
41
+ subject { described_class.new "user", "localhost", "attach" }
42
+
43
+ its(:node) { should eq "user" }
44
+ its(:domain) { should eq "localhost" }
45
+ its(:resource) { should eq "attach" }
46
+ end
47
+
48
+ context "when node is fully loaded and domain, resource given" do
49
+ subject { described_class.new "user@example.com/bind", "localhost", "attach" }
50
+
51
+ its(:node) { should eq "user" }
52
+ its(:domain) { should eq "localhost" }
53
+ its(:resource) { should eq "attach" }
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#strip" do
59
+ subject { described_class.new(args).strip }
60
+
61
+ context "when JID has no resource" do
62
+ let(:args) { "strech@localhost" }
63
+
64
+ its(:to_s) { should eq "strech@localhost" }
65
+ end
66
+
67
+ context "when JID has no resource" do
68
+ let(:args) { "strech@localhost/pewpew" }
69
+
70
+ its(:to_s) { should eq "strech@localhost" }
71
+ end
72
+ end
73
+
74
+ describe "#strip!" do
75
+ subject { described_class.new(args).strip! }
76
+
77
+ context "when JID has no resource" do
78
+ let(:args) { "strech@localhost" }
79
+
80
+ its(:to_s) { should eq "strech@localhost" }
81
+ its(:resource) { should be_nil }
82
+ end
83
+
84
+ context "when JID has no resource" do
85
+ let(:args) { "strech@localhost/pewpew" }
86
+
87
+ its(:to_s) { should eq "strech@localhost" }
88
+ its(:resource) { should be_nil }
89
+ end
90
+ end
91
+
92
+ describe "#hash" do
93
+ let(:hash) { "strech@pewpew/one".hash }
94
+ subject { described_class.new "strech@pewpew/one" }
95
+
96
+ its(:hash) { should eq hash }
97
+ end
98
+
99
+ describe "#to_s" do
100
+ context "when only domain and domain exists" do
101
+ subject { described_class.new("strech", "localhost").to_s }
102
+
103
+ it { should eq "strech@localhost" }
104
+ end
105
+
106
+ context "when only domain and domain exists" do
107
+ subject { described_class.new("strech", "localhost", "attach-resource").to_s }
108
+
109
+ it { should eq "strech@localhost/attach-resource" }
110
+ end
111
+ end
112
+
113
+ describe "#==" do
114
+ subject { jid1 == jid2 }
115
+
116
+ context "when jids are equal" do
117
+ let(:jid1) { described_class.new "strech@localhost" }
118
+ let(:jid2) { described_class.new "strech@localhost" }
119
+
120
+ it { should be_true }
121
+ end
122
+
123
+ context "when jids are not equal" do
124
+ let(:jid1) { described_class.new "strech@localhost" }
125
+ let(:jid2) { described_class.new "strech@localhost/resource1" }
126
+
127
+ it { should be_false }
128
+ end
129
+ end
130
+
131
+ describe "#same?" do
132
+ subject { jid1.same? jid2 }
133
+
134
+ context "when jids are equal" do
135
+ context "when jid1 and jid2 has no resource" do
136
+ let(:jid1) { described_class.new "strech@localhost" }
137
+ let(:jid2) { described_class.new "strech@localhost" }
138
+
139
+ it { should be_true }
140
+ end
141
+
142
+ context "when jid1 has resource, but jid2 not" do
143
+ let(:jid1) { described_class.new "strech@localhost/pewpew" }
144
+ let(:jid2) { described_class.new "strech@localhost" }
145
+
146
+ it { should be_true }
147
+ end
148
+
149
+ context "when jid1 and jid2 has resources" do
150
+ let(:jid1) { described_class.new "strech@localhost/pewpew" }
151
+ let(:jid2) { described_class.new "strech@localhost/hola" }
152
+
153
+ it { should be_true }
154
+ end
155
+ end
156
+
157
+ context "when jids are not equal" do
158
+ context "when jid1 and jid2 has no resource" do
159
+ let(:jid1) { described_class.new "strech@localhost" }
160
+ let(:jid2) { described_class.new "strech@gmail.com" }
161
+
162
+ it { should be_false }
163
+ end
164
+
165
+ context "when jid1 has resource, but jid2 not" do
166
+ let(:jid1) { described_class.new "strech@localhost/pewpew" }
167
+ let(:jid2) { described_class.new "strech@gmail.com" }
168
+
169
+ it { should be_false }
170
+ end
171
+
172
+ context "when jid1 and jid2 has resources" do
173
+ let(:jid1) { described_class.new "strech@localhost/pewpew" }
174
+ let(:jid2) { described_class.new "strech@gmail.com/hola" }
175
+
176
+ it { should be_false }
177
+ end
178
+ end
179
+ end
180
+
181
+ describe "::to_jid" do
182
+ subject { Jabber::JID.to_jid jid }
183
+
184
+ context "when jid is a Jabber::JID" do
185
+ let(:jid) { described_class.new "strech@localhost" }
186
+
187
+ its(:object_id) { should eq jid.object_id }
188
+ its(:to_s) { should eq "strech@localhost" }
189
+ end
190
+
191
+ context "when jid is a String" do
192
+ let(:jid) { "strech@localhost/resource" }
193
+
194
+ its(:object_id) { should_not eq jid.object_id }
195
+ its(:to_s) { should eq "strech@localhost/resource" }
196
+ end
197
+ end
198
198
  end