/
zdevice_spec.rb
63 lines (50 loc) · 1.34 KB
/
zdevice_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'lib/zdevice'
include ZMQ::Device
describe ZMQ::Device do
let(:ctx) { ZMQ::Context.new }
context Builder do
it "should symbolize configuration keys" do
b = Builder.new(
'context' => { 'iothreads' => 5 },
'main' => {
'type' => :queue,
}
)
b.main.class.should == Device
b.main.type.should == :queue
end
end
context Context do
it "should accept optional iothread count" do
c = Context.new(iothreads: 5)
c.iothreads.should == 5
end
it "should accept optional verbose flag" do
c = Context.new(verbose: true)
c.verbose.should be_true
end
end
context Device do
it "should validate type" do
lambda { Device.new('context') }.should raise_error
end
it "should validate name" do
lambda { Device.new('context', ctx, type: :a) }.should raise_error
d = Device.new('valid', nil, type: :a)
d.name.should == 'valid'
end
end
context ZSocket do
it "should have any name except 'type'" do
lambda { ZSocket.new('type') }.should raise_error('invalid name')
s = ZSocket.new('valid', ctx, type: :queue)
s.name.should == 'valid'
s.close
end
it "should have a type" do
s = ZSocket.new('valid', ctx, type: :queue)
s.type.should >= 0
s.close
end
end
end