bindata 1.4.3 → 1.4.4

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.

Potentially problematic release.


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

data/spec/choice_spec.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
4
4
  require File.expand_path(File.join(File.dirname(__FILE__), "example"))
5
5
  require 'bindata/choice'
6
+ require 'bindata/int'
6
7
 
7
8
  class Chooser
8
9
  attr_accessor :choice
@@ -26,89 +27,91 @@ def create_choice(choices, options = {})
26
27
  end
27
28
 
28
29
  describe BinData::Choice, "when instantiating" do
29
- it "should ensure mandatory parameters are supplied" do
30
+ it "ensures mandatory parameters are supplied" do
30
31
  args = {}
31
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
32
+ expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
33
+
32
34
  args = {:selection => 1}
33
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
35
+ expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
36
+
34
37
  args = {:choices => []}
35
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
38
+ expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
36
39
  end
37
40
 
38
- it "should fail if a given type is unknown" do
41
+ it "fails when a given type is unknown" do
39
42
  args = {:choices => [:does_not_exist], :selection => 0}
40
- lambda { BinData::Choice.new(args) }.should raise_error(BinData::UnRegisteredTypeError)
43
+ expect { BinData::Choice.new(args) }.to raise_error(BinData::UnRegisteredTypeError)
41
44
  end
42
45
 
43
- it "should fail if a given type is unknown" do
46
+ it "fails when a given type is unknown" do
44
47
  args = {:choices => {0 => :does_not_exist}, :selection => 0}
45
- lambda { BinData::Choice.new(args) }.should raise_error(BinData::UnRegisteredTypeError)
48
+ expect { BinData::Choice.new(args) }.to raise_error(BinData::UnRegisteredTypeError)
46
49
  end
47
50
 
48
- it "should fail if :choices Hash has a symbol as key" do
51
+ it "fails when :choices Hash has a symbol as key" do
49
52
  args = {:choices => {:a => :example_single}, :selection => 0}
50
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
53
+ expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
51
54
  end
52
55
 
53
- it "should fail if :choices Hash has a nil key" do
56
+ it "fails when :choices Hash has a nil key" do
54
57
  args = {:choices => {nil => :example_single}, :selection => 0}
55
- lambda { BinData::Choice.new(args) }.should raise_error(ArgumentError)
58
+ expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
56
59
  end
57
60
  end
58
61
 
59
- share_examples_for "Choice initialized with array or hash" do
60
- it "should be able to select the choice" do
62
+ shared_examples "Choice initialized with array or hash" do
63
+ it "can select the choice" do
61
64
  subject.choice = 3
62
65
  subject.should == 30
63
66
  end
64
67
 
65
- it "should show the current selection" do
68
+ it "shows the current selection" do
66
69
  subject.choice = 3
67
70
  subject.selection.should == 3
68
71
  end
69
72
 
70
- it "should forward #snapshot" do
73
+ it "forwards #snapshot" do
71
74
  subject.choice = 3
72
75
  subject.snapshot.should == 30
73
76
  end
74
77
 
75
- it "should be able to change the choice" do
78
+ it "can change the choice" do
76
79
  subject.choice = 3
77
80
 
78
81
  subject.choice = 7
79
82
  subject.should == 70
80
83
  end
81
84
 
82
- it "should fail if no choice has been set" do
83
- lambda { subject.to_s }.should raise_error(IndexError)
85
+ it "fails if no choice has been set" do
86
+ expect { subject.to_s }.to raise_error(IndexError)
84
87
  end
85
88
 
86
- it "should not be able to select an invalid choice" do
89
+ it "will not select an invalid choice" do
87
90
  subject.choice = 99
88
- lambda { subject.to_s }.should raise_error(IndexError)
91
+ expect { subject.to_s }.to raise_error(IndexError)
89
92
  end
90
93
 
91
- it "should not be able to select a nil choice" do
94
+ it "will not select a nil choice" do
92
95
  subject.choice = 1
93
- lambda { subject.to_s }.should raise_error(IndexError)
96
+ expect { subject.to_s }.to raise_error(IndexError)
94
97
  end
95
98
 
96
- it "should handle missing methods correctly" do
99
+ it "handles missing methods correctly" do
97
100
  subject.choice = 3
98
101
 
99
102
  subject.should respond_to(:value)
100
103
  subject.should_not respond_to(:does_not_exist)
101
- lambda { subject.does_not_exist }.should raise_error(NoMethodError)
104
+ expect { subject.does_not_exist }.to raise_error(NoMethodError)
102
105
  end
103
106
 
104
- it "should delegate methods to the selected single choice" do
107
+ it "delegates methods to the selected single choice" do
105
108
  subject.choice = 5
106
109
  subject.num_bytes.should == ExampleSingle.new.num_bytes
107
110
  end
108
111
  end
109
112
 
110
113
  describe BinData::Choice, "with sparse choices array" do
111
- it_should_behave_like "Choice initialized with array or hash"
114
+ include_examples "Choice initialized with array or hash"
112
115
 
113
116
  subject {
114
117
  choices = [nil, nil, nil,
@@ -120,7 +123,7 @@ describe BinData::Choice, "with sparse choices array" do
120
123
  end
121
124
 
122
125
  describe BinData::Choice, "with choices hash" do
123
- it_should_behave_like "Choice initialized with array or hash"
126
+ include_examples "Choice initialized with array or hash"
124
127
 
125
128
  subject {
126
129
  choices = {3 => [:example_single, {:value => 30}],
@@ -138,13 +141,13 @@ describe BinData::Choice, "with single values" do
138
141
  create_choice(choices)
139
142
  }
140
143
 
141
- it "should assign raw values" do
144
+ it "assigns raw values" do
142
145
  subject.choice = 3
143
146
  subject.assign(254)
144
147
  subject.should == 254
145
148
  end
146
149
 
147
- it "should assign Single values" do
150
+ it "assigns Single values" do
148
151
  obj = ExampleSingle.new(11)
149
152
 
150
153
  subject.choice = 3
@@ -152,7 +155,7 @@ describe BinData::Choice, "with single values" do
152
155
  subject.should == 11
153
156
  end
154
157
 
155
- it "should clear" do
158
+ it "clears" do
156
159
  subject.choice = 3
157
160
  subject.assign(254)
158
161
 
@@ -160,20 +163,20 @@ describe BinData::Choice, "with single values" do
160
163
  subject.should be_zero
161
164
  end
162
165
 
163
- it "should be clear on initialisation" do
166
+ it "is clear on initialisation" do
164
167
  subject.choice = 3
165
168
 
166
169
  subject.should be_clear
167
170
  end
168
171
 
169
- it "should not be clear after assignment" do
172
+ it "is not clear after assignment" do
170
173
  subject.choice = 3
171
174
  subject.assign(254)
172
175
 
173
176
  subject.should_not be_clear
174
177
  end
175
178
 
176
- it "should not copy value when changing selection" do
179
+ it "does not copy value when changing selection" do
177
180
  subject.choice = 3
178
181
  subject.assign(254)
179
182
 
@@ -181,7 +184,7 @@ describe BinData::Choice, "with single values" do
181
184
  subject.should_not == 254
182
185
  end
183
186
 
184
- it "should behave as value" do
187
+ it "behaves as value" do
185
188
  subject.choice = 3
186
189
  subject.assign(5)
187
190
 
@@ -198,7 +201,7 @@ describe BinData::Choice, "with copy_on_change => true" do
198
201
  create_choice(choices, :copy_on_change => true)
199
202
  }
200
203
 
201
- it "should copy value when changing selection" do
204
+ it "copies value when changing selection" do
202
205
  subject.choice = 3
203
206
  subject.assign(254)
204
207
 
@@ -210,12 +213,12 @@ end
210
213
  describe BinData::Choice, "with :default" do
211
214
  let(:choices) { { "a" => :int8, :default => :int16be } }
212
215
 
213
- it "should select for existing case" do
216
+ it "selects for existing case" do
214
217
  subject = BinData::Choice.new(:selection => "a", :choices => choices)
215
218
  subject.num_bytes.should == 1
216
219
  end
217
220
 
218
- it "should select for default case" do
221
+ it "selects for default case" do
219
222
  subject = BinData::Choice.new(:selection => "other", :choices => choices)
220
223
  subject.num_bytes.should == 2
221
224
  end
@@ -231,17 +234,17 @@ describe BinData::Choice, "subclassed with default parameters" do
231
234
  uint64 :default
232
235
  end
233
236
 
234
- it "should set initial selection" do
237
+ it "sets initial selection" do
235
238
  subject = DerivedChoice.new
236
239
  subject.num_bytes.should == 2
237
240
  end
238
241
 
239
- it "should overide default parameter" do
242
+ it "overides default parameter" do
240
243
  subject = DerivedChoice.new(:selection => 'b')
241
244
  subject.num_bytes.should == 4
242
245
  end
243
246
 
244
- it "should select default selection" do
247
+ it "selects default selection" do
245
248
  subject = DerivedChoice.new(:selection => 'z')
246
249
  subject.num_bytes.should == 8
247
250
  end
@@ -5,37 +5,34 @@ require 'bindata/count_bytes_remaining'
5
5
 
6
6
  describe BinData::CountBytesRemaining do
7
7
  it { should == 0 }
8
+ its(:num_bytes) { should be_zero }
8
9
 
9
- it "should count till end of stream" do
10
+ it "counts till end of stream" do
10
11
  data = "abcdefghij"
11
12
  subject.read(data).should == 10
12
13
  end
13
14
 
14
- it "should have no size" do
15
- subject.num_bytes.should == 0
16
- end
17
-
18
- it "should not read any data" do
15
+ it "does not read any data" do
19
16
  io = StringIO.new "abcdefghij"
20
17
  subject.read(io)
21
18
 
22
19
  io.pos.should == 0
23
20
  end
24
21
 
25
- it "should not write any data" do
22
+ it "does not write any data" do
26
23
  subject.to_binary_s.should == ""
27
24
  end
28
25
 
29
- it "should allow setting value for completeness" do
26
+ it "allows setting value for completeness" do
30
27
  subject.assign("123")
31
28
  subject.should == "123"
32
29
  subject.to_binary_s.should == ""
33
30
  end
34
31
 
35
- it "should accept BinData::BasePrimitive parameters" do
32
+ it "accepts BinData::BasePrimitive parameters" do
36
33
  count = BinData::CountBytesRemaining.new(:check_value => 2)
37
- lambda {
34
+ expect {
38
35
  count.read("xyz")
39
- }.should raise_error(BinData::ValidityError)
36
+ }.to raise_error(BinData::ValidityError)
40
37
  end
41
38
  end
@@ -5,66 +5,66 @@ require File.expand_path(File.join(File.dirname(__FILE__), "example"))
5
5
  require 'bindata'
6
6
 
7
7
  describe BinData::SingleValue, "when defining" do
8
- it "should fail when inheriting from deprecated SingleValue" do
9
- lambda {
8
+ it "fails when inheriting from deprecated SingleValue" do
9
+ expect {
10
10
  class SubclassSingleValue < BinData::SingleValue
11
11
  end
12
- }.should raise_error
12
+ }.to raise_error
13
13
  end
14
14
  end
15
15
 
16
16
  describe BinData::MultiValue, "when defining" do
17
- it "should fail inheriting from deprecated MultiValue" do
18
- lambda {
17
+ it "fails inheriting from deprecated MultiValue" do
18
+ expect {
19
19
  class SubclassMultiValue < BinData::MultiValue
20
20
  end
21
- }.should raise_error
21
+ }.to raise_error
22
22
  end
23
23
  end
24
24
 
25
25
  describe BinData::Base, "when defining" do
26
- it "should fail if #initialize is overridden" do
26
+ it "fails if #initialize is overridden" do
27
27
  class BaseWithInitialize < BinData::Base
28
28
  def initialize(params = {}, parent = nil)
29
29
  super
30
30
  end
31
31
  end
32
32
 
33
- lambda {
33
+ expect {
34
34
  BaseWithInitialize.new
35
- }.should raise_error
35
+ }.to raise_error
36
36
  end
37
37
 
38
- it "should handle if #initialize is naively renamed to #initialize_instance" do
38
+ it "handles if #initialize is naively renamed to #initialize_instance" do
39
39
  class BaseWithInitializeInstance < BinData::Base
40
40
  def initialize_instance(params = {}, parent = nil)
41
41
  super
42
42
  end
43
43
  end
44
44
 
45
- lambda {
45
+ expect {
46
46
  BaseWithInitializeInstance.new
47
- }.should_not raise_error
47
+ }.not_to raise_error
48
48
  end
49
49
 
50
- it "should handle deprecated #register_self method" do
51
- lambda {
50
+ it "handles deprecated #register_self method" do
51
+ expect {
52
52
  class DeprecatedRegisterSelfBase < BinData::Base
53
53
  register_self
54
54
  end
55
- }.should_not raise_error
55
+ }.not_to raise_error
56
56
  end
57
57
 
58
- it "should handle deprecated #register method" do
59
- lambda {
58
+ it "handles deprecated #register method" do
59
+ expect {
60
60
  class DeprecatedRegisterBase < BinData::Base
61
61
  register(self.name, self)
62
62
  end
63
- }.should_not raise_error
63
+ }.not_to raise_error
64
64
  end
65
65
 
66
- it "should handle deprecated #register method for subclasses" do
67
- lambda {
66
+ it "handles deprecated #register method for subclasses" do
67
+ expect {
68
68
  class DeprecatedSuperBase < BinData::Base
69
69
  def self.inherited(subclass)
70
70
  register(subclass.name, subclass)
@@ -73,15 +73,15 @@ describe BinData::Base, "when defining" do
73
73
 
74
74
  class DeprecatedSubBase < DeprecatedSuperBase
75
75
  end
76
- }.should_not raise_error
76
+ }.not_to raise_error
77
77
  end
78
78
 
79
- it "should handle deprecated #register method with custom calling" do
80
- lambda {
79
+ it "handles deprecated #register method with custom calling" do
80
+ expect {
81
81
  class DeprecatedCustomBase < BinData::Base
82
82
  register(name, Object)
83
83
  end
84
- }.should_not raise_error
84
+ }.not_to raise_error
85
85
  end
86
86
  end
87
87
 
@@ -92,28 +92,28 @@ describe BinData::Base do
92
92
  subject { DeprecatedBase.new }
93
93
  let(:io) { "abcde" }
94
94
 
95
- it "should forward _do_read to do_read" do
95
+ it "forwards _do_read to do_read" do
96
96
  subject.should_receive(:do_read).with(io)
97
97
  subject._do_read(io)
98
98
  end
99
99
 
100
- it "should forward _do_write to do_write" do
100
+ it "forwards _do_write to do_write" do
101
101
  subject.should_receive(:do_write).with(io)
102
102
  subject._do_write(io)
103
103
  end
104
104
 
105
- it "should forward _do_num_bytes to do_num_bytes" do
105
+ it "forwards _do_num_bytes to do_num_bytes" do
106
106
  subject.should_receive(:do_num_bytes)
107
107
  subject._do_num_bytes
108
108
  end
109
109
 
110
- it "should forward _assign to assign" do
110
+ it "forwards _assign to assign" do
111
111
  val = 3
112
112
  subject.should_receive(:assign).with(val)
113
113
  subject._assign(val)
114
114
  end
115
115
 
116
- it "should forward _snapshot to snapshot" do
116
+ it "forwards _snapshot to snapshot" do
117
117
  subject.should_receive(:snapshot)
118
118
  subject._snapshot
119
119
  end
data/spec/float_spec.rb CHANGED
@@ -6,32 +6,32 @@ require 'bindata/float'
6
6
  describe "A FloatLe" do
7
7
  subject { BinData::FloatLe.new(Math::PI) }
8
8
 
9
- its(:num_bytes) { should == 4 }
10
- its(:to_binary_s) { should == [Math::PI].pack('e') }
11
- its(:value_read_from_written) { should be_close(Math::PI, 0.000001) }
9
+ its(:num_bytes) { should == 4 }
10
+ its(:to_binary_s) { should == [Math::PI].pack('e') }
11
+ its(:value_read_from_written) { should be_within(0.000001).of(Math::PI) }
12
12
  end
13
13
 
14
14
  describe "A FloatBe" do
15
15
  subject { BinData::FloatBe.new(Math::PI) }
16
16
 
17
- its(:num_bytes) { should == 4 }
18
- its(:to_binary_s) { should == [Math::PI].pack('g') }
19
- its(:value_read_from_written) { should be_close(Math::PI, 0.000001) }
17
+ its(:num_bytes) { should == 4 }
18
+ its(:to_binary_s) { should == [Math::PI].pack('g') }
19
+ its(:value_read_from_written) { should be_within(0.000001).of(Math::PI) }
20
20
  end
21
21
 
22
22
  describe "A DoubleLe" do
23
23
  subject { BinData::DoubleLe.new(Math::PI) }
24
24
 
25
- its(:num_bytes) { should == 8 }
26
- its(:to_binary_s) { should == [Math::PI].pack('E') }
27
- its(:value_read_from_written) { should be_close(Math::PI, 0.0000000000000001) }
25
+ its(:num_bytes) { should == 8 }
26
+ its(:to_binary_s) { should == [Math::PI].pack('E') }
27
+ its(:value_read_from_written) { should be_within(0.0000000000000001).of(Math::PI) }
28
28
  end
29
29
 
30
30
 
31
31
  describe "A DoubleBe" do
32
32
  subject { BinData::DoubleBe.new(Math::PI) }
33
33
 
34
- its(:num_bytes) { should == 8 }
35
- its(:to_binary_s) { should == [Math::PI].pack('G') }
36
- its(:value_read_from_written) { should be_close(Math::PI, 0.0000000000000001) }
34
+ its(:num_bytes) { should == 8 }
35
+ its(:to_binary_s) { should == [Math::PI].pack('G') }
36
+ its(:value_read_from_written) { should be_within(0.0000000000000001).of(Math::PI) }
37
37
  end