spec/structure_spec.rb in structure-0.3.0 vs spec/structure_spec.rb in structure-0.3.1
- old
+ new
@@ -47,19 +47,32 @@
end.to raise_error TypeError
end
end
end
+ describe "#default_attributes" do
+ it "returns the default attributes for the structure" do
+ Person.send(:default_attributes).should == { :name => nil,
+ :age => nil,
+ :friends => [] }
+ Book.send(:default_attributes).should == { :title => nil,
+ :authors => nil }
+ end
+ end
+
describe "attribute getter" do
it "returns the value of the attribute" do
person.instance_variable_get(:@attributes)[:name] = 'Joe'
person.name.should eql 'Joe'
end
context "when type is Array and default value is []" do
+ let(:friend) { Person.new }
+
it "supports the `<<' idiom" do
- person.friends << Person.new
+ person.friends << friend
person.friends.count.should eql 1
+ friend.friends.count.should eql 0
end
end
end
describe "attribute setter" do