spec/blobject_spec.rb in blobject-0.3.7 vs spec/blobject_spec.rb in blobject-0.4.0
- old
+ new
@@ -17,11 +17,11 @@
b.checker_with_an_arg? :this_should_not_be_here
end.must_raise NoMethodError
end
- it 'provides access tot he internal hash with #hash' do
+ it 'provides access to the internal hash with #hash' do
assert b.hash.equal?(b.instance_variable_get :@hash)
end
it 'sets values when calling a writer' do
b.number = 123
@@ -37,13 +37,13 @@
b.fish.food
assert !b.fish?, 'should not have assigned an empty blobject'
end
it 'turns hashes into blobjects when assigning' do
-
+
b.name = { christian: "Vinnie", surname: "Jones" }
-
+
assert_instance_of Blobject, b.name
assert_equal b.name.christian, "Vinnie"
assert_equal b.name.surname, "Jones"
end
@@ -66,54 +66,54 @@
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)
assert b.respond_to?(:name=)
assert b.respond_to?(:name?)
end
- it 'should return true if a prohibited attribute name is a defined method' do
+ it 'returns true if a prohibited attribute name is a defined method' do
def b.to_ary
123
end
assert b.respond_to? :to_ary
end
- it 'should return false if the methods ends with a !' do
+ it 'returns false if the methods ends with a !' do
refute b.respond_to? :hello!
end
it 'returns true if the blobject has no corresponding member' do
b.name = 'jim'
assert b.respond_to?(:name)
assert b.respond_to?(:name=)
assert b.respond_to?(:name?)
end
- it 'should return true if the blobject has the corresponding member but the accessor has not been memoized' do
+ it 'returns true if the blobject has the corresponding member but the accessor has not been memoized' do
b = Blobject.new :name => 'barry'
assert b.respond_to?(:name)
assert b.respond_to?(:name=)
assert b.respond_to?(:name?)
end
@@ -137,13 +137,13 @@
assert_equal h[:name][:first], 'barry'
end
end
describe 'from_json' do
-
+
describe 'array' do
-
+
it 'returns an array with blobjects not hashes' do
json = '[1, true, {"meaning": false}]'
array = Blobject.from_json json
assert_instance_of Array, array
@@ -152,11 +152,11 @@
assert_instance_of Blobject, array[2]
end
end
describe 'json object' do
-
+
it 'returns a blobject which' do
json = '{"name": {"first": "doogle"}}'
b = Blobject.from_json json
assert_equal b.name.first, 'doogle'
assert b.name?
@@ -197,13 +197,17 @@
it 'returns false if the attribute does not exist' do
assert !b.fish?
end
- it 'does not indicate the boolean status of the value' do
- b.fish = false
- assert b.fish?
+ describe 'when the value is a boolean' do
+ it 'indicates false correctly' do
+ b.fish = true
+ assert b.fish?
+ b.fish = false
+ refute b.fish?
+ end
end
end
describe 'memoization' do
@@ -269,28 +273,25 @@
end
end
end
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_r
+ b.freeze
end
+ it 'freezes the internal hash' do
+ b.freeze
+ b.hash.must_be :frozen?
+ end
+
it 'still provides access' do
refute_nil b.name.first
end
it 'freezes the internal hash' do
@@ -316,6 +317,7 @@
b.meow_face.must_be_instance_of Blobject
# check again to test memoized method
b.meow_face.must_be_instance_of Blobject
end
end
-end
\ No newline at end of file
+
+end