prawn-svg 0.34.2 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +19 -0
  3. data/.github/workflows/test.yml +14 -27
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +86 -0
  6. data/.rubocop_todo.yml +51 -0
  7. data/Gemfile +4 -3
  8. data/Gemfile.lock +81 -0
  9. data/README.md +1 -1
  10. data/Rakefile +1 -1
  11. data/lib/prawn/svg/attributes/clip_path.rb +3 -3
  12. data/lib/prawn/svg/attributes/opacity.rb +3 -3
  13. data/lib/prawn/svg/attributes/stroke.rb +9 -9
  14. data/lib/prawn/svg/attributes/transform.rb +2 -2
  15. data/lib/prawn/svg/attributes.rb +1 -1
  16. data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +17 -15
  17. data/lib/prawn/svg/calculators/aspect_ratio.rb +16 -14
  18. data/lib/prawn/svg/calculators/document_sizing.rb +9 -10
  19. data/lib/prawn/svg/calculators/pixels.rb +8 -5
  20. data/lib/prawn/svg/color.rb +209 -212
  21. data/lib/prawn/svg/css/font_family_parser.rb +2 -2
  22. data/lib/prawn/svg/css/selector_parser.rb +39 -35
  23. data/lib/prawn/svg/css/stylesheets.rb +24 -24
  24. data/lib/prawn/svg/css/values_parser.rb +68 -0
  25. data/lib/prawn/svg/document.rb +6 -5
  26. data/lib/prawn/svg/elements/base.rb +29 -34
  27. data/lib/prawn/svg/elements/circle.rb +4 -4
  28. data/lib/prawn/svg/elements/clip_path.rb +0 -1
  29. data/lib/prawn/svg/elements/depth_first_base.rb +6 -6
  30. data/lib/prawn/svg/elements/ellipse.rb +3 -4
  31. data/lib/prawn/svg/elements/gradient.rb +49 -51
  32. data/lib/prawn/svg/elements/image.rb +5 -5
  33. data/lib/prawn/svg/elements/marker.rb +5 -5
  34. data/lib/prawn/svg/elements/path.rb +46 -47
  35. data/lib/prawn/svg/elements/polygon.rb +1 -1
  36. data/lib/prawn/svg/elements/polyline.rb +2 -2
  37. data/lib/prawn/svg/elements/rect.rb +3 -3
  38. data/lib/prawn/svg/elements/text.rb +1 -1
  39. data/lib/prawn/svg/elements/text_component.rb +22 -22
  40. data/lib/prawn/svg/elements/use.rb +3 -7
  41. data/lib/prawn/svg/elements/viewport.rb +1 -3
  42. data/lib/prawn/svg/elements.rb +30 -29
  43. data/lib/prawn/svg/extension.rb +2 -1
  44. data/lib/prawn/svg/font.rb +7 -7
  45. data/lib/prawn/svg/font_registry.rb +13 -13
  46. data/lib/prawn/svg/gradients.rb +3 -2
  47. data/lib/prawn/svg/interface.rb +4 -3
  48. data/lib/prawn/svg/loaders/data.rb +2 -2
  49. data/lib/prawn/svg/loaders/file.rb +12 -14
  50. data/lib/prawn/svg/loaders/web.rb +4 -8
  51. data/lib/prawn/svg/pathable.rb +41 -37
  52. data/lib/prawn/svg/properties.rb +34 -33
  53. data/lib/prawn/svg/renderer.rb +7 -7
  54. data/lib/prawn/svg/state.rb +1 -1
  55. data/lib/prawn/svg/transform_parser.rb +5 -5
  56. data/lib/prawn/svg/ttf.rb +21 -17
  57. data/lib/prawn/svg/url_loader.rb +1 -1
  58. data/lib/prawn/svg/version.rb +1 -1
  59. data/lib/prawn-svg.rb +1 -0
  60. data/prawn-svg.gemspec +4 -6
  61. data/spec/integration_spec.rb +77 -70
  62. data/spec/prawn/svg/attributes/opacity_spec.rb +11 -15
  63. data/spec/prawn/svg/attributes/transform_spec.rb +6 -6
  64. data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +50 -50
  65. data/spec/prawn/svg/calculators/document_sizing_spec.rb +35 -35
  66. data/spec/prawn/svg/calculators/pixels_spec.rb +31 -30
  67. data/spec/prawn/svg/color_spec.rb +31 -31
  68. data/spec/prawn/svg/css/font_family_parser_spec.rb +12 -12
  69. data/spec/prawn/svg/css/selector_parser_spec.rb +21 -21
  70. data/spec/prawn/svg/css/stylesheets_spec.rb +51 -45
  71. data/spec/prawn/svg/css/values_parser_spec.rb +16 -0
  72. data/spec/prawn/svg/document_spec.rb +15 -14
  73. data/spec/prawn/svg/elements/base_spec.rb +39 -34
  74. data/spec/prawn/svg/elements/gradient_spec.rb +39 -39
  75. data/spec/prawn/svg/elements/line_spec.rb +22 -22
  76. data/spec/prawn/svg/elements/marker_spec.rb +36 -40
  77. data/spec/prawn/svg/elements/path_spec.rb +134 -110
  78. data/spec/prawn/svg/elements/polygon_spec.rb +18 -18
  79. data/spec/prawn/svg/elements/polyline_spec.rb +16 -16
  80. data/spec/prawn/svg/elements/text_spec.rb +149 -127
  81. data/spec/prawn/svg/font_registry_spec.rb +34 -34
  82. data/spec/prawn/svg/font_spec.rb +4 -4
  83. data/spec/prawn/svg/interface_spec.rb +47 -39
  84. data/spec/prawn/svg/loaders/data_spec.rb +21 -21
  85. data/spec/prawn/svg/loaders/file_spec.rb +43 -40
  86. data/spec/prawn/svg/loaders/web_spec.rb +15 -15
  87. data/spec/prawn/svg/pathable_spec.rb +21 -21
  88. data/spec/prawn/svg/properties_spec.rb +51 -51
  89. data/spec/prawn/svg/transform_parser_spec.rb +12 -12
  90. data/spec/prawn/svg/ttf_spec.rb +5 -5
  91. data/spec/prawn/svg/url_loader_spec.rb +25 -23
  92. data/spec/spec_helper.rb +4 -4
  93. metadata +12 -143
@@ -5,66 +5,74 @@ describe Prawn::SVG::Interface do
5
5
  let(:prawn) { instance_double(Prawn::Document, font_families: {}, bounds: bounds, cursor: 600) }
6
6
  let(:svg) { '<svg width="250" height="100"></svg>' }
7
7
 
8
- describe "#initialize" do
9
- describe "invalid option detection" do
10
- it "rejects invalid options when debug is on" do
8
+ describe '#initialize' do
9
+ describe 'invalid option detection' do
10
+ it 'rejects invalid options when debug is on' do
11
11
  allow(Prawn).to receive(:debug).and_return(true)
12
12
 
13
- expect {
14
- Prawn::SVG::Interface.new(svg, prawn, :invalid => "option")
15
- }.to raise_error(Prawn::Errors::UnknownOption)
13
+ expect do
14
+ Prawn::SVG::Interface.new(svg, prawn, invalid: 'option')
15
+ end.to raise_error(Prawn::Errors::UnknownOption)
16
16
  end
17
17
 
18
- it "does nothing if an invalid option is given and debug is off" do
19
- Prawn::SVG::Interface.new(svg, prawn, :invalid => "option")
18
+ it 'does nothing if an invalid option is given and debug is off' do
19
+ Prawn::SVG::Interface.new(svg, prawn, invalid: 'option')
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
- describe "#draw" do
25
- context "when the sizing object indicates the sizes are invalid" do
24
+ describe '#draw' do
25
+ context 'when the sizing object indicates the sizes are invalid' do
26
26
  let(:interface) { Prawn::SVG::Interface.new('<svg width="0"></svg>', prawn, {}) }
27
27
 
28
28
  it "doesn't draw anything and adds a warning" do
29
29
  interface.draw
30
- expect(interface.document.warnings).to eq ["Zero or negative sizing data means this SVG cannot be rendered"]
30
+ expect(interface.document.warnings).to eq ['Zero or negative sizing data means this SVG cannot be rendered']
31
31
  end
32
32
  end
33
33
 
34
- describe "rewrites" do
34
+ describe 'rewrites' do
35
35
  before do
36
36
  [:save_font, :bounding_box].each { |message| allow(prawn).to receive(message).and_yield }
37
- allow(prawn).to receive_messages([:move_to, :line_to, :close_path, :fill_color, :stroke_color, :transformation_matrix, :restore_graphics_state])
38
- allow(prawn).to receive(:save_graphics_state) { |&block| block.call if block }
37
+ allow(prawn).to receive_messages([:move_to, :line_to, :close_path, :fill_color, :stroke_color,
38
+ :transformation_matrix, :restore_graphics_state])
39
+ allow(prawn).to receive(:save_graphics_state) { |&block| block&.call }
39
40
  end
40
41
 
41
- context "when fill_and_stroke is issued" do
42
+ context 'when fill_and_stroke is issued' do
42
43
  def expect_rectangle
43
- if RUBY_VERSION.start_with?("2.7.")
44
+ if RUBY_VERSION.start_with?('2.7.')
44
45
  expect(prawn).to receive(:rectangle)
45
46
  else
46
47
  expect(prawn).to receive(:rectangle).with([0, 100], 10, 10)
47
48
  end
48
49
  end
49
50
 
50
- context "and fill rule is not set" do
51
- let(:interface) { Prawn::SVG::Interface.new('<svg width="250" height="100"><rect width="10" height="10" stroke="red"></rect></svg>', prawn, {}) }
51
+ context 'and fill rule is not set' do
52
+ let(:interface) do
53
+ Prawn::SVG::Interface.new('<svg width="250" height="100"><rect width="10" height="10" stroke="red"></rect></svg>',
54
+ prawn, {})
55
+ end
52
56
 
53
57
  it "adds content 'B'" do
54
58
  expect_rectangle
55
- expect(prawn).to receive(:add_content).with("W n")
56
- expect(prawn).to receive(:add_content).with("B")
59
+ expect(prawn).to receive(:add_content).with('W n')
60
+ expect(prawn).to receive(:add_content).with('B')
57
61
  interface.draw
58
62
  end
59
63
  end
60
64
 
61
- context "and fill rule is evenodd" do
62
- let(:interface) { Prawn::SVG::Interface.new('<svg width="250" height="100"><rect width="10" height="10" stroke="red" fill-rule="evenodd"></rect></svg>', prawn, {}) }
65
+ context 'and fill rule is evenodd' do
66
+ let(:interface) do
67
+ Prawn::SVG::Interface.new(
68
+ '<svg width="250" height="100"><rect width="10" height="10" stroke="red" fill-rule="evenodd"></rect></svg>', prawn, {}
69
+ )
70
+ end
63
71
 
64
72
  it "adds content 'B*'" do
65
73
  expect_rectangle
66
- expect(prawn).to receive(:add_content).with("W n")
67
- expect(prawn).to receive(:add_content).with("B*")
74
+ expect(prawn).to receive(:add_content).with('W n')
75
+ expect(prawn).to receive(:add_content).with('B*')
68
76
  interface.draw
69
77
  end
70
78
  end
@@ -72,70 +80,70 @@ describe Prawn::SVG::Interface do
72
80
  end
73
81
  end
74
82
 
75
- describe "#position" do
83
+ describe '#position' do
76
84
  subject { interface.position }
77
85
 
78
- context "when options[:at] supplied" do
86
+ context 'when options[:at] supplied' do
79
87
  let(:interface) { Prawn::SVG::Interface.new(svg, prawn, at: [1, 2], position: :left) }
80
88
 
81
- it "returns options[:at]" do
89
+ it 'returns options[:at]' do
82
90
  expect(subject).to eq [1, 2]
83
91
  end
84
92
  end
85
93
 
86
- context "when only a position is supplied" do
94
+ context 'when only a position is supplied' do
87
95
  let(:interface) { Prawn::SVG::Interface.new(svg, prawn, position: position) }
88
96
 
89
- context "(:left)" do
97
+ context '(:left)' do
90
98
  let(:position) { :left }
91
99
  it { is_expected.to eq [0, 600] }
92
100
  end
93
101
 
94
- context "(:center)" do
102
+ context '(:center)' do
95
103
  let(:position) { :center }
96
104
  it { is_expected.to eq [275, 600] }
97
105
  end
98
106
 
99
- context "(:right)" do
107
+ context '(:right)' do
100
108
  let(:position) { :right }
101
109
  it { is_expected.to eq [550, 600] }
102
110
  end
103
111
 
104
- context "a number" do
112
+ context 'a number' do
105
113
  let(:position) { 25.5 }
106
114
  it { is_expected.to eq [25.5, 600] }
107
115
  end
108
116
  end
109
117
 
110
- context "when a vposition is supplied" do
118
+ context 'when a vposition is supplied' do
111
119
  let(:interface) { Prawn::SVG::Interface.new(svg, prawn, vposition: vposition) }
112
120
 
113
- context "(:top)" do
121
+ context '(:top)' do
114
122
  let(:vposition) { :top }
115
123
  it { is_expected.to eq [0, 600] }
116
124
  end
117
125
 
118
- context "(:center)" do
126
+ context '(:center)' do
119
127
  let(:vposition) { :center }
120
128
  it { is_expected.to eq [0, 350] }
121
129
  end
122
130
 
123
- context "(:bottom)" do
131
+ context '(:bottom)' do
124
132
  let(:vposition) { :bottom }
125
133
  it { is_expected.to eq [0, 100] }
126
134
  end
127
135
 
128
- context "a number" do
136
+ context 'a number' do
129
137
  let(:vposition) { 25.5 }
130
138
  it { is_expected.to eq [0, 600 - 25.5] }
131
139
  end
132
140
  end
133
141
  end
134
142
 
135
- describe "#sizing and #resize" do
143
+ describe '#sizing and #resize' do
136
144
  let(:interface) { Prawn::SVG::Interface.new(svg, prawn, {}) }
137
145
 
138
- it "allows the advanced user to resize the SVG after learning about its dimensions" do
146
+ it 'allows the advanced user to resize the SVG after learning about its dimensions' do
139
147
  expect(interface.sizing.output_width).to eq 250
140
148
  expect(interface.sizing.output_height).to eq 100
141
149
 
@@ -5,58 +5,58 @@ RSpec.describe Prawn::SVG::Loaders::Data do
5
5
 
6
6
  subject { Prawn::SVG::Loaders::Data.new.from_url(url) }
7
7
 
8
- context "with a valid image/png data URL" do
9
- let(:url) { "data:image/png;base64,aGVsbG8=" }
8
+ context 'with a valid image/png data URL' do
9
+ let(:url) { 'data:image/png;base64,aGVsbG8=' }
10
10
 
11
- it "loads the data" do
12
- expect(subject).to eq "hello"
11
+ it 'loads the data' do
12
+ expect(subject).to eq 'hello'
13
13
  end
14
14
  end
15
15
 
16
- context "with a valid image/jpeg data URL" do
17
- let(:url) { "data:image/jpeg;base64,aGVsbG8=" }
16
+ context 'with a valid image/jpeg data URL' do
17
+ let(:url) { 'data:image/jpeg;base64,aGVsbG8=' }
18
18
 
19
- it "loads the data" do
20
- expect(subject).to eq "hello"
19
+ it 'loads the data' do
20
+ expect(subject).to eq 'hello'
21
21
  end
22
22
  end
23
23
 
24
- context "with a data URL that has extra metadata" do
25
- let(:url) { "data:image/png;base64;metadata;here,aGVsbG8=" }
24
+ context 'with a data URL that has extra metadata' do
25
+ let(:url) { 'data:image/png;base64;metadata;here,aGVsbG8=' }
26
26
 
27
- it "loads the data" do
28
- expect(subject).to eq "hello"
27
+ it 'loads the data' do
28
+ expect(subject).to eq 'hello'
29
29
  end
30
30
  end
31
31
 
32
32
  context "with a data URL that's uppercase" do
33
- let(:url) { "DATA:IMAGE/PNG;BASE64;METADATA;HERE,aGVsbG8=" }
33
+ let(:url) { 'DATA:IMAGE/PNG;BASE64;METADATA;HERE,aGVsbG8=' }
34
34
 
35
- it "loads the data" do
36
- expect(subject).to eq "hello"
35
+ it 'loads the data' do
36
+ expect(subject).to eq 'hello'
37
37
  end
38
38
  end
39
39
 
40
40
  context "with a URL that's not a data scheme" do
41
- let(:url) { "http://some.host" }
41
+ let(:url) { 'http://some.host' }
42
42
 
43
- it "returns nil" do
43
+ it 'returns nil' do
44
44
  expect(subject).to be nil
45
45
  end
46
46
  end
47
47
 
48
48
  context "with a data URL that's not an image" do
49
- let(:url) { "data:application/pdf;base64,aGVsbG8=" }
49
+ let(:url) { 'data:application/pdf;base64,aGVsbG8=' }
50
50
 
51
- it "raises" do
51
+ it 'raises' do
52
52
  expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /image/
53
53
  end
54
54
  end
55
55
 
56
56
  context "with a data URL that's not base64 encoded" do
57
- let(:url) { "data:image/png;base32,agvsbg" }
57
+ let(:url) { 'data:image/png;base32,agvsbg' }
58
58
 
59
- it "raises" do
59
+ it 'raises' do
60
60
  expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /base64/
61
61
  end
62
62
  end
@@ -1,71 +1,73 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Prawn::SVG::Loaders::File do
4
- let(:root_path) { "." }
5
- let(:fake_root_path) { "/some" }
4
+ let(:root_path) { '.' }
5
+ let(:fake_root_path) { '/some' }
6
6
 
7
7
  let(:file_loader) { Prawn::SVG::Loaders::File.new(root_path) }
8
8
  subject { file_loader.from_url(url) }
9
9
 
10
- context "when an invalid path is supplied" do
11
- let(:root_path) { "/does/not/exist" }
10
+ context 'when an invalid path is supplied' do
11
+ let(:root_path) { '/does/not/exist' }
12
12
 
13
- it "raises with an ArgumentError" do
13
+ it 'raises with an ArgumentError' do
14
14
  expect { subject }.to raise_error ArgumentError, /is not a directory/
15
15
  end
16
16
  end
17
17
 
18
- context "when a relative path is supplied" do
19
- let(:url) { "relative/./path" }
18
+ context 'when a relative path is supplied' do
19
+ let(:url) { 'relative/./path' }
20
20
 
21
- it "loads the file" do
22
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
23
- expect(File).to receive(:expand_path).with("relative/./path", fake_root_path).and_return("#{fake_root_path}/relative/path")
21
+ it 'loads the file' do
22
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
23
+ expect(File).to receive(:expand_path).with('relative/./path',
24
+ fake_root_path).and_return("#{fake_root_path}/relative/path")
24
25
 
25
26
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
26
27
  expect(File).to receive(:exist?).with("#{fake_root_path}/relative/path").and_return(true)
27
- expect(IO).to receive(:binread).with("#{fake_root_path}/relative/path").and_return("data")
28
+ expect(File).to receive(:binread).with("#{fake_root_path}/relative/path").and_return('data')
28
29
 
29
30
  expect(subject).to eq 'data'
30
31
  end
31
32
  end
32
33
 
33
- context "when an absolute path without file scheme is supplied" do
34
- let(:url) { "/some/absolute/./path" }
34
+ context 'when an absolute path without file scheme is supplied' do
35
+ let(:url) { '/some/absolute/./path' }
35
36
 
36
- it "loads the file" do
37
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
38
- expect(File).to receive(:expand_path).with(url, fake_root_path).and_return("/some/absolute/path")
37
+ it 'loads the file' do
38
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
39
+ expect(File).to receive(:expand_path).with(url, fake_root_path).and_return('/some/absolute/path')
39
40
 
40
41
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
41
- expect(File).to receive(:exist?).with("/some/absolute/path").and_return(true)
42
- expect(IO).to receive(:binread).with("/some/absolute/path").and_return("data")
42
+ expect(File).to receive(:exist?).with('/some/absolute/path').and_return(true)
43
+ expect(File).to receive(:binread).with('/some/absolute/path').and_return('data')
43
44
 
44
45
  expect(subject).to eq 'data'
45
46
  end
46
47
  end
47
48
 
48
- context "when an absolute path with file scheme is supplied" do
49
- let(:url) { "file:///some/absolute/./path%20name" }
49
+ context 'when an absolute path with file scheme is supplied' do
50
+ let(:url) { 'file:///some/absolute/./path%20name' }
50
51
 
51
- it "loads the file" do
52
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
53
- expect(File).to receive(:expand_path).with("/some/absolute/./path name", fake_root_path).and_return("/some/absolute/path name")
52
+ it 'loads the file' do
53
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
54
+ expect(File).to receive(:expand_path).with('/some/absolute/./path name',
55
+ fake_root_path).and_return('/some/absolute/path name')
54
56
 
55
57
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
56
- expect(File).to receive(:exist?).with("/some/absolute/path name").and_return(true)
57
- expect(IO).to receive(:binread).with("/some/absolute/path name").and_return("data")
58
+ expect(File).to receive(:exist?).with('/some/absolute/path name').and_return(true)
59
+ expect(File).to receive(:binread).with('/some/absolute/path name').and_return('data')
58
60
 
59
61
  expect(subject).to eq 'data'
60
62
  end
61
63
  end
62
64
 
63
- context "when a path outside of our root is specified" do
64
- let(:url) { "/other/absolute/./path" }
65
+ context 'when a path outside of our root is specified' do
66
+ let(:url) { '/other/absolute/./path' }
65
67
 
66
- it "raises" do
67
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
68
- expect(File).to receive(:expand_path).with(url, fake_root_path).and_return("/other/absolute/path")
68
+ it 'raises' do
69
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
70
+ expect(File).to receive(:expand_path).with(url, fake_root_path).and_return('/other/absolute/path')
69
71
 
70
72
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
71
73
 
@@ -73,11 +75,11 @@ RSpec.describe Prawn::SVG::Loaders::File do
73
75
  end
74
76
  end
75
77
 
76
- context "when a file: url with a host is specified" do
77
- let(:url) { "file://somewhere/somefile" }
78
+ context 'when a file: url with a host is specified' do
79
+ let(:url) { 'file://somewhere/somefile' }
78
80
 
79
- it "raises" do
80
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
81
+ it 'raises' do
82
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
81
83
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
82
84
 
83
85
  expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /with a host/
@@ -85,16 +87,17 @@ RSpec.describe Prawn::SVG::Loaders::File do
85
87
  end
86
88
 
87
89
  context "when we're running on Windows" do
88
- let(:url) { "file:///c:/path/to/file.png" }
89
- let(:fake_root_path) { "c:/full" }
90
+ let(:url) { 'file:///c:/path/to/file.png' }
91
+ let(:fake_root_path) { 'c:/full' }
90
92
 
91
93
  it "automatically fixes up URI's misparsing of Windows file paths and loads the file" do
92
- expect(File).to receive(:expand_path).with(".").and_return(fake_root_path)
93
- expect(File).to receive(:expand_path).with("c:/path/to/file.png", fake_root_path).and_return("c:/full/path/to/file.png")
94
+ expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
95
+ expect(File).to receive(:expand_path).with('c:/path/to/file.png',
96
+ fake_root_path).and_return('c:/full/path/to/file.png')
94
97
 
95
98
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
96
- expect(File).to receive(:exist?).with("c:/full/path/to/file.png").and_return(true)
97
- expect(IO).to receive(:binread).with("c:/full/path/to/file.png").and_return("data")
99
+ expect(File).to receive(:exist?).with('c:/full/path/to/file.png').and_return(true)
100
+ expect(File).to receive(:binread).with('c:/full/path/to/file.png').and_return('data')
98
101
 
99
102
  allow(file_loader).to receive(:windows?).and_return true
100
103
  expect(subject).to eq 'data'
@@ -1,36 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Prawn::SVG::Loaders::Web do
4
- let(:url) { "http://hello.there/path" }
4
+ let(:url) { 'http://hello.there/path' }
5
5
  let(:uri) { URI(url) }
6
6
 
7
7
  subject { Prawn::SVG::Loaders::Web.new.from_url(url) }
8
8
 
9
- it "loads an HTTP URL" do
10
- expect(Net::HTTP).to receive(:get).with(uri).and_return("hello!")
11
- expect(subject).to eq "hello!"
9
+ it 'loads an HTTP URL' do
10
+ expect(Net::HTTP).to receive(:get).with(uri).and_return('hello!')
11
+ expect(subject).to eq 'hello!'
12
12
  end
13
13
 
14
- context "with an https URL" do
15
- let(:url) { "https://hello.there/path"}
14
+ context 'with an https URL' do
15
+ let(:url) { 'https://hello.there/path' }
16
16
 
17
- it "loads the HTTPS URL" do
18
- expect(Net::HTTP).to receive(:get).with(uri).and_return("hello!")
19
- expect(subject).to eq "hello!"
17
+ it 'loads the HTTPS URL' do
18
+ expect(Net::HTTP).to receive(:get).with(uri).and_return('hello!')
19
+ expect(subject).to eq 'hello!'
20
20
  end
21
21
  end
22
22
 
23
- context "when the HTTP call raises" do
24
- it "re-raises the error as UrlLoader errors" do
25
- expect(Net::HTTP).to receive(:get).with(uri).and_raise(SocketError, "argh")
23
+ context 'when the HTTP call raises' do
24
+ it 're-raises the error as UrlLoader errors' do
25
+ expect(Net::HTTP).to receive(:get).with(uri).and_raise(SocketError, 'argh')
26
26
  expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, 'argh'
27
27
  end
28
28
  end
29
29
 
30
- context "with a non-http, non-https URL" do
31
- let(:url) { "mailto:someone@something" }
30
+ context 'with a non-http, non-https URL' do
31
+ let(:url) { 'mailto:someone@something' }
32
32
 
33
- it "returns nil" do
33
+ it 'returns nil' do
34
34
  expect(subject).to be nil
35
35
  end
36
36
  end
@@ -22,68 +22,68 @@ RSpec.describe Prawn::SVG::Pathable do
22
22
  end
23
23
  end
24
24
 
25
- let(:document) { Prawn::SVG::Document.new("<svg></svg>", [800, 600], {width: 800, height: 600}) }
25
+ let(:document) { Prawn::SVG::Document.new('<svg></svg>', [800, 600], { width: 800, height: 600 }) }
26
26
  let(:state) { Prawn::SVG::State.new }
27
27
 
28
28
  subject do
29
29
  FakeElement.new(document, document.root, [], state)
30
30
  end
31
31
 
32
- describe "#bounding_box" do
33
- it "determines the bounding box using the translated commands" do
32
+ describe '#bounding_box' do
33
+ it 'determines the bounding box using the translated commands' do
34
34
  expect(subject.bounding_box).to eq [10, 590, 30, 570]
35
35
  end
36
36
  end
37
37
 
38
- describe "#apply_commands" do
39
- it "applies the commands to the call stack" do
38
+ describe '#apply_commands' do
39
+ it 'applies the commands to the call stack' do
40
40
  subject.apply_commands
41
41
 
42
42
  expect(subject.base_calls).to eq [
43
- ["move_to", [[10.0, 590.0]], {}, []],
44
- ["line_to", [[20.0, 580.0]], {}, []],
45
- ["curve_to", [[30.0, 570.0]], {bounds: [[25.0, 580.0], [25.0, 575.0]]}, []],
46
- ["close_path", [], {}, []]
43
+ ['move_to', [[10.0, 590.0]], {}, []],
44
+ ['line_to', [[20.0, 580.0]], {}, []],
45
+ ['curve_to', [[30.0, 570.0]], { bounds: [[25.0, 580.0], [25.0, 575.0]] }, []],
46
+ ['close_path', [], {}, []]
47
47
  ]
48
48
  end
49
49
  end
50
50
 
51
- describe "#apply_markers" do
52
- let(:marker) { instance_double(Prawn::SVG::Elements::Marker, name: "marker") }
51
+ describe '#apply_markers' do
52
+ let(:marker) { instance_double(Prawn::SVG::Elements::Marker, name: 'marker') }
53
53
 
54
54
  before do
55
- document.elements_by_id["triangle"] = marker
55
+ document.elements_by_id['triangle'] = marker
56
56
  end
57
57
 
58
- context "with marker-start attribute specified" do
58
+ context 'with marker-start attribute specified' do
59
59
  before do
60
- subject.properties.marker_start = "url(#triangle)"
60
+ subject.properties.marker_start = 'url(#triangle)'
61
61
  end
62
62
 
63
- it "calls apply_marker on the marker" do
63
+ it 'calls apply_marker on the marker' do
64
64
  expect(marker).to receive(:apply_marker).with(subject, point: [10, 10], angle: 45)
65
65
  subject.apply_markers
66
66
  end
67
67
  end
68
68
 
69
- context "with marker-mid attribute specified" do
69
+ context 'with marker-mid attribute specified' do
70
70
  before do
71
- subject.properties.marker_mid = "url(#triangle)"
71
+ subject.properties.marker_mid = 'url(#triangle)'
72
72
  end
73
73
 
74
- it "calls apply_marker on the marker" do
74
+ it 'calls apply_marker on the marker' do
75
75
  expect(marker).to receive(:apply_marker).with(subject, point: [20, 20], angle: 45)
76
76
  expect(marker).to receive(:apply_marker).with(subject, point: [30, 30], angle: -45)
77
77
  subject.apply_markers
78
78
  end
79
79
  end
80
80
 
81
- context "with marker-end attribute specified" do
81
+ context 'with marker-end attribute specified' do
82
82
  before do
83
- subject.properties.marker_end = "url(#triangle)"
83
+ subject.properties.marker_end = 'url(#triangle)'
84
84
  end
85
85
 
86
- it "calls apply_marker on the marker" do
86
+ it 'calls apply_marker on the marker' do
87
87
  expect(marker).to receive(:apply_marker).with(subject, point: [10, 10], angle: -45)
88
88
  subject.apply_markers
89
89
  end