main
1describe Scale::Path do
2 describe "#move_to" do
3 it 'moves' do
4 subject.move_to(x: 10, y: 10)
5 expected = <<-XML
6<?xml version="1.0"?>
7<path d="M10 10"/>
8 XML
9 expect(subject.to_xml).to eql(expected)
10 end
11 end
12
13 describe "#line_to" do
14 it 'draws a line to the x and y coordinate' do
15 subject.move_to(x: 10, y: 10)
16 subject.line_to(x: 20, y: 20)
17 expected = <<-XML
18<?xml version="1.0"?>
19<path d="M10 10 L 20 20"/>
20 XML
21 expect(subject.to_xml).to eql(expected)
22 end
23 end
24
25 describe "#horizontal" do
26 before :each do
27 subject.move_to(x: 10, y: 10)
28 end
29
30 it 'draws a horizontal line' do
31 subject.horizontal(90)
32 expected = <<-XML
33<?xml version="1.0"?>
34<path d="M10 10 H 90"/>
35 XML
36 expect(subject.to_xml).to eql(expected)
37 end
38
39 it 'moves horizontally using relative position' do
40 subject.horizontal(90, relative: true)
41 expected = <<-XML
42<?xml version="1.0"?>
43<path d="M10 10 h 90"/>
44 XML
45 expect(subject.to_xml).to eql(expected)
46 end
47 end
48
49 describe "#vertical" do
50 before :each do
51 subject.move_to(x: 10, y: 10)
52 end
53
54 it 'draws a vertical line' do
55 subject.vertical(90)
56 expected = <<-XML
57<?xml version="1.0"?>
58<path d="M10 10 V 90"/>
59 XML
60 expect(subject.to_xml).to eql(expected)
61 end
62
63 it 'draws a vertical line relative to the current position' do
64 subject.vertical(90, relative: true)
65 expected = <<-XML
66<?xml version="1.0"?>
67<path d="M10 10 v 90"/>
68 XML
69 expect(subject.to_xml).to eql(expected)
70 end
71 end
72
73 describe "#close_path" do
74 it 'navigates back to the start' do
75 subject.move_to(x: 10, y: 10)
76 subject.horizontal(10)
77 subject.close_path
78 expected = <<-XML
79<?xml version="1.0"?>
80<path d="M10 10 H 10 Z"/>
81 XML
82 expect(subject.to_xml).to eql(expected)
83 end
84 end
85
86 describe "drawing a rectangle" do
87 it 'draws the proper rectangle' do
88 subject.move_to(x: 10, y: 10)
89 subject.horizontal(90)
90 subject.vertical(90)
91 subject.horizontal(10)
92 subject.line_to(x: 10, y: 10)
93
94 expected = <<-XML
95<?xml version="1.0"?>
96<path d="M10 10 H 90 V 90 H 10 L 10 10"/>
97 XML
98 expect(subject.to_xml).to eql(expected)
99 end
100 end
101end