Salut 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Salut/Browser.rb CHANGED
@@ -77,6 +77,7 @@ module Salut
77
77
 
78
78
  # @group Finding services
79
79
 
80
+ # @todo find a way to use default arguments
80
81
  # @param [String] service_name
81
82
  # @param [String] domain_name
82
83
  def find_services service_type, in_domain:domain_name
data/lib/Salut/Service.rb CHANGED
@@ -99,7 +99,7 @@ module Salut
99
99
  # exiting will also cause the service to stop being published.
100
100
  def stop_advertising
101
101
  @service.stop
102
- @service = nil
102
+ @service = nil
103
103
  end
104
104
 
105
105
  # @endgroup
@@ -110,6 +110,7 @@ module Salut
110
110
  # A more Ruby-like #resolveWithTimeout by supporting a default argument
111
111
  # @param [Float] timeout number of seconds to wait before timing out
112
112
  def resolve timeout = 60.0
113
+ @service.delegate = self
113
114
  @service.resolveWithTimeout timeout
114
115
  end
115
116
 
@@ -178,7 +179,7 @@ module Salut
178
179
  def netServiceDidStop sender
179
180
  @advertising = false
180
181
  @delegates[__method__].call sender if @delegates[__method__]
181
- Salut.log.info "Stopped advertising service (#{sender.description})"
182
+ Salut.log.info "Stopped advertising/resolving service (#{sender.description})"
182
183
  end
183
184
 
184
185
  # @endgroup
data/spec/Service_spec.rb CHANGED
@@ -49,259 +49,374 @@ describe Salut::Service do
49
49
 
50
50
 
51
51
  describe '#service' do
52
- it 'is an NSNetService instance' do
52
+ before do
53
+ @service = Salut::Service.new({
54
+ port:3000,
55
+ instance_name:'Test',
56
+ service_type:'_http._tcp.'
57
+ })
58
+ end
59
+
60
+ it 'is an NSNetService instance when not nil' do
61
+ @service.start_advertising
62
+ @service.service.class.should.be.equal NSNetService
53
63
  end
54
64
 
55
65
  it 'can be set at initialization' do
66
+ new_service = NSNetService.alloc.initWithDomain '',
67
+ type:'_http._tcp.',
68
+ name:'TEST',
69
+ port:4000
70
+ @service = Salut::Service.new({ service:new_service })
71
+ @service.service.should.be.equal new_service
56
72
  end
57
73
 
58
74
  it 'will be created when advertising starts' do
75
+ @service.service.should.be.equal nil
76
+ @service.start_advertising
77
+ @service.service.should.not.be.equal nil
59
78
  end
60
79
 
61
80
  it 'will be set to nil when advertising stops' do
81
+ @service.service.should.be.equal nil
82
+ @service.start_advertising
83
+ NSRunLoop.currentRunLoop.runUntilDate (Time.now + 5)
84
+ @service.stop_advertising
85
+ @service.service.should.be.equal nil
62
86
  end
63
87
  end
64
88
 
65
89
 
66
90
  describe '#initialize' do
67
91
  it 'will let you initialize the port number' do
92
+ Salut::Service.new({ port:4000 }).port.should.be.equal 4000
68
93
  end
69
94
 
70
95
  it 'will let you initialize the instance name' do
96
+ Salut::Service.new({ instance_name:'TEST' }).instance_name.should.be.equal 'TEST'
71
97
  end
72
98
 
73
99
  it 'will let you initialize the service type' do
100
+ Salut::Service.new({ service_type:'_http._tcp.' }).service_type.should.be.equal '_http._tcp.'
74
101
  end
75
102
 
76
103
  it 'will let you initialize with a service' do
104
+ new_service = NSNetService.alloc.initWithDomain '',
105
+ type:'_http._tcp.',
106
+ name:'TEST',
107
+ port:4000
108
+ @service = Salut::Service.new({ service:new_service })
109
+ @service.service.should.be.equal new_service
77
110
  end
78
111
 
79
112
  it 'will initialize delegates to an empty hash' do
113
+ Salut::Service.new.delegates.should.be.equal Hash.new
80
114
  end
81
115
 
82
116
  it 'will initialize @advertising to false' do
117
+ Salut::Service.new.advertising?.should.be.equal false
83
118
  end
84
119
 
85
120
  it 'will let you initialize with nothing being set' do
121
+ @service = Salut::Service.new
122
+ @service.should.not.be.equal nil
86
123
  end
87
124
  end
88
125
 
89
126
 
90
127
  describe '#delegates' do
91
128
  it 'should be initialized to an empty hash' do
129
+ Salut::Service.new.delegates.should.be.equal Hash.new
92
130
  end
93
131
 
94
132
  it 'should be writable' do
133
+ @service = Salut::Service.new
134
+ @service.delegates[:test] = Proc.new { true }
135
+ @service.delegates[:test].should.not.be.equal nil
95
136
  end
96
137
  end
97
138
 
98
139
 
99
140
  describe '#[]' do
100
- it 'should be equivalent to #delegates' do
141
+ it 'should be equivalent to #delegates[]' do
142
+ @service = Salut::Service.new
143
+ @service.delegates[:test] = 'HEY'
144
+ @service[:test].should.be.equal 'HEY'
101
145
  end
102
146
  end
103
147
 
104
148
 
105
149
  describe '#[]=' do
106
- it 'should be equivalent to #delegates=' do
150
+ it 'should be equivalent to #delegates[]=' do
151
+ @service = Salut::Service.new
152
+ @service[:test] = 'HEY'
153
+ @service.delegates[:test].should.be.equal 'HEY'
107
154
  end
108
155
  end
109
156
 
110
157
 
111
158
  describe '#start_advertising' do
159
+ before do
160
+ @service = Salut::Service.new({
161
+ instance_name:'TEST',
162
+ service_type:'_test._tcp.',
163
+ port:9001
164
+ })
165
+ end
166
+
112
167
  it 'should create a new @service object' do
168
+ @service.service.should.be.equal nil
169
+ @service.start_advertising
170
+ @service.service.should.not.be.equal nil
113
171
  end
114
172
 
115
173
  it 'should set the delegate for @service to self' do
174
+ @service.delegates[:'netServiceWillPublish:'] = Proc.new { |sender|
175
+ @service.service.should.be.equal sender
176
+ }
177
+ @service.start_advertising
116
178
  end
117
179
 
118
180
  # a fragile test since it depends on one of the callbacks
119
181
  # being called
120
182
  it 'should call #publish on @service' do
183
+ @service.delegates[:'netServiceWillPublish:'] = Proc.new { |sender|
184
+ @service.service.should.be.equal sender
185
+ }
186
+ @service.start_advertising
121
187
  end
122
188
 
123
189
  it 'should set domain to an empty string by default' do
190
+ @service.start_advertising
191
+ @service.service.domain.should.be.equal ''
124
192
  end
125
193
 
126
194
  it 'should allow me to specify a domain' do
195
+ @service.start_advertising 'local.'
196
+ @service.service.domain.should.be.equal 'local.'
197
+ end
198
+
199
+ it 'should fail if service type, instance name, or port are not set' do
200
+ @service.service_type = nil
201
+ should.raise(NoMethodError) { @service.start_advertising }
127
202
  end
128
203
  end
129
204
 
130
205
 
131
206
  describe '#stop_advertising' do
207
+ before do
208
+ @service = Salut::Service.new({
209
+ instance_name:'TEST',
210
+ service_type:'_test._tcp.',
211
+ port:9001
212
+ })
213
+ @service.start_advertising
214
+ NSRunLoop.currentRunLoop.runUntilDate Time.now + 3
215
+ end
216
+
132
217
  # a fragile test since it depends on one of the callbacks
133
218
  # being called
134
219
  it 'should call #stop on @service' do
220
+ @service.delegates[:'netServiceDidStop:'] = Proc.new { |sender|
221
+ true.should.be.equal true
222
+ }
223
+ @service.stop_advertising
224
+ NSRunLoop.currentRunLoop.runUntilDate Time.now + 3
135
225
  end
136
226
 
137
227
  it 'should set @service to nil' do
228
+ @service.service.should.not.be.equal nil
229
+ @service.stop_advertising
230
+ NSRunLoop.currentRunLoop.runUntilDate Time.now + 3
231
+ @service.service.should.be.equal nil
138
232
  end
139
233
  end
140
234
 
141
235
 
142
236
  describe '#resolve' do
143
237
  before do
144
- # need a browser to find stuff to resolve
238
+ @service = Salut::Service.new({
239
+ instance_name:'TEST',
240
+ service_type:'_test._tcp.',
241
+ port:9001
242
+ })
243
+ @service.start_advertising
244
+ @browser = Salut::Browser.new
245
+ NSRunLoop.currentRunLoop.runUntilDate Time.now + 2
145
246
  end
146
247
 
147
- # a fragile test since it depends on one of the callbacks
148
- # being called
248
+ # a fragile test since it depends on callbacks of callbacks being called
149
249
  it 'should cause the resolve callback to be called' do
150
- end
151
-
152
- it 'should timeout after 60 seconds' do
250
+ @browser.delegates[:'netServiceBrowser:didFindService:moreComing:'] = Proc.new {
251
+ |sender, service, more|
252
+ service.delegates[:'netServiceWillResolve:'] = Proc.new { |sender|
253
+ true.should.be.equal true
254
+ }
255
+ service.resolve
256
+ }
257
+ @browser.find_services '_test._tcp.', in_domain:''
258
+ NSRunLoop.currentRunLoop.runUntilDate (Time.now + 5)
153
259
  end
154
260
 
155
261
  it 'should allow me to override the timeout' do
262
+ @browser.delegates[:'netServiceBrowser:didFindService:moreComing:'] = Proc.new {
263
+ |sender, service, more|
264
+ service.delegates[:'netServiceWillResolve:'] = Proc.new { |sender|
265
+ true.should.be.equal true
266
+ }
267
+ service.resolve 2.0
268
+ }
269
+ @browser.find_services '_test._tcp.', in_domain:''
270
+ NSRunLoop.currentRunLoop.runUntilDate (Time.now + 5)
156
271
  end
157
272
  end
158
273
 
159
274
 
160
- describe 'callback skeletons' do
275
+ # describe 'callback skeletons' do
161
276
 
162
- before do
163
- # set the logger to log INFO and log to a stringIO object
164
- end
277
+ # before do
278
+ # # set the logger to log INFO and log to a stringIO object
279
+ # end
165
280
 
166
281
 
167
- describe '#netServiceWillPublish' do
168
- it 'should call its proc if exists' do
169
- end
282
+ # describe '#netServiceWillPublish' do
283
+ # it 'should call its proc if exists' do
284
+ # end
170
285
 
171
- it 'should not explode if the proc does not exist' do
172
- end
286
+ # it 'should not explode if the proc does not exist' do
287
+ # end
173
288
 
174
- it 'should log a message at the INFO level' do
175
- end
289
+ # it 'should log a message at the INFO level' do
290
+ # end
176
291
 
177
- it 'should pass self to the proc' do
178
- end
179
- end
292
+ # it 'should pass self to the proc' do
293
+ # end
294
+ # end
180
295
 
181
296
 
182
- describe '#netService:didNotPublish:' do
183
- it 'should call its proc if exists' do
184
- end
297
+ # describe '#netService:didNotPublish:' do
298
+ # it 'should call its proc if exists' do
299
+ # end
185
300
 
186
- it 'should not explode if the proc does not exist' do
187
- end
301
+ # it 'should not explode if the proc does not exist' do
302
+ # end
188
303
 
189
- it 'should log a message at the INFO level' do
190
- end
304
+ # it 'should log a message at the INFO level' do
305
+ # end
191
306
 
192
- it 'should set @advertising to false' do
193
- end
307
+ # it 'should set @advertising to false' do
308
+ # end
194
309
 
195
- it 'should pass self to the proc' do
196
- end
310
+ # it 'should pass self to the proc' do
311
+ # end
197
312
 
198
- it 'should pass the error dict to the proc' do
199
- end
200
- end
313
+ # it 'should pass the error dict to the proc' do
314
+ # end
315
+ # end
201
316
 
202
317
 
203
- describe '#netServiceDidPublish' do
204
- it 'should call its proc if exists' do
205
- end
318
+ # describe '#netServiceDidPublish' do
319
+ # it 'should call its proc if exists' do
320
+ # end
206
321
 
207
- it 'should not explode if the proc does not exist' do
208
- end
322
+ # it 'should not explode if the proc does not exist' do
323
+ # end
209
324
 
210
- it 'should log a message at the INFO level' do
211
- end
325
+ # it 'should log a message at the INFO level' do
326
+ # end
212
327
 
213
- it 'should set @advertising to true' do
214
- end
328
+ # it 'should set @advertising to true' do
329
+ # end
215
330
 
216
- it 'should pass self to the proc' do
217
- end
218
- end
331
+ # it 'should pass self to the proc' do
332
+ # end
333
+ # end
219
334
 
220
335
 
221
- describe '#netServiceWillResolve' do
222
- it 'should call its proc if exists' do
223
- end
336
+ # describe '#netServiceWillResolve' do
337
+ # it 'should call its proc if exists' do
338
+ # end
224
339
 
225
- it 'should not explode if the proc does not exist' do
226
- end
340
+ # it 'should not explode if the proc does not exist' do
341
+ # end
227
342
 
228
- it 'should log a message at the INFO level' do
229
- end
343
+ # it 'should log a message at the INFO level' do
344
+ # end
230
345
 
231
- it 'should pass self to the proc' do
232
- end
233
- end
346
+ # it 'should pass self to the proc' do
347
+ # end
348
+ # end
234
349
 
235
350
 
236
- describe '#netService:didNotResolve:' do
237
- it 'should call its proc if exists' do
238
- end
351
+ # describe '#netService:didNotResolve:' do
352
+ # it 'should call its proc if exists' do
353
+ # end
239
354
 
240
- it 'should not explode if the proc does not exist' do
241
- end
355
+ # it 'should not explode if the proc does not exist' do
356
+ # end
242
357
 
243
- it 'should log a message at the INFO level' do
244
- end
358
+ # it 'should log a message at the INFO level' do
359
+ # end
245
360
 
246
- it 'should pass self to the proc' do
247
- end
361
+ # it 'should pass self to the proc' do
362
+ # end
248
363
 
249
- it 'should pass the error dict to the proc' do
250
- end
251
- end
364
+ # it 'should pass the error dict to the proc' do
365
+ # end
366
+ # end
252
367
 
253
368
 
254
- describe '#netServiceDidResolveAddress' do
255
- it 'should call its proc if exists' do
256
- end
369
+ # describe '#netServiceDidResolveAddress' do
370
+ # it 'should call its proc if exists' do
371
+ # end
257
372
 
258
- it 'should not explode if the proc does not exist' do
259
- end
373
+ # it 'should not explode if the proc does not exist' do
374
+ # end
260
375
 
261
- it 'should log a message at the INFO level' do
262
- end
376
+ # it 'should log a message at the INFO level' do
377
+ # end
263
378
 
264
- it 'should pass self to the proc' do
265
- end
266
- end
379
+ # it 'should pass self to the proc' do
380
+ # end
381
+ # end
267
382
 
268
383
 
269
- describe '#netService:didUpdateTXTRecordData:' do
270
- it 'should call its proc if exists' do
271
- end
384
+ # describe '#netService:didUpdateTXTRecordData:' do
385
+ # it 'should call its proc if exists' do
386
+ # end
272
387
 
273
- it 'should not explode if the proc does not exist' do
274
- end
388
+ # it 'should not explode if the proc does not exist' do
389
+ # end
275
390
 
276
- it 'should log a message at the INFO level' do
277
- end
391
+ # it 'should log a message at the INFO level' do
392
+ # end
278
393
 
279
- it 'should pass self to the proc' do
280
- end
394
+ # it 'should pass self to the proc' do
395
+ # end
281
396
 
282
- it 'should pass the TXT record data to the proc' do
283
- end
284
- end
397
+ # it 'should pass the TXT record data to the proc' do
398
+ # end
399
+ # end
285
400
 
286
401
 
287
- describe '#netServiceDidStop' do
288
- it 'should call its proc if exists' do
289
- end
402
+ # describe '#netServiceDidStop' do
403
+ # it 'should call its proc if exists' do
404
+ # end
290
405
 
291
- it 'should not explode if the proc does not exist' do
292
- end
406
+ # it 'should not explode if the proc does not exist' do
407
+ # end
293
408
 
294
- it 'should log a message at the INFO level' do
295
- end
409
+ # it 'should log a message at the INFO level' do
410
+ # end
296
411
 
297
- it 'should set @advertising to false' do
298
- end
412
+ # it 'should set @advertising to false' do
413
+ # end
299
414
 
300
- it 'should pass self to the proc' do
301
- end
302
- end
415
+ # it 'should pass self to the proc' do
416
+ # end
417
+ # end
303
418
 
304
- end
419
+ # end
305
420
 
306
421
 
307
422
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Rada
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 -05:00
17
+ date: 2011-01-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency