main
1describe Scale::Node do
2 class FakeNode
3 include Scale::Node
4 attribute :x, Integer
5 attribute :y, Integer
6 attribute :font_size_adjust, Float
7
8 def xml_tag
9 :fake
10 end
11 end
12
13 subject { FakeNode.new }
14
15 describe "#xml_attributes" do
16 it "skips attributes that are not specified" do
17 expect(subject.xml_attributes).to be_empty
18 end
19 end
20
21 describe "#add" do
22 it 'adds a child node' do
23 child = Object.new
24 subject.add(child)
25 expect(subject).to include(child)
26 end
27 end
28
29 describe "#to_xml" do
30 it 'generates the full xml tree' do
31 grandchild = Scale::Rectangle.new(width: "100%", height: "100%", fill: "blue")
32 child = Scale::Rectangle.new(width: "100%", height: "100%", fill: "red")
33 child.add(grandchild)
34 subject.add(child)
35
36 expected = <<-XML
37<?xml version="1.0"?>
38<fake>
39 <rect width="100%" height="100%" fill="red">
40 <rect width="100%" height="100%" fill="blue"/>
41 </rect>
42</fake>
43 XML
44 expect(subject.to_xml).to eql(expected)
45 end
46
47 it 'replaces underscores in attribute names' do
48 subject.font_size_adjust = 0.5
49 expected = <<-XML
50<?xml version="1.0"?>
51<fake font-size-adjust="0.5"/>
52 XML
53 expect(subject.to_xml).to eql(expected)
54 end
55 end
56end