uv-rays 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  require 'uv-rays'
2
2
 
3
- describe UvRays::BufferedTokenizer do
3
+ describe UV::BufferedTokenizer do
4
4
  describe 'delimiter' do
5
5
 
6
6
  before :each do
7
- @buffer = UvRays::BufferedTokenizer.new({
7
+ @buffer = UV::BufferedTokenizer.new({
8
8
  delimiter: "\n\r"
9
9
  })
10
10
  end
@@ -14,21 +14,21 @@ describe UvRays::BufferedTokenizer do
14
14
  msg1 = "test"
15
15
 
16
16
  result = @buffer.extract(msg1)
17
- result.should == []
17
+ expect(result).to eq([])
18
18
  end
19
19
 
20
20
  it "should tokenize messages where the data is a complete message" do
21
21
  msg1 = "test\n\r"
22
22
 
23
23
  result = @buffer.extract(msg1)
24
- result.should == ['test']
24
+ expect(result).to eq(['test'])
25
25
  end
26
26
 
27
27
  it "should return multiple complete messages" do
28
28
  msg1 = "test\n\rwhoa\n\r"
29
29
 
30
30
  result = @buffer.extract(msg1)
31
- result.should == ['test', 'whoa']
31
+ expect(result).to eq(['test', 'whoa'])
32
32
  end
33
33
 
34
34
  it "should tokenize messages where the delimiter is split" do
@@ -36,9 +36,9 @@ describe UvRays::BufferedTokenizer do
36
36
  msg2 = "\rwhoa\n\r"
37
37
 
38
38
  result = @buffer.extract(msg1)
39
- result.should == []
39
+ expect(result).to eq([])
40
40
  result = @buffer.extract(msg2)
41
- result.should == ['test', 'whoa']
41
+ expect(result).to eq(['test', 'whoa'])
42
42
 
43
43
 
44
44
  msg3 = "test\n"
@@ -46,19 +46,19 @@ describe UvRays::BufferedTokenizer do
46
46
  msg5 = "\r"
47
47
 
48
48
  result = @buffer.extract(msg3)
49
- result.should == []
49
+ expect(result).to eq([])
50
50
  result = @buffer.extract(msg4)
51
- result.should == ['test']
51
+ expect(result).to eq(['test'] )
52
52
 
53
53
  result = @buffer.extract(msg5)
54
- result.should == ['whoa']
54
+ expect(result).to eq(['whoa'])
55
55
  end
56
56
  end
57
57
 
58
58
  describe 'delimiter' do
59
59
 
60
60
  before :each do
61
- @buffer = UvRays::BufferedTokenizer.new({
61
+ @buffer = UV::BufferedTokenizer.new({
62
62
  delimiter: "\n\r"
63
63
  })
64
64
  end
@@ -68,28 +68,28 @@ describe UvRays::BufferedTokenizer do
68
68
  msg1 = "test"
69
69
 
70
70
  result = @buffer.extract(msg1)
71
- result.should == []
71
+ expect(result).to eq([])
72
72
  end
73
73
 
74
74
  it "should not return anything when the messages is empty" do
75
75
  msg1 = ""
76
76
 
77
77
  result = @buffer.extract(msg1)
78
- result.should == []
78
+ expect(result).to eq([])
79
79
  end
80
80
 
81
81
  it "should tokenize messages where the data is a complete message" do
82
82
  msg1 = "test\n\r"
83
83
 
84
84
  result = @buffer.extract(msg1)
85
- result.should == ['test']
85
+ expect(result).to eq(['test'])
86
86
  end
87
87
 
88
88
  it "should return multiple complete messages" do
89
89
  msg1 = "test\n\rwhoa\n\r"
90
90
 
91
91
  result = @buffer.extract(msg1)
92
- result.should == ['test', 'whoa']
92
+ expect(result).to eq(['test', 'whoa'])
93
93
  end
94
94
 
95
95
  it "should tokenize messages where the delimiter is split" do
@@ -97,9 +97,9 @@ describe UvRays::BufferedTokenizer do
97
97
  msg2 = "\rwhoa\n\r"
98
98
 
99
99
  result = @buffer.extract(msg1)
100
- result.should == []
100
+ expect(result).to eq([])
101
101
  result = @buffer.extract(msg2)
102
- result.should == ['test', 'whoa']
102
+ expect(result).to eq(['test', 'whoa'])
103
103
 
104
104
 
105
105
  msg3 = "test\n"
@@ -107,12 +107,12 @@ describe UvRays::BufferedTokenizer do
107
107
  msg5 = "\r"
108
108
 
109
109
  result = @buffer.extract(msg3)
110
- result.should == []
110
+ expect(result).to eq([])
111
111
  result = @buffer.extract(msg4)
112
- result.should == ['test']
112
+ expect(result).to eq(['test'] )
113
113
 
114
114
  result = @buffer.extract(msg5)
115
- result.should == ['whoa']
115
+ expect(result).to eq(['whoa'])
116
116
  end
117
117
  end
118
118
 
@@ -121,7 +121,7 @@ describe UvRays::BufferedTokenizer do
121
121
  describe 'indicator with delimiter' do
122
122
 
123
123
  before :each do
124
- @buffer = UvRays::BufferedTokenizer.new({
124
+ @buffer = UV::BufferedTokenizer.new({
125
125
  delimiter: "\n\r",
126
126
  indicator: "GO"
127
127
  })
@@ -132,42 +132,42 @@ describe UvRays::BufferedTokenizer do
132
132
  msg1 = "GO-somedata"
133
133
 
134
134
  result = @buffer.extract(msg1)
135
- result.should == []
135
+ expect(result).to eq([])
136
136
  end
137
137
 
138
138
  it "should not return anything when the messages is empty" do
139
139
  msg1 = ""
140
140
 
141
141
  result = @buffer.extract(msg1)
142
- result.should == []
142
+ expect(result).to eq([])
143
143
  end
144
144
 
145
145
  it "should tokenize messages where the data is a complete message" do
146
146
  msg1 = "GOtest\n\r"
147
147
 
148
148
  result = @buffer.extract(msg1)
149
- result.should == ['test']
149
+ expect(result).to eq(['test'])
150
150
  end
151
151
 
152
152
  it "should discard data that is not relevant" do
153
153
  msg1 = "1234-GOtest\n\r"
154
154
 
155
155
  result = @buffer.extract(msg1)
156
- result.should == ['test']
156
+ expect(result).to eq(['test'])
157
157
  end
158
158
 
159
159
  it "should return multiple complete messages" do
160
160
  msg1 = "GOtest\n\rGOwhoa\n\r"
161
161
 
162
162
  result = @buffer.extract(msg1)
163
- result.should == ['test', 'whoa']
163
+ expect(result).to eq(['test', 'whoa'])
164
164
  end
165
165
 
166
166
  it "should discard data between multiple complete messages" do
167
167
  msg1 = "1234-GOtest\n\r12345-GOwhoa\n\r"
168
168
 
169
169
  result = @buffer.extract(msg1)
170
- result.should == ['test', 'whoa']
170
+ expect(result).to eq(['test', 'whoa'])
171
171
  end
172
172
 
173
173
  it "should tokenize messages where the delimiter is split" do
@@ -175,9 +175,9 @@ describe UvRays::BufferedTokenizer do
175
175
  msg2 = "\rGOwhoa\n\r"
176
176
 
177
177
  result = @buffer.extract(msg1)
178
- result.should == []
178
+ expect(result).to eq([])
179
179
  result = @buffer.extract(msg2)
180
- result.should == ['test', 'whoa']
180
+ expect(result).to eq(['test', 'whoa'])
181
181
 
182
182
 
183
183
  msg3 = "GOtest\n"
@@ -185,12 +185,12 @@ describe UvRays::BufferedTokenizer do
185
185
  msg5 = "\r"
186
186
 
187
187
  result = @buffer.extract(msg3)
188
- result.should == []
188
+ expect(result).to eq([])
189
189
  result = @buffer.extract(msg4)
190
- result.should == ['test']
190
+ expect(result).to eq(['test'] )
191
191
 
192
192
  result = @buffer.extract(msg5)
193
- result.should == ['whoa']
193
+ expect(result).to eq(['whoa'])
194
194
  end
195
195
 
196
196
  it "should tokenize messages where the indicator is split" do
@@ -199,11 +199,11 @@ describe UvRays::BufferedTokenizer do
199
199
  msg3 = "\rGOwhoa\n\r"
200
200
 
201
201
  result = @buffer.extract(msg1)
202
- result.should == ['test']
202
+ expect(result).to eq(['test'])
203
203
  result = @buffer.extract(msg2)
204
- result.should == []
204
+ expect(result).to eq([])
205
205
  result = @buffer.extract(msg3)
206
- result.should == ['whoa', 'whoa']
206
+ expect(result).to eq(['whoa', 'whoa'])
207
207
  end
208
208
 
209
209
  it "should tokenize messages where the indicator is split and there is discard data" do
@@ -212,17 +212,17 @@ describe UvRays::BufferedTokenizer do
212
212
  msg3 = "\r1234GOwhoa\n\r"
213
213
 
214
214
  result = @buffer.extract(msg1)
215
- result.should == ['test']
215
+ expect(result).to eq(['test'])
216
216
  result = @buffer.extract(msg2)
217
- result.should == []
217
+ expect(result).to eq([])
218
218
  result = @buffer.extract(msg3)
219
- result.should == ['whoa', 'whoa']
219
+ expect(result).to eq(['whoa', 'whoa'])
220
220
  end
221
221
  end
222
222
 
223
223
  describe 'buffer size limit with indicator' do
224
224
  before :each do
225
- @buffer = UvRays::BufferedTokenizer.new({
225
+ @buffer = UV::BufferedTokenizer.new({
226
226
  delimiter: "\n\r",
227
227
  indicator: "Start",
228
228
  size_limit: 10
@@ -231,14 +231,14 @@ describe UvRays::BufferedTokenizer do
231
231
 
232
232
  it "should empty the buffer if the limit is exceeded" do
233
233
  result = @buffer.extract('1234567890G')
234
- result.should == []
235
- @buffer.flush.should == '890G'
234
+ expect(result).to eq([])
235
+ expect(@buffer.flush).to eq('890G')
236
236
  end
237
237
  end
238
238
 
239
239
  describe 'buffer size limit without indicator' do
240
240
  before :each do
241
- @buffer = UvRays::BufferedTokenizer.new({
241
+ @buffer = UV::BufferedTokenizer.new({
242
242
  delimiter: "\n\r",
243
243
  size_limit: 10
244
244
  })
@@ -246,8 +246,8 @@ describe UvRays::BufferedTokenizer do
246
246
 
247
247
  it "should empty the buffer if the limit is exceeded" do
248
248
  result = @buffer.extract('1234567890G')
249
- result.should == []
250
- @buffer.flush.should == ''
249
+ expect(result).to eq([])
250
+ expect(@buffer.flush).to eq('')
251
251
  end
252
252
  end
253
253
  end
@@ -44,7 +44,7 @@ module TestServer
44
44
  end
45
45
 
46
46
 
47
- describe UvRays::Connection do
47
+ describe UV::Connection do
48
48
  before :each do
49
49
  @loop = Libuv::Loop.new
50
50
  @general_failure = []
@@ -57,10 +57,16 @@ describe UvRays::Connection do
57
57
 
58
58
  after :each do
59
59
  module TestConnect
60
- remove_const :UR_CONNECTION_CLASS
60
+ begin
61
+ remove_const :UR_CONNECTION_CLASS
62
+ rescue
63
+ end
61
64
  end
62
65
  module TestServer
63
- remove_const :UR_CONNECTION_CLASS
66
+ begin
67
+ remove_const :UR_CONNECTION_CLASS
68
+ rescue
69
+ end
64
70
  end
65
71
  end
66
72
 
@@ -79,11 +85,31 @@ describe UvRays::Connection do
79
85
  @klass = UV.connect '127.0.0.1', 3210, TestConnect
80
86
  }
81
87
 
82
- @general_failure.should == []
88
+ expect(@general_failure).to eq([])
83
89
  res = @klass.check
84
- res[0].should == true
85
- res[1].should == true
86
- res[2].should == 'hello'
90
+ expect(res[0]).to eq(true)
91
+ expect(res[1]).to eq(true)
92
+ expect(res[2]).to eq('hello')
93
+ end
94
+
95
+ it "should not call connect on connection failure", :network => true do
96
+ @loop.run { |logger|
97
+ logger.progress do |level, errorid, error|
98
+ begin
99
+ @general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
100
+ rescue Exception
101
+ @general_failure << 'error in logger'
102
+ end
103
+ end
104
+
105
+ @klass = UV.connect '127.0.0.1', 8123, TestConnect
106
+ }
107
+
108
+ expect(@general_failure).to eq([])
109
+ res = @klass.check
110
+ expect(res[0]).to eq(nil)
111
+ expect(res[1]).to eq(true) # Disconnect
112
+ expect(res[2]).to eq(nil)
87
113
  end
88
114
  end
89
115
 
@@ -103,11 +129,11 @@ describe UvRays::Connection do
103
129
  @klass.use_tls
104
130
  }
105
131
 
106
- @general_failure.should == []
132
+ expect(@general_failure).to eq([])
107
133
  res = @klass.check
108
- res[0].should == true
109
- res[1].should == true
110
- res[2].should == 'hello'
134
+ expect(res[0]).to eq(true)
135
+ expect(res[1]).to eq(true)
136
+ expect(res[2]).to eq('hello')
111
137
  end
112
138
  end
113
139
 
@@ -127,11 +153,11 @@ describe UvRays::Connection do
127
153
  @klass.send_datagram('hello', '127.0.0.1', 3210)
128
154
  }
129
155
 
130
- @general_failure.should == []
156
+ expect(@general_failure).to eq([])
131
157
  res = @klass.check
132
- res[0].should == nil
133
- res[1].should == nil
134
- res[2].should == nil #'hello' (libuv receive bug?)
158
+ expect(res[0]).to eq(nil)
159
+ expect(res[1]).to eq(nil)
160
+ expect(res[2]).to eq(nil) #'hello' (libuv receive bug?)
135
161
  end
136
162
  end
137
163
  end
@@ -40,7 +40,7 @@ module OldServer
40
40
  end
41
41
 
42
42
 
43
- describe UvRays::HttpEndpoint do
43
+ describe UV::HttpEndpoint do
44
44
  before :each do
45
45
  @loop = Libuv::Loop.new
46
46
  @general_failure = []
@@ -78,12 +78,12 @@ describe UvRays::HttpEndpoint do
78
78
  }, @request_failure)
79
79
  }
80
80
 
81
- @general_failure.should == []
82
- @response[:headers][:"Content-type"].should == 'text/html'
83
- @response[:headers].http_version.should == '1.1'
84
- @response[:headers].status.should == 200
85
- @response[:headers].cookies.should == {}
86
- @response[:headers].keep_alive.should == true
81
+ expect(@general_failure).to eq([])
82
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
83
+ expect(@response[:headers].http_version).to eq('1.1')
84
+ expect(@response[:headers].status).to eq(200)
85
+ expect(@response[:headers].cookies).to eq({})
86
+ expect(@response[:headers].keep_alive).to eq(true)
87
87
  end
88
88
 
89
89
  it "should send multiple requests on the same connection", :network => true do
@@ -113,18 +113,18 @@ describe UvRays::HttpEndpoint do
113
113
  }, @request_failure)
114
114
  }
115
115
 
116
- @general_failure.should == []
117
- @response[:headers][:"Content-type"].should == 'text/html'
118
- @response[:headers].http_version.should == '1.1'
119
- @response[:headers].status.should == 200
120
- @response[:headers].cookies.should == {}
121
- @response[:headers].keep_alive.should == true
122
-
123
- @response2[:headers][:"Content-type"].should == 'text/html'
124
- @response2[:headers].http_version.should == '1.1'
125
- @response2[:headers].status.should == 200
126
- @response2[:headers].cookies.should == {}
127
- @response2[:headers].keep_alive.should == true
116
+ expect(@general_failure).to eq([])
117
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
118
+ expect(@response[:headers].http_version).to eq('1.1')
119
+ expect(@response[:headers].status).to eq(200)
120
+ expect(@response[:headers].cookies).to eq({})
121
+ expect(@response[:headers].keep_alive).to eq(true)
122
+
123
+ expect(@response2[:headers][:"Content-type"]).to eq('text/html')
124
+ expect(@response2[:headers].http_version).to eq('1.1')
125
+ expect(@response2[:headers].status).to eq(200)
126
+ expect(@response2[:headers].cookies).to eq({})
127
+ expect(@response2[:headers].keep_alive).to eq(true)
128
128
  end
129
129
 
130
130
  it "should send pipelined requests on the same connection", :network => true do
@@ -154,18 +154,18 @@ describe UvRays::HttpEndpoint do
154
154
  }, @request_failure)
155
155
  }
156
156
 
157
- @general_failure.should == []
158
- @response[:headers][:"Content-type"].should == 'text/html'
159
- @response[:headers].http_version.should == '1.1'
160
- @response[:headers].status.should == 200
161
- @response[:headers].cookies.should == {}
162
- @response[:headers].keep_alive.should == true
163
-
164
- @response2[:headers][:"Content-type"].should == 'text/html'
165
- @response2[:headers].http_version.should == '1.1'
166
- @response2[:headers].status.should == 200
167
- @response2[:headers].cookies.should == {}
168
- @response2[:headers].keep_alive.should == true
157
+ expect(@general_failure).to eq([])
158
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
159
+ expect(@response[:headers].http_version).to eq('1.1')
160
+ expect(@response[:headers].status).to eq(200)
161
+ expect(@response[:headers].cookies).to eq({})
162
+ expect(@response[:headers].keep_alive).to eq(true)
163
+
164
+ expect(@response2[:headers][:"Content-type"]).to eq('text/html')
165
+ expect(@response2[:headers].http_version).to eq('1.1')
166
+ expect(@response2[:headers].status).to eq(200)
167
+ expect(@response2[:headers].cookies).to eq({})
168
+ expect(@response2[:headers].keep_alive).to eq(true)
169
169
  end
170
170
  end
171
171
 
@@ -191,12 +191,12 @@ describe UvRays::HttpEndpoint do
191
191
  }, @request_failure)
192
192
  }
193
193
 
194
- @general_failure.should == []
195
- @response[:headers][:"Content-type"].should == 'text/html'
196
- @response[:headers].http_version.should == '1.0'
197
- @response[:headers].status.should == 200
198
- @response[:headers].cookies.should == {}
199
- @response[:headers].keep_alive.should == false
194
+ expect(@general_failure).to eq([])
195
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
196
+ expect(@response[:headers].http_version).to eq('1.0')
197
+ expect(@response[:headers].status).to eq(200)
198
+ expect(@response[:headers].cookies).to eq({})
199
+ expect(@response[:headers].keep_alive).to eq(false)
200
200
  end
201
201
 
202
202
  it "should send multiple requests", :network => true do
@@ -226,18 +226,18 @@ describe UvRays::HttpEndpoint do
226
226
  }, @request_failure)
227
227
  }
228
228
 
229
- @general_failure.should == []
230
- @response[:headers][:"Content-type"].should == 'text/html'
231
- @response[:headers].http_version.should == '1.0'
232
- @response[:headers].status.should == 200
233
- @response[:headers].cookies.should == {}
234
- @response[:headers].keep_alive.should == false
235
-
236
- @response2[:headers][:"Content-type"].should == 'text/html'
237
- @response2[:headers].http_version.should == '1.0'
238
- @response2[:headers].status.should == 200
239
- @response2[:headers].cookies.should == {}
240
- @response2[:headers].keep_alive.should == false
229
+ expect(@general_failure).to eq([])
230
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
231
+ expect(@response[:headers].http_version).to eq('1.0')
232
+ expect(@response[:headers].status).to eq(200)
233
+ expect(@response[:headers].cookies).to eq({})
234
+ expect(@response[:headers].keep_alive).to eq(false)
235
+
236
+ expect(@response2[:headers][:"Content-type"]).to eq('text/html')
237
+ expect(@response2[:headers].http_version).to eq('1.0')
238
+ expect(@response2[:headers].status).to eq(200)
239
+ expect(@response2[:headers].cookies).to eq({})
240
+ expect(@response2[:headers].keep_alive).to eq(false)
241
241
  end
242
242
 
243
243
  it "should fail to send pipelined requests", :network => true do
@@ -267,12 +267,12 @@ describe UvRays::HttpEndpoint do
267
267
  }, @request_failure)
268
268
  }
269
269
 
270
- @general_failure.should == [:disconnected]
271
- @response[:headers][:"Content-type"].should == 'text/html'
272
- @response[:headers].http_version.should == '1.0'
273
- @response[:headers].status.should == 200
274
- @response[:headers].cookies.should == {}
275
- @response[:headers].keep_alive.should == false
270
+ expect(@general_failure).to eq([:disconnected])
271
+ expect(@response[:headers][:"Content-type"]).to eq('text/html')
272
+ expect(@response[:headers].http_version).to eq('1.0')
273
+ expect(@response[:headers].status).to eq(200)
274
+ expect(@response[:headers].cookies).to eq({})
275
+ expect(@response[:headers].keep_alive).to eq(false)
276
276
  # Response 2 was the general failure
277
277
  end
278
278
  end