Commit efd77e1

mo khan <mo@mokhan.ca>
2015-04-08 18:12:20
remove empty attributes.
1 parent af841c9
Changed files (2)
lib/scale/rectangle.rb
@@ -14,7 +14,7 @@ module Scale
     end
 
     def attributes
-      { width: width, height: height, fill: fill, x: x, y: y, rx: rx, ry: ry }
+      { width: width, height: height, fill: fill, x: x, y: y, rx: rx, ry: ry }.delete_if { |key, value| value.nil? }
     end
   end
 end
spec/rectangle_spec.rb
@@ -2,34 +2,38 @@ describe Scale::Rectangle do
   it { expect(subject.xml_tag).to eql(:rect) }
 
   describe "#attributes" do
-    it 'includes the x position of the top left corner' do
+    it "includes the x position of the top left corner" do
       subject.x = 10
       expect(subject.attributes).to include(x: 10)
     end
 
-    it 'includes the y position of the top left corner' do
+    it "includes the y position of the top left corner" do
       subject.y = 10
       expect(subject.attributes).to include(y: 10)
     end
 
-    it 'includes the width' do
+    it "includes the width" do
       subject.width = "100%"
       expect(subject.attributes).to include(width: "100%")
     end
 
-    it 'includes the height' do
+    it "includes the height" do
       subject.height = "100%"
       expect(subject.attributes).to include(height: "100%")
     end
 
-    it 'includes the x radius of the corners' do
+    it "includes the x radius of the corners" do
       subject.rx = 10
       expect(subject.attributes).to include(rx: 10)
     end
 
-    it 'includes the y radius of the corners' do
+    it "includes the y radius of the corners" do
       subject.ry = 10
       expect(subject.attributes).to include(ry: 10)
     end
+
+    it "skips attributes that are not specified" do
+      expect(subject.attributes).to be_empty
+    end
   end
 end