Permalink
Browse files

Added a spec for DataEntity

  • Loading branch information...
1 parent 44d9736 commit a6f76e0d307ec60412b6094471b6f9acfd2afc87 @farcaller farcaller committed Apr 16, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/indis-core/data_entity.rb
  2. +13 −0 spec/indis-core/data_entity_spec.rb
@@ -45,7 +45,7 @@ class DataEntity < Entity
# @param [Indus::VMMap] vmmap map of the target to load value from
# @raise [AttributeError] if the size is not one of the known values
def initialize(ofs, size, vmmap)
- raise AttributeError, "Unaligned size" unless KIND[size]
+ raise ArgumentError, "Unaligned size" unless KIND[size]
super ofs
@size = size
@value = vmmap.bytes_at(ofs, size).reverse_each.reduce(0) { |v, i| (v << 8) + i }
@@ -0,0 +1,13 @@
+require 'indis-core/data_entity'
+
+describe Indis::DataEntity do
+ it "should load its value from vmmap" do
+ map = double('VMMap', bytes_at: [1, 2, 3, 4])
+ e = Indis::DataEntity.new(0, 4, map)
+ e.to_s.should == "DCD\t04030201"
+ end
+
+ it "should raise an erorr if the size is bad" do
+ expect { Indis::DataEntity.new(0, 3, nil) }.to raise_error(ArgumentError)
+ end
+end

0 comments on commit a6f76e0

Please sign in to comment.