bindata 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bindata might be problematic. Click here for more details.

@@ -14,7 +14,7 @@ describe BinData::Registry do
14
14
 
15
15
  let(:r) { BinData::Registry.new }
16
16
 
17
- it "should lookup registered names" do
17
+ it "lookups registered names" do
18
18
  r.register('ASubClass', A)
19
19
  r.register('AnotherSubClass', B)
20
20
 
@@ -24,37 +24,37 @@ describe BinData::Registry do
24
24
  r.lookup('another_sub_class').should == B
25
25
  end
26
26
 
27
- it "should not lookup unregistered names" do
28
- lambda {
27
+ it "does not lookup unregistered names" do
28
+ expect {
29
29
  r.lookup('a_non_existent_sub_class')
30
- }.should raise_error(BinData::UnRegisteredTypeError)
30
+ }.to raise_error(BinData::UnRegisteredTypeError)
31
31
  end
32
32
 
33
- it "should be able to unregister names" do
33
+ it "unregisters names" do
34
34
  r.register('ASubClass', A)
35
35
  r.unregister('ASubClass')
36
36
 
37
- lambda {
37
+ expect {
38
38
  r.lookup('ASubClass')
39
- }.should raise_error(BinData::UnRegisteredTypeError)
39
+ }.to raise_error(BinData::UnRegisteredTypeError)
40
40
  end
41
41
 
42
- it "should allow overriding of registered classes" do
42
+ it "allows overriding of registered classes" do
43
43
  r.register('A', A)
44
44
  r.register('A', B)
45
45
 
46
46
  r.lookup('a').should == B
47
47
  end
48
48
 
49
- it "should convert CamelCase to underscores" do
49
+ it "converts CamelCase to underscores" do
50
50
  r.underscore_name('CamelCase').should == 'camel_case'
51
51
  end
52
52
 
53
- it "should convert adjacent caps camelCase to underscores" do
53
+ it "converts adjacent caps camelCase to underscores" do
54
54
  r.underscore_name('XYZCamelCase').should == 'xyz_camel_case'
55
55
  end
56
56
 
57
- it "should ignore the outer nestings of classes" do
57
+ it "ignores the outer nestings of classes" do
58
58
  r.underscore_name('A::B::C').should == 'c'
59
59
  end
60
60
  end
@@ -62,44 +62,44 @@ end
62
62
  describe BinData::Registry, "with numerics" do
63
63
  let(:r) { BinData::RegisteredClasses }
64
64
 
65
- it "should lookup integers with endian" do
65
+ it "lookup integers with endian" do
66
66
  r.lookup("int24", :big).to_s.should == "BinData::Int24be"
67
67
  r.lookup("int24", :little).to_s.should == "BinData::Int24le"
68
68
  r.lookup("uint24", :big).to_s.should == "BinData::Uint24be"
69
69
  r.lookup("uint24", :little).to_s.should == "BinData::Uint24le"
70
70
  end
71
71
 
72
- it "should not lookup integers without endian" do
73
- lambda {
72
+ it "does not lookup integers without endian" do
73
+ expect {
74
74
  r.lookup("int24")
75
- }.should raise_error(BinData::UnRegisteredTypeError)
75
+ }.to raise_error(BinData::UnRegisteredTypeError)
76
76
  end
77
77
 
78
- it "should not lookup non byte based integers" do
79
- lambda {
78
+ it "does not lookup non byte based integers" do
79
+ expect {
80
80
  r.lookup("int3")
81
- }.should raise_error(BinData::UnRegisteredTypeError)
82
- lambda {
81
+ }.to raise_error(BinData::UnRegisteredTypeError)
82
+ expect {
83
83
  r.lookup("int3", :big)
84
- }.should raise_error(BinData::UnRegisteredTypeError)
85
- lambda {
84
+ }.to raise_error(BinData::UnRegisteredTypeError)
85
+ expect {
86
86
  r.lookup("int3", :little)
87
- }.should raise_error(BinData::UnRegisteredTypeError)
87
+ }.to raise_error(BinData::UnRegisteredTypeError)
88
88
  end
89
89
 
90
- it "should lookup floats with endian" do
90
+ it "lookup floats with endian" do
91
91
  r.lookup("float", :big).to_s.should == "BinData::FloatBe"
92
92
  r.lookup("float", :little).to_s.should == "BinData::FloatLe"
93
93
  r.lookup("double", :big).to_s.should == "BinData::DoubleBe"
94
94
  r.lookup("double", :little).to_s.should == "BinData::DoubleLe"
95
95
  end
96
96
 
97
- it "should lookup bits" do
97
+ it "lookup bits" do
98
98
  r.lookup("bit5").to_s.should == "BinData::Bit5"
99
99
  r.lookup("bit6le").to_s.should == "BinData::Bit6le"
100
100
  end
101
101
 
102
- it "should lookup bits by ignoring endian" do
102
+ it "lookup bits by ignoring endian" do
103
103
  r.lookup("bit2", :big).to_s.should == "BinData::Bit2"
104
104
  r.lookup("bit3le", :big).to_s.should == "BinData::Bit3le"
105
105
  r.lookup("bit2", :little).to_s.should == "BinData::Bit2"
data/spec/rest_spec.rb CHANGED
@@ -6,21 +6,21 @@ require 'bindata/rest'
6
6
  describe BinData::Rest do
7
7
  it { should == "" }
8
8
 
9
- it "should read till end of stream" do
9
+ it "reads till end of stream" do
10
10
  data = "abcdefghij"
11
11
  subject.read(data).should == data
12
12
  end
13
13
 
14
- it "should allow setting value for completeness" do
14
+ it "allows setting value for completeness" do
15
15
  subject.assign("123")
16
16
  subject.should == "123"
17
17
  subject.to_binary_s.should == "123"
18
18
  end
19
19
 
20
- it "should accept BinData::BasePrimitive parameters" do
20
+ it "accepts BinData::BasePrimitive parameters" do
21
21
  rest = BinData::Rest.new(:check_value => "abc")
22
- lambda {
22
+ expect {
23
23
  rest.read("xyz")
24
- }.should raise_error(BinData::ValidityError)
24
+ }.to raise_error(BinData::ValidityError)
25
25
  end
26
26
  end
data/spec/skip_spec.rb CHANGED
@@ -10,17 +10,17 @@ describe BinData::Skip do
10
10
  it { should == "" }
11
11
  its(:to_binary_s) { should == "\000" * 5 }
12
12
 
13
- it "should skip bytes" do
13
+ it "skips bytes" do
14
14
  subject.read(io)
15
15
  io.pos.should == 5
16
16
  end
17
17
 
18
- it "should have expected binary representation after setting value" do
18
+ it "has expected binary representation after setting value" do
19
19
  subject.assign("123")
20
20
  subject.to_binary_s.should == "\000" * 5
21
21
  end
22
22
 
23
- it "should have expected binary representation after reading" do
23
+ it "has expected binary representation after reading" do
24
24
  subject.read(io)
25
25
  subject.to_binary_s.should == "\000" * 5
26
26
  end
data/spec/spec_common.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
2
2
 
3
- require 'spec'
4
- require 'spec/autorun'
3
+ require 'rspec'
4
+ require 'rspec/autorun'
5
5
  require 'stringio'
6
6
 
7
7
  class Object
data/spec/string_spec.rb CHANGED
@@ -7,30 +7,30 @@ require 'bindata/string'
7
7
  describe BinData::String, "with mutually exclusive parameters" do
8
8
  it ":value and :initial_value" do
9
9
  params = {:value => "", :initial_value => ""}
10
- lambda { BinData::String.new(params) }.should raise_error(ArgumentError)
10
+ expect { BinData::String.new(params) }.to raise_error(ArgumentError)
11
11
  end
12
12
 
13
13
  it ":length and :read_length" do
14
14
  params = {:length => 5, :read_length => 5}
15
- lambda { BinData::String.new(params) }.should raise_error(ArgumentError)
15
+ expect { BinData::String.new(params) }.to raise_error(ArgumentError)
16
16
  end
17
17
 
18
18
  it ":value and :length" do
19
19
  params = {:value => "", :length => 5}
20
- lambda { BinData::String.new(params) }.should raise_error(ArgumentError)
20
+ expect { BinData::String.new(params) }.to raise_error(ArgumentError)
21
21
  end
22
22
  end
23
23
 
24
24
  describe BinData::String, "when assigning" do
25
- let(:small) { BinData::String.new(:length => 3, :pad_char => "A") }
26
- let(:large) { BinData::String.new(:length => 5, :pad_char => "B") }
25
+ let(:small) { BinData::String.new(:length => 3, :pad_byte => "A") }
26
+ let(:large) { BinData::String.new(:length => 5, :pad_byte => "B") }
27
27
 
28
- it "should copy data from small to large" do
28
+ it "copies data from small to large" do
29
29
  large.assign(small)
30
30
  large.should == "AAABB"
31
31
  end
32
32
 
33
- it "should copy data from large to small" do
33
+ it "copies data from large to small" do
34
34
  small.assign(large)
35
35
  small.should == "BBB"
36
36
  end
@@ -39,11 +39,11 @@ end
39
39
  describe BinData::String do
40
40
  subject { BinData::String.new("testing") }
41
41
 
42
- it "should compare with regexp" do
42
+ it "compares with regexp" do
43
43
  (/es/ =~ subject).should == 1
44
44
  end
45
45
 
46
- it "should compare with regexp" do
46
+ it "compares with regexp" do
47
47
  (subject =~ /es/).should == 1
48
48
  end
49
49
  end
@@ -54,12 +54,12 @@ describe BinData::String, "with :read_length" do
54
54
  its(:num_bytes) { should == 0 }
55
55
  its(:value) { should == "" }
56
56
 
57
- it "should read :read_length bytes" do
57
+ it "reads :read_length bytes" do
58
58
  subject.read("abcdefghij")
59
59
  subject.should == "abcde"
60
60
  end
61
61
 
62
- it "should remember :read_length after value is cleared" do
62
+ it "remembers :read_length after value is cleared" do
63
63
  subject.assign("abc")
64
64
  subject.num_bytes.should == 3
65
65
  subject.clear
@@ -75,27 +75,27 @@ describe BinData::String, "with :length" do
75
75
  its(:num_bytes) { should == 5 }
76
76
  its(:value) { should == "\0\0\0\0\0" }
77
77
 
78
- it "should retain :length after value is set" do
78
+ it "retains :length after value is set" do
79
79
  subject.assign("abcdefghij")
80
80
  subject.num_bytes.should == 5
81
81
  end
82
82
 
83
- it "should read :length bytes" do
83
+ it "reads :length bytes" do
84
84
  subject.read("abcdefghij")
85
85
  subject.should == "abcde"
86
86
  end
87
87
 
88
- it "should pad values less than :length" do
88
+ it "pads values less than :length" do
89
89
  subject.assign("abc")
90
90
  subject.should == "abc\0\0"
91
91
  end
92
92
 
93
- it "should accept values exactly :length" do
93
+ it "accepts values exactly :length" do
94
94
  subject.assign("abcde")
95
95
  subject.should == "abcde"
96
96
  end
97
97
 
98
- it "should truncate values greater than :length" do
98
+ it "truncates values greater than :length" do
99
99
  subject.assign("abcdefghij")
100
100
  subject.should == "abcde"
101
101
  end
@@ -107,13 +107,13 @@ describe BinData::String, "with :read_length and :initial_value" do
107
107
  its(:num_bytes) { should == 10 }
108
108
  its(:value) { should == "abcdefghij" }
109
109
 
110
- it "should use :read_length for reading" do
110
+ it "uses :read_length for reading" do
111
111
  io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
112
112
  subject.read(io)
113
113
  io.pos.should == 5
114
114
  end
115
115
 
116
- it "should forget :initial_value after reading" do
116
+ it "forgets :initial_value after reading" do
117
117
  subject.read("ABCDEFGHIJKLMNOPQRST")
118
118
  subject.num_bytes.should == 5
119
119
  subject.should == "ABCDE"
@@ -126,7 +126,7 @@ describe BinData::String, "with :read_length and :value" do
126
126
  its(:num_bytes) { should == 10 }
127
127
  its(:value) { should == "abcdefghij" }
128
128
 
129
- it "should use :read_length for reading" do
129
+ it "uses :read_length for reading" do
130
130
  io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
131
131
  subject.read(io)
132
132
  io.pos.should == 5
@@ -137,12 +137,12 @@ describe BinData::String, "with :read_length and :value" do
137
137
  subject.read("ABCDEFGHIJKLMNOPQRST")
138
138
  end
139
139
 
140
- it "should not be affected by :read_length after reading" do
140
+ it "is not affected by :read_length after reading" do
141
141
  subject.num_bytes.should == 10
142
142
  subject.should == "abcdefghij"
143
143
  end
144
144
 
145
- it "should return read value while reading" do
145
+ it "returns read value while reading" do
146
146
  subject.stub(:reading?).and_return(true)
147
147
  subject.should == "ABCDE"
148
148
  end
@@ -155,7 +155,7 @@ describe BinData::String, "with :length and :initial_value" do
155
155
  its(:num_bytes) { should == 5 }
156
156
  its(:value) { should == "abcde" }
157
157
 
158
- it "should forget :initial_value after reading" do
158
+ it "forgets :initial_value after reading" do
159
159
  io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
160
160
  subject.read(io)
161
161
  io.pos.should == 5
@@ -164,21 +164,21 @@ describe BinData::String, "with :length and :initial_value" do
164
164
  end
165
165
  end
166
166
 
167
- describe BinData::String, "with :pad_char" do
168
- it "should accept a numeric value for :pad_char" do
169
- str = BinData::String.new(:length => 5, :pad_char => 6)
167
+ describe BinData::String, "with :pad_byte" do
168
+ it "accepts a numeric value for :pad_byte" do
169
+ str = BinData::String.new(:length => 5, :pad_byte => 6)
170
170
  str.assign("abc")
171
171
  str.should == "abc\x06\x06"
172
172
  end
173
173
 
174
- it "should accept a character for :pad_char" do
175
- str = BinData::String.new(:length => 5, :pad_char => "R")
174
+ it "accepts a character for :pad_byte" do
175
+ str = BinData::String.new(:length => 5, :pad_byte => "R")
176
176
  str.assign("abc")
177
177
  str.should == "abcRR"
178
178
  end
179
179
 
180
- it "should not accept a string for :pad_char" do
181
- params = {:length => 5, :pad_char => "RR"}
180
+ it "does not accept a string for :pad_byte" do
181
+ params = {:length => 5, :pad_byte => "RR"}
182
182
  lambda { BinData::String.new(params) }.should raise_error(ArgumentError)
183
183
  end
184
184
  end
@@ -194,24 +194,24 @@ describe BinData::String, "with :trim_padding" do
194
194
  end
195
195
 
196
196
  context "trim padding set" do
197
- subject { BinData::String.new(:pad_char => 'R', :trim_padding => true) }
197
+ subject { BinData::String.new(:pad_byte => 'R', :trim_padding => true) }
198
198
 
199
- it "should trim the value" do
199
+ it "trims the value" do
200
200
  subject.assign("abcRR")
201
201
  subject.should == "abc"
202
202
  end
203
203
 
204
- it "should not affect num_bytes" do
204
+ it "does not affect num_bytes" do
205
205
  subject.assign("abcRR")
206
206
  subject.num_bytes.should == 5
207
207
  end
208
208
 
209
- it "should trim if last char is :pad_char" do
209
+ it "trims if last char is :pad_byte" do
210
210
  subject.assign("abcRR")
211
211
  subject.should == "abc"
212
212
  end
213
213
 
214
- it "should not trim if value contains :pad_char not at the end" do
214
+ it "does not trim if value contains :pad_byte not at the end" do
215
215
  subject.assign("abcRRde")
216
216
  subject.should == "abcRRde"
217
217
  end
@@ -230,25 +230,25 @@ describe BinData::String, "with Ruby 1.9 encodings" do
230
230
  let(:binary_str) { "\xC3\x85\xC3\x84\xC3\x96" }
231
231
  let(:utf8_str) { binary_str.dup.force_encoding('UTF-8') }
232
232
 
233
- it "should store assigned values as binary" do
233
+ it "stores assigned values as binary" do
234
234
  subject.assign(utf8_str)
235
235
  subject.to_binary_s.should == binary_str
236
236
  end
237
237
 
238
- it "should store read values as binary" do
238
+ it "stores read values as binary" do
239
239
  subject = UTF8String.new(:read_length => binary_str.length)
240
240
  subject.read(binary_str)
241
241
 
242
242
  subject.to_binary_s.should == binary_str
243
243
  end
244
244
 
245
- it "should return values in correct encoding" do
245
+ it "returns values in correct encoding" do
246
246
  subject.assign(utf8_str)
247
247
 
248
248
  subject.snapshot.should == utf8_str
249
249
  end
250
250
 
251
- it "should have correct num_bytes" do
251
+ it "has correct num_bytes" do
252
252
  subject.assign(utf8_str)
253
253
 
254
254
  subject.num_bytes.should == binary_str.length
data/spec/stringz_spec.rb CHANGED
@@ -18,47 +18,47 @@ describe BinData::Stringz, "with value set" do
18
18
  end
19
19
 
20
20
  describe BinData::Stringz, "when reading" do
21
- it "should stop at the first zero byte" do
21
+ it "stops at the first zero byte" do
22
22
  io = StringIO.new("abcd\0xyz\0")
23
23
  subject.read(io)
24
24
  io.pos.should == 5
25
25
  subject.should == "abcd"
26
26
  end
27
27
 
28
- it "should handle a zero length string" do
28
+ it "handles a zero length string" do
29
29
  io = StringIO.new("\0abcd")
30
30
  subject.read(io)
31
31
  io.pos.should == 1
32
32
  subject.should == ""
33
33
  end
34
34
 
35
- it "should fail if no zero byte is found" do
36
- lambda {subject.read("abcd") }.should raise_error(EOFError)
35
+ it "fails if no zero byte is found" do
36
+ expect {subject.read("abcd") }.to raise_error(EOFError)
37
37
  end
38
38
  end
39
39
 
40
40
  describe BinData::Stringz, "when setting the value" do
41
- it "should include the zero byte in num_bytes total" do
41
+ it "includes the zero byte in num_bytes total" do
42
42
  subject.assign("abcd")
43
43
  subject.num_bytes.should == 5
44
44
  end
45
45
 
46
- it "should accept empty strings" do
46
+ it "accepts empty strings" do
47
47
  subject.assign("")
48
48
  subject.should == ""
49
49
  end
50
50
 
51
- it "should accept strings that aren't zero terminated" do
51
+ it "accepts strings that aren't zero terminated" do
52
52
  subject.assign("abcd")
53
53
  subject.should == "abcd"
54
54
  end
55
55
 
56
- it "should accept strings that are zero terminated" do
56
+ it "accepts strings that are zero terminated" do
57
57
  subject.assign("abcd\0")
58
58
  subject.should == "abcd"
59
59
  end
60
60
 
61
- it "should accept up to the first zero byte" do
61
+ it "accepts up to the first zero byte" do
62
62
  subject.assign("abcd\0xyz\0")
63
63
  subject.should == "abcd"
64
64
  end
@@ -67,51 +67,51 @@ end
67
67
  describe BinData::Stringz, "with max_length" do
68
68
  subject { BinData::Stringz.new(:max_length => 5) }
69
69
 
70
- it "should read less than max_length" do
70
+ it "reads less than max_length" do
71
71
  io = StringIO.new("abc\0xyz")
72
72
  subject.read(io)
73
73
  subject.should == "abc"
74
74
  end
75
75
 
76
- it "should read exactly max_length" do
76
+ it "reads exactly max_length" do
77
77
  io = StringIO.new("abcd\0xyz")
78
78
  subject.read(io)
79
79
  subject.should == "abcd"
80
80
  end
81
81
 
82
- it "should read no more than max_length" do
82
+ it "reads no more than max_length" do
83
83
  io = StringIO.new("abcdefg\0xyz")
84
84
  subject.read(io)
85
85
  io.pos.should == 5
86
86
  subject.should == "abcd"
87
87
  end
88
88
 
89
- it "should accept values less than max_length" do
89
+ it "accepts values less than max_length" do
90
90
  subject.assign("abc")
91
91
  subject.should == "abc"
92
92
  end
93
93
 
94
- it "should accept values exactly max_length" do
94
+ it "accepts values exactly max_length" do
95
95
  subject.assign("abcd")
96
96
  subject.should == "abcd"
97
97
  end
98
98
 
99
- it "should trim values greater than max_length" do
99
+ it "trims values greater than max_length" do
100
100
  subject.assign("abcde")
101
101
  subject.should == "abcd"
102
102
  end
103
103
 
104
- it "should write values greater than max_length" do
104
+ it "writes values greater than max_length" do
105
105
  subject.assign("abcde")
106
106
  subject.to_binary_s.should == "abcd\0"
107
107
  end
108
108
 
109
- it "should write values less than max_length" do
109
+ it "writes values less than max_length" do
110
110
  subject.assign("abc")
111
111
  subject.to_binary_s.should == "abc\0"
112
112
  end
113
113
 
114
- it "should write values exactly max_length" do
114
+ it "writes values exactly max_length" do
115
115
  subject.assign("abcd")
116
116
  subject.to_binary_s.should == "abcd\0"
117
117
  end