spec/choice_spec.rb in bindata-1.3.1 vs spec/choice_spec.rb in bindata-1.4.0
- old
+ new
@@ -65,16 +65,10 @@
it "should show the current selection" do
subject.choice = 3
subject.selection.should == 3
end
- it "should not be able to directly change the current selection" do
- lambda {
- subject.selection = 3
- }.should raise_error(NoMethodError)
- end
-
it "should forward #snapshot" do
subject.choice = 3
subject.snapshot.should == 30
end
@@ -208,7 +202,27 @@
subject.choice = 3
subject.assign(254)
subject.choice = 7
subject.should == 254
+ end
+end
+
+describe BinData::Choice, "subclassed with default parameters" do
+ class DerivedChoice < BinData::Choice
+ endian :big
+ default_parameter :selection => 'a'
+
+ uint16 'a'
+ uint32 'b'
+ end
+
+ it "should set initial selection" do
+ subject = DerivedChoice.new
+ subject.num_bytes.should == 2
+ end
+
+ it "should overide default parameter" do
+ subject = DerivedChoice.new(:selection => 'b')
+ subject.num_bytes.should == 4
end
end