bindata 1.5.1 → 1.6.0

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.

Files changed (61) hide show
  1. data/ChangeLog.rdoc +7 -0
  2. data/NEWS.rdoc +11 -0
  3. data/Rakefile +6 -1
  4. data/bindata.gemspec +2 -1
  5. data/doc/manual.md +17 -9
  6. data/examples/gzip.rb +2 -2
  7. data/examples/list.rb +2 -2
  8. data/lib/bindata/alignment.rb +4 -9
  9. data/lib/bindata/array.rb +57 -51
  10. data/lib/bindata/base.rb +13 -110
  11. data/lib/bindata/base_primitive.rb +130 -75
  12. data/lib/bindata/bits.rb +5 -7
  13. data/lib/bindata/choice.rb +24 -32
  14. data/lib/bindata/dsl.rb +1 -6
  15. data/lib/bindata/framework.rb +81 -0
  16. data/lib/bindata/int.rb +5 -7
  17. data/lib/bindata/name.rb +28 -0
  18. data/lib/bindata/offset.rb +42 -53
  19. data/lib/bindata/params.rb +33 -38
  20. data/lib/bindata/struct.rb +2 -6
  21. data/lib/bindata/trace.rb +16 -16
  22. data/lib/bindata/version.rb +1 -1
  23. data/lib/bindata/virtual.rb +3 -3
  24. data/{spec/alignment_spec.rb → test/alignment_test.rb} +17 -16
  25. data/test/array_test.rb +371 -0
  26. data/test/base_primitive_test.rb +312 -0
  27. data/test/base_test.rb +183 -0
  28. data/{spec/bits_spec.rb → test/bits_test.rb} +59 -59
  29. data/test/choice_test.rb +260 -0
  30. data/{spec/spec_common.rb → test/common.rb} +33 -18
  31. data/test/count_bytes_remaining_test.rb +41 -0
  32. data/{spec/deprecated_spec.rb → test/deprecated_test.rb} +5 -7
  33. data/test/float_test.rb +72 -0
  34. data/{spec/int_spec.rb → test/int_test.rb} +34 -43
  35. data/{spec/io_spec.rb → test/io_test.rb} +70 -71
  36. data/{spec/lazy_spec.rb → test/lazy_test.rb} +38 -39
  37. data/test/offset_test.rb +93 -0
  38. data/test/params_test.rb +144 -0
  39. data/{spec/primitive_spec.rb → test/primitive_test.rb} +42 -54
  40. data/{spec/record_spec.rb → test/record_test.rb} +133 -154
  41. data/test/registry_test.rb +104 -0
  42. data/test/rest_test.rb +29 -0
  43. data/test/skip_test.rb +28 -0
  44. data/{spec/string_spec.rb → test/string_test.rb} +96 -97
  45. data/test/stringz_test.rb +127 -0
  46. data/{spec/struct_spec.rb → test/struct_test.rb} +119 -120
  47. data/{spec/system_spec.rb → test/system_test.rb} +66 -106
  48. metadata +39 -38
  49. data/lib/a.rb +0 -24
  50. data/spec/array_spec.rb +0 -331
  51. data/spec/base_primitive_spec.rb +0 -238
  52. data/spec/base_spec.rb +0 -376
  53. data/spec/choice_spec.rb +0 -263
  54. data/spec/count_bytes_remaining_spec.rb +0 -38
  55. data/spec/example.rb +0 -21
  56. data/spec/float_spec.rb +0 -37
  57. data/spec/registry_spec.rb +0 -108
  58. data/spec/rest_spec.rb +0 -26
  59. data/spec/skip_spec.rb +0 -27
  60. data/spec/stringz_spec.rb +0 -118
  61. data/tasks/rspec.rake +0 -17
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
4
- require 'bindata'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "common"))
5
4
 
6
5
  describe BinData::Record do
7
6
  it "is not registered" do
8
- expect {
7
+ lambda {
9
8
  BinData::RegisteredClasses.lookup("Record")
10
- }.to raise_error(BinData::UnRegisteredTypeError)
9
+ }.must_raise BinData::UnRegisteredTypeError
11
10
  end
12
11
  end
13
12
 
@@ -17,9 +16,7 @@ describe BinData::Record, "when defining with errors" do
17
16
  class BadTypeRecord < BinData::Record
18
17
  non_registered_type :a
19
18
  end
20
- }.should raise_error_on_line(TypeError, 2) { |err|
21
- err.message.should == "unknown type 'non_registered_type' in #{BadTypeRecord}"
22
- }
19
+ }.must_raise_on_line TypeError, 2, "unknown type 'non_registered_type' in BadTypeRecord"
23
20
  end
24
21
 
25
22
  it "gives correct error message for non registered nested types" do
@@ -27,9 +24,7 @@ describe BinData::Record, "when defining with errors" do
27
24
  class BadNestedTypeRecord < BinData::Record
28
25
  array :a, :type => :non_registered_type
29
26
  end
30
- }.should raise_error_on_line(TypeError, 2) { |err|
31
- err.message.should == "unknown type 'non_registered_type' in #{BadNestedTypeRecord}"
32
- }
27
+ }.must_raise_on_line TypeError, 2, "unknown type 'non_registered_type' in BadNestedTypeRecord"
33
28
  end
34
29
 
35
30
  it "gives correct error message for non registered nested types in blocks" do
@@ -39,9 +34,7 @@ describe BinData::Record, "when defining with errors" do
39
34
  non_registered_type
40
35
  end
41
36
  end
42
- }.should raise_error_on_line(TypeError, 3) { |err|
43
- err.message.should == "unknown type 'non_registered_type' in #{BinData::Array}"
44
- }
37
+ }.must_raise_on_line TypeError, 3, "unknown type 'non_registered_type' in BinData::Array"
45
38
  end
46
39
 
47
40
  it "fails on nested choice when missing names" do
@@ -52,9 +45,7 @@ describe BinData::Record, "when defining with errors" do
52
45
  int8
53
46
  end
54
47
  end
55
- }.should raise_error_on_line(SyntaxError, 4) { |err|
56
- err.message.should == "fields must either all have names, or none must have names in BinData::Choice"
57
- }
48
+ }.must_raise_on_line SyntaxError, 4, "fields must either all have names, or none must have names in BinData::Choice"
58
49
  end
59
50
 
60
51
  it "fails on malformed names" do
@@ -63,9 +54,7 @@ describe BinData::Record, "when defining with errors" do
63
54
  int8 :a
64
55
  int8 "45"
65
56
  end
66
- }.should raise_error_on_line(NameError, 3) { |err|
67
- err.message.should == "field '45' is an illegal fieldname in #{MalformedNameRecord}"
68
- }
57
+ }.must_raise_on_line NameError, 3, "field '45' is an illegal fieldname in MalformedNameRecord"
69
58
  end
70
59
 
71
60
  it "fails on duplicate names" do
@@ -75,9 +64,7 @@ describe BinData::Record, "when defining with errors" do
75
64
  int8 :b
76
65
  int8 :a
77
66
  end
78
- }.should raise_error_on_line(SyntaxError, 4) { |err|
79
- err.message.should == "duplicate field 'a' in #{DuplicateNameRecord}"
80
- }
67
+ }.must_raise_on_line SyntaxError, 4, "duplicate field 'a' in DuplicateNameRecord"
81
68
  end
82
69
 
83
70
  it "fails on reserved names" do
@@ -86,9 +73,7 @@ describe BinData::Record, "when defining with errors" do
86
73
  int8 :a
87
74
  int8 :invert # from Hash.instance_methods
88
75
  end
89
- }.should raise_error_on_line(NameError, 3) { |err|
90
- err.message.should == "field 'invert' is a reserved name in #{ReservedNameRecord}"
91
- }
76
+ }.must_raise_on_line NameError, 3, "field 'invert' is a reserved name in ReservedNameRecord"
92
77
  end
93
78
 
94
79
  it "fails when field name shadows an existing method" do
@@ -96,9 +81,7 @@ describe BinData::Record, "when defining with errors" do
96
81
  class ExistingNameRecord < BinData::Record
97
82
  int8 :object_id
98
83
  end
99
- }.should raise_error_on_line(NameError, 2) { |err|
100
- err.message.should == "field 'object_id' shadows an existing method in #{ExistingNameRecord}"
101
- }
84
+ }.must_raise_on_line NameError, 2, "field 'object_id' shadows an existing method in ExistingNameRecord"
102
85
  end
103
86
 
104
87
  it "fails on unknown endian" do
@@ -106,9 +89,7 @@ describe BinData::Record, "when defining with errors" do
106
89
  class BadEndianRecord < BinData::Record
107
90
  endian 'a bad value'
108
91
  end
109
- }.should raise_error_on_line(ArgumentError, 2) { |err|
110
- err.message.should == "unknown value for endian 'a bad value' in #{BadEndianRecord}"
111
- }
92
+ }.must_raise_on_line ArgumentError, 2, "unknown value for endian 'a bad value' in BadEndianRecord"
112
93
  end
113
94
  end
114
95
 
@@ -121,22 +102,22 @@ describe BinData::Record, "with anonymous fields" do
121
102
  int8 :value => :a
122
103
  end
123
104
 
124
- subject { AnonymousRecord.new }
105
+ let(:obj) { AnonymousRecord.new }
125
106
 
126
107
  it "only shows non anonymous fields" do
127
- subject.field_names.should == ["a"]
108
+ obj.field_names.must_equal ["a"]
128
109
  end
129
110
 
130
111
  it "does not include anonymous fields in snapshot" do
131
- subject.a = 5
132
- subject.snapshot.should == {"a" => 5}
112
+ obj.a = 5
113
+ obj.snapshot.must_equal({"a" => 5})
133
114
  end
134
115
 
135
116
  it "writes anonymous fields" do
136
117
  str = "\001\002\003\004\005"
137
- subject.read(str)
138
- subject.a.clear
139
- subject.to_binary_s.should == "\012\002\003\004\012"
118
+ obj.read(str)
119
+ obj.a.clear
120
+ obj.to_binary_s.must_equal "\012\002\003\004\012"
140
121
  end
141
122
  end
142
123
 
@@ -149,23 +130,23 @@ describe BinData::Record, "with hidden fields" do
149
130
  int8 :d, :value => :b
150
131
  end
151
132
 
152
- subject { HiddenRecord.new }
133
+ let(:obj) { HiddenRecord.new }
153
134
 
154
135
  it "only shows fields that aren't hidden" do
155
- subject.field_names.should == ["a", "d"]
136
+ obj.field_names.must_equal ["a", "d"]
156
137
  end
157
138
 
158
139
  it "accesses hidden fields directly" do
159
- subject.b.should == 10
160
- subject.c = 15
161
- subject.c.should == 15
140
+ obj.b.must_equal 10
141
+ obj.c = 15
142
+ obj.c.must_equal 15
162
143
 
163
- subject.should respond_to(:b=)
144
+ obj.must_respond_to :b=
164
145
  end
165
146
 
166
147
  it "does not include hidden fields in snapshot" do
167
- subject.b = 5
168
- subject.snapshot.should == {"a" => 0, "d" => 5}
148
+ obj.b = 5
149
+ obj.snapshot.must_equal({"a" => 0, "d" => 5})
169
150
  end
170
151
  end
171
152
 
@@ -175,57 +156,57 @@ describe BinData::Record, "with multiple fields" do
175
156
  int8 :b
176
157
  end
177
158
 
178
- subject { MultiFieldRecord.new(:a => 1, :b => 2) }
159
+ let(:obj) { MultiFieldRecord.new(:a => 1, :b => 2) }
179
160
 
180
161
  it "returns num_bytes" do
181
- subject.a.num_bytes.should == 1
182
- subject.b.num_bytes.should == 1
183
- subject.num_bytes.should == 2
162
+ obj.a.num_bytes.must_equal 1
163
+ obj.b.num_bytes.must_equal 1
164
+ obj.num_bytes.must_equal 2
184
165
  end
185
166
 
186
167
  it "identifies accepted parameters" do
187
- BinData::Record.accepted_parameters.all.should include(:hide)
188
- BinData::Record.accepted_parameters.all.should include(:endian)
168
+ BinData::Record.accepted_parameters.all.must_include :hide
169
+ BinData::Record.accepted_parameters.all.must_include :endian
189
170
  end
190
171
 
191
172
  it "clears" do
192
- subject.a = 6
193
- subject.clear
194
- subject.should be_clear
173
+ obj.a = 6
174
+ obj.clear
175
+ assert obj.clear?
195
176
  end
196
177
 
197
178
  it "clears individual elements" do
198
- subject.a = 6
199
- subject.b = 7
200
- subject.a.clear
201
- subject.a.should be_clear
202
- subject.b.should_not be_clear
179
+ obj.a = 6
180
+ obj.b = 7
181
+ obj.a.clear
182
+ assert obj.a.clear?
183
+ refute obj.b.clear?
203
184
  end
204
185
 
205
186
  it "writes ordered" do
206
- subject.to_binary_s.should == "\x01\x02"
187
+ obj.to_binary_s.must_equal "\x01\x02"
207
188
  end
208
189
 
209
190
  it "reads ordered" do
210
- subject.read("\x03\x04")
191
+ obj.read("\x03\x04")
211
192
 
212
- subject.a.should == 3
213
- subject.b.should == 4
193
+ obj.a.must_equal 3
194
+ obj.b.must_equal 4
214
195
  end
215
196
 
216
197
  it "returns a snapshot" do
217
- snap = subject.snapshot
218
- snap.a.should == 1
219
- snap.b.should == 2
220
- snap.should == { "a" => 1, "b" => 2 }
198
+ snap = obj.snapshot
199
+ snap.a.must_equal 1
200
+ snap.b.must_equal 2
201
+ snap.must_equal({ "a" => 1, "b" => 2 })
221
202
  end
222
203
 
223
204
  it "returns field_names" do
224
- subject.field_names.should == ["a", "b"]
205
+ obj.field_names.must_equal ["a", "b"]
225
206
  end
226
207
 
227
208
  it "fails on unknown method call" do
228
- expect { subject.does_not_exist }.to raise_error(NoMethodError)
209
+ lambda { obj.does_not_exist }.must_raise NoMethodError
229
210
  end
230
211
  end
231
212
 
@@ -243,45 +224,45 @@ describe BinData::Record, "with nested structs" do
243
224
  end
244
225
  end
245
226
 
246
- subject { NestedStructRecord.new }
227
+ let(:obj) { NestedStructRecord.new }
247
228
 
248
229
  it "includes nested field names" do
249
- subject.field_names.should == ["a", "b", "c"]
230
+ obj.field_names.must_equal ["a", "b", "c"]
250
231
  end
251
232
 
252
233
  it "hides nested field names" do
253
- subject.b.field_names.should == ["x"]
234
+ obj.b.field_names.must_equal ["x"]
254
235
  end
255
236
 
256
237
  it "accesses nested fields" do
257
- subject.a.should == 6
258
- subject.b.w.should == 3
259
- subject.b.x.should == 6
260
- subject.c.y.should == 3
238
+ obj.a.must_equal 6
239
+ obj.b.w.must_equal 3
240
+ obj.b.x.must_equal 6
241
+ obj.c.y.must_equal 3
261
242
  end
262
243
 
263
244
  it "returns correct offset" do
264
- subject.offset.should == 0
265
- subject.b.offset.should == 1
266
- subject.b.w.offset.should == 1
267
- subject.c.offset.should == 3
268
- subject.c.z.offset.should == 4
245
+ obj.offset.must_equal 0
246
+ obj.b.offset.must_equal 1
247
+ obj.b.w.offset.must_equal 1
248
+ obj.c.offset.must_equal 3
249
+ obj.c.z.offset.must_equal 4
269
250
  end
270
251
 
271
252
  it "returns correct rel_offset" do
272
- subject.rel_offset.should == 0
273
- subject.b.rel_offset.should == 1
274
- subject.b.w.rel_offset.should == 0
275
- subject.c.rel_offset.should == 3
276
- subject.c.z.rel_offset.should == 1
253
+ obj.rel_offset.must_equal 0
254
+ obj.b.rel_offset.must_equal 1
255
+ obj.b.w.rel_offset.must_equal 0
256
+ obj.c.rel_offset.must_equal 3
257
+ obj.c.z.rel_offset.must_equal 1
277
258
  end
278
259
 
279
260
  it "assigns nested fields" do
280
- subject.assign(:a => 2, :b => {:w => 4})
281
- subject.a.should == 2
282
- subject.b.w.should == 4
283
- subject.b.x.should == 2
284
- subject.c.y.should == 4
261
+ obj.assign(:a => 2, :b => {:w => 4})
262
+ obj.a.must_equal 2
263
+ obj.b.w.must_equal 4
264
+ obj.b.x.must_equal 2
265
+ obj.c.y.must_equal 4
285
266
  end
286
267
  end
287
268
 
@@ -292,10 +273,10 @@ describe BinData::Record, "with nested array of primitives" do
292
273
  end
293
274
  end
294
275
 
295
- subject { NestedPrimitiveArrayRecord.new }
276
+ let(:obj) { NestedPrimitiveArrayRecord.new }
296
277
 
297
278
  it "uses block as :type" do
298
- subject.snapshot.should == {"a" => [0, 1, 2]}
279
+ obj.snapshot.must_equal({"a" => [0, 1, 2]})
299
280
  end
300
281
  end
301
282
 
@@ -307,11 +288,11 @@ describe BinData::Record, "with nested array of structs" do
307
288
  end
308
289
  end
309
290
 
310
- subject { NestedStructArrayRecord.new }
291
+ let(:obj) { NestedStructArrayRecord.new }
311
292
 
312
293
  it "uses block as struct for :type" do
313
- subject.a[0].b = 2
314
- subject.snapshot.should == {"a" => [{"b" => 2, "c" => 0}]}
294
+ obj.a[0].b = 2
295
+ obj.snapshot.must_equal({"a" => [{"b" => 2, "c" => 0}]})
315
296
  end
316
297
  end
317
298
 
@@ -323,9 +304,9 @@ describe BinData::Record, "with nested choice with implied keys" do
323
304
  end
324
305
  end
325
306
 
326
- subject { NestedChoiceWithImpliedKeysRecord.new }
307
+ let(:obj) { NestedChoiceWithImpliedKeysRecord.new }
327
308
 
328
- its(:a) { should == 2 }
309
+ specify { obj.a.must_equal 2 }
329
310
  end
330
311
 
331
312
  describe BinData::Record, "with nested choice with explicit keys" do
@@ -336,9 +317,9 @@ describe BinData::Record, "with nested choice with explicit keys" do
336
317
  end
337
318
  end
338
319
 
339
- subject { NestedChoiceWithKeysRecord.new }
320
+ let(:obj) { NestedChoiceWithKeysRecord.new }
340
321
 
341
- its(:a) { should == 2 }
322
+ specify { obj.a.must_equal 2 }
342
323
  end
343
324
 
344
325
  describe BinData::Record, "with nested choice with names" do
@@ -349,9 +330,9 @@ describe BinData::Record, "with nested choice with names" do
349
330
  end
350
331
  end
351
332
 
352
- subject { NestedChoiceWithNamesRecord.new }
333
+ let(:obj) { NestedChoiceWithNamesRecord.new }
353
334
 
354
- its(:a) { should == 1 }
335
+ specify { obj.a.must_equal 1 }
355
336
  end
356
337
 
357
338
  describe BinData::Record, "with an endian defined" do
@@ -379,21 +360,21 @@ describe BinData::Record, "with an endian defined" do
379
360
  end
380
361
  end
381
362
 
382
- subject { RecordWithEndian.new }
363
+ let(:obj) { RecordWithEndian.new }
383
364
 
384
365
  it "uses correct endian" do
385
- subject.a = 1
386
- subject.b = 2.0
387
- subject.c[0] = 3
388
- subject.c[1] = 4
389
- subject.d = 5
390
- subject.e.f = 6
391
- subject.e.g = 7
392
- subject.h.i.j = 8
366
+ obj.a = 1
367
+ obj.b = 2.0
368
+ obj.c[0] = 3
369
+ obj.c[1] = 4
370
+ obj.d = 5
371
+ obj.e.f = 6
372
+ obj.e.g = 7
373
+ obj.h.i.j = 8
393
374
 
394
- expected = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNn')
375
+ lambdaed = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNn')
395
376
 
396
- subject.to_binary_s.should == expected
377
+ obj.to_binary_s.must_equal lambdaed
397
378
  end
398
379
  end
399
380
 
@@ -406,30 +387,30 @@ describe BinData::Record, "defined recursively" do
406
387
  end
407
388
 
408
389
  it "can be created" do
409
- subject = RecursiveRecord.new
390
+ obj = RecursiveRecord.new
410
391
  end
411
392
 
412
393
  it "reads" do
413
394
  str = "\x00\x01\x01\x00\x02\x01\x00\x03\x00"
414
- subject = RecursiveRecord.read(str)
415
- subject.val.should == 1
416
- subject.nxt.val.should == 2
417
- subject.nxt.nxt.val.should == 3
395
+ obj = RecursiveRecord.read(str)
396
+ obj.val.must_equal 1
397
+ obj.nxt.val.must_equal 2
398
+ obj.nxt.nxt.val.must_equal 3
418
399
  end
419
400
 
420
401
  it "is assignable on demand" do
421
- subject = RecursiveRecord.new
422
- subject.val = 13
423
- subject.nxt.val = 14
424
- subject.nxt.nxt.val = 15
402
+ obj = RecursiveRecord.new
403
+ obj.val = 13
404
+ obj.nxt.val = 14
405
+ obj.nxt.nxt.val = 15
425
406
  end
426
407
 
427
408
  it "writes" do
428
- subject = RecursiveRecord.new
429
- subject.val = 5
430
- subject.nxt.val = 6
431
- subject.nxt.nxt.val = 7
432
- subject.to_binary_s.should == "\x00\x05\x01\x00\x06\x01\x00\x07\x00"
409
+ obj = RecursiveRecord.new
410
+ obj.val = 5
411
+ obj.nxt.val = 6
412
+ obj.nxt.nxt.val = 7
413
+ obj.to_binary_s.must_equal "\x00\x05\x01\x00\x06\x01\x00\x07\x00"
433
414
  end
434
415
  end
435
416
 
@@ -441,12 +422,12 @@ describe BinData::Record, "with custom mandatory parameters" do
441
422
  end
442
423
 
443
424
  it "raises error if mandatory parameter is not supplied" do
444
- expect { MandatoryRecord.new }.to raise_error(ArgumentError)
425
+ lambda { MandatoryRecord.new }.must_raise ArgumentError
445
426
  end
446
427
 
447
428
  it "uses mandatory parameter" do
448
- subject = MandatoryRecord.new(:arg1 => 5)
449
- subject.a.should == 5
429
+ obj = MandatoryRecord.new(:arg1 => 5)
430
+ obj.a.must_equal 5
450
431
  end
451
432
  end
452
433
 
@@ -458,29 +439,25 @@ describe BinData::Record, "with custom default parameters" do
458
439
  uint8 :b
459
440
  end
460
441
 
461
- it "does not raise error if default parameter is not supplied" do
462
- expect { DefaultRecord.new }.not_to raise_error(ArgumentError)
463
- end
464
-
465
442
  it "uses default parameter" do
466
- subject = DefaultRecord.new
467
- subject.a.should == 5
443
+ obj = DefaultRecord.new
444
+ obj.a.must_equal 5
468
445
  end
469
446
 
470
447
  it "overrides default parameter" do
471
- subject = DefaultRecord.new(:arg1 => 7)
472
- subject.a.should == 7
448
+ obj = DefaultRecord.new(:arg1 => 7)
449
+ obj.a.must_equal 7
473
450
  end
474
451
 
475
452
  it "accepts values" do
476
- subject = DefaultRecord.new(:b => 2)
477
- subject.b.should == 2
453
+ obj = DefaultRecord.new(:b => 2)
454
+ obj.b.must_equal 2
478
455
  end
479
456
 
480
457
  it "accepts values and parameters" do
481
- subject = DefaultRecord.new({:b => 2}, :arg1 => 3)
482
- subject.a.should == 3
483
- subject.b.should == 2
458
+ obj = DefaultRecord.new({:b => 2}, :arg1 => 3)
459
+ obj.a.must_equal 3
460
+ obj.b.must_equal 2
484
461
  end
485
462
  end
486
463
 
@@ -491,15 +468,17 @@ describe BinData::Record, "with :onlyif" do
491
468
  uint8 :c, :initial_value => 7, :onlyif => lambda { a != 3 }
492
469
  end
493
470
 
494
- subject { OnlyIfRecord.new }
471
+ let(:obj) { OnlyIfRecord.new }
495
472
 
496
- its(:num_bytes) { should == 2 }
497
- its(:snapshot) { should == {"a" => 3, "b" => 5} }
498
- its(:to_binary_s) { should == "\x03\x05" }
473
+ it "initial state" do
474
+ obj.num_bytes.must_equal 2
475
+ obj.snapshot.must_equal({"a" => 3, "b" => 5})
476
+ obj.to_binary_s.must_equal "\x03\x05"
477
+ end
499
478
 
500
- it "reads as expected" do
501
- subject.read("\x01\x02")
502
- subject.snapshot.should == {"a" => 1, "c" => 2}
479
+ it "reads as lambdaed" do
480
+ obj.read("\x01\x02")
481
+ obj.snapshot.must_equal({"a" => 1, "c" => 2})
503
482
  end
504
483
  end
505
484
 
@@ -517,14 +496,14 @@ describe BinData::Record, "derived classes" do
517
496
  end
518
497
 
519
498
  it "does not affect parent" do
520
- ParentRecord.new.field_names.should == ["a"]
499
+ ParentRecord.new.field_names.must_equal ["a"]
521
500
  end
522
501
 
523
502
  it "inherits fields for first child" do
524
- Child1Record.new.field_names.should == ["a", "b"]
503
+ Child1Record.new.field_names.must_equal ["a", "b"]
525
504
  end
526
505
 
527
506
  it "inherits fields for second child" do
528
- Child2Record.new.field_names.should == ["a", "b", "c"]
507
+ Child2Record.new.field_names.must_equal ["a", "b", "c"]
529
508
  end
530
509
  end