spec/blobject_spec.rb in blobject-0.3.3 vs spec/blobject_spec.rb in blobject-0.3.7

- old
+ new

@@ -45,10 +45,47 @@ assert_instance_of Blobject, b.name assert_equal b.name.christian, "Vinnie" assert_equal b.name.surname, "Jones" end + it 'recursively blobjectifies assigned values' do + b.data = {name: 'jim', number: 144} + b.data.must_be_instance_of Blobject + end + + it 'recursively blobjectifies assigned arrays' do + b.data = [{name: 'jim', number: 144}, [{name: 'jam', number: 147}]] + b.data[0].must_be_instance_of Blobject + b.data[1][0].must_be_instance_of Blobject + end + + it 'can indicate whether it is empty' do + b = Blobject.new + b.must_be :empty? + b.name = "something" + b.wont_be :empty? + end + + describe 'hash-like access' do + + it 'allows hash-style setters' do + + b[:foo] = 123 + b['bar'] = 456 + + assert_equal "#{b.foo}#{b.bar}", '123456' + end + + it 'allows hash-style getters' do + + b.name = "Jimmy" + + assert_equal b[:name] , "Jimmy" + assert_equal b['name'], "Jimmy" + end + end + describe 'respond_to?' do it 'returns true if the blobject has the corresponding member' do b.name = 'jim' assert b.respond_to?(:name) @@ -231,20 +268,27 @@ assert_equal b.name.first, 'Barry' end end end - describe 'frozen blobject' do + describe 'freeze' do + it 'freezes the internal hash' do + b.freeze + b.hash.must_be :frozen? + end + end + describe 'freeze_r' do + before :each do list_element = Blobject.new b.name.first = 'barry' b.data.list = [1, 2, 3, list_element] b.data.inner_hash = {:inner => {:one => 1}} - b.freeze + b.freeze_r end it 'still provides access' do refute_nil b.name.first end @@ -266,12 +310,12 @@ it 'raises an error when trying to set an attribute' do proc { b.hello = 123 }.must_raise RuntimeError end - it 'returns nil when trying to get an attribute' do - assert b.meow_face.nil?, 'method missing returned something' + it 'still returns a blobject when trying to get an attribute' do + b.meow_face.must_be_instance_of Blobject # check again to test memoized method - assert b.meow_face.nil?, 'memoized method returned something' - end + b.meow_face.must_be_instance_of Blobject + end end end \ No newline at end of file