prawn-svg 0.34.2 → 0.35.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +19 -0
- data/.github/workflows/test.yml +14 -27
- data/.gitignore +0 -1
- data/.rubocop.yml +86 -0
- data/.rubocop_todo.yml +51 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +81 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/prawn/svg/attributes/clip_path.rb +3 -3
- data/lib/prawn/svg/attributes/opacity.rb +3 -3
- data/lib/prawn/svg/attributes/stroke.rb +9 -9
- data/lib/prawn/svg/attributes/transform.rb +2 -2
- data/lib/prawn/svg/attributes.rb +1 -1
- data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +17 -15
- data/lib/prawn/svg/calculators/aspect_ratio.rb +16 -14
- data/lib/prawn/svg/calculators/document_sizing.rb +9 -10
- data/lib/prawn/svg/calculators/pixels.rb +8 -5
- data/lib/prawn/svg/color.rb +209 -212
- data/lib/prawn/svg/css/font_family_parser.rb +2 -2
- data/lib/prawn/svg/css/selector_parser.rb +39 -35
- data/lib/prawn/svg/css/stylesheets.rb +24 -24
- data/lib/prawn/svg/css/values_parser.rb +68 -0
- data/lib/prawn/svg/document.rb +6 -5
- data/lib/prawn/svg/elements/base.rb +29 -34
- data/lib/prawn/svg/elements/circle.rb +4 -4
- data/lib/prawn/svg/elements/clip_path.rb +0 -1
- data/lib/prawn/svg/elements/depth_first_base.rb +6 -6
- data/lib/prawn/svg/elements/ellipse.rb +3 -4
- data/lib/prawn/svg/elements/gradient.rb +49 -51
- data/lib/prawn/svg/elements/image.rb +5 -5
- data/lib/prawn/svg/elements/marker.rb +5 -5
- data/lib/prawn/svg/elements/path.rb +46 -47
- data/lib/prawn/svg/elements/polygon.rb +1 -1
- data/lib/prawn/svg/elements/polyline.rb +2 -2
- data/lib/prawn/svg/elements/rect.rb +3 -3
- data/lib/prawn/svg/elements/text.rb +1 -1
- data/lib/prawn/svg/elements/text_component.rb +22 -22
- data/lib/prawn/svg/elements/use.rb +3 -7
- data/lib/prawn/svg/elements/viewport.rb +1 -3
- data/lib/prawn/svg/elements.rb +30 -29
- data/lib/prawn/svg/extension.rb +2 -1
- data/lib/prawn/svg/font.rb +7 -7
- data/lib/prawn/svg/font_registry.rb +13 -13
- data/lib/prawn/svg/gradients.rb +3 -2
- data/lib/prawn/svg/interface.rb +4 -3
- data/lib/prawn/svg/loaders/data.rb +2 -2
- data/lib/prawn/svg/loaders/file.rb +12 -14
- data/lib/prawn/svg/loaders/web.rb +4 -8
- data/lib/prawn/svg/pathable.rb +41 -37
- data/lib/prawn/svg/properties.rb +34 -33
- data/lib/prawn/svg/renderer.rb +7 -7
- data/lib/prawn/svg/state.rb +1 -1
- data/lib/prawn/svg/transform_parser.rb +5 -5
- data/lib/prawn/svg/ttf.rb +21 -17
- data/lib/prawn/svg/url_loader.rb +1 -1
- data/lib/prawn/svg/version.rb +1 -1
- data/lib/prawn-svg.rb +1 -0
- data/prawn-svg.gemspec +5 -7
- data/spec/integration_spec.rb +77 -70
- data/spec/prawn/svg/attributes/opacity_spec.rb +11 -15
- data/spec/prawn/svg/attributes/transform_spec.rb +6 -6
- data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +50 -50
- data/spec/prawn/svg/calculators/document_sizing_spec.rb +35 -35
- data/spec/prawn/svg/calculators/pixels_spec.rb +31 -30
- data/spec/prawn/svg/color_spec.rb +31 -31
- data/spec/prawn/svg/css/font_family_parser_spec.rb +12 -12
- data/spec/prawn/svg/css/selector_parser_spec.rb +21 -21
- data/spec/prawn/svg/css/stylesheets_spec.rb +51 -45
- data/spec/prawn/svg/css/values_parser_spec.rb +16 -0
- data/spec/prawn/svg/document_spec.rb +15 -14
- data/spec/prawn/svg/elements/base_spec.rb +39 -34
- data/spec/prawn/svg/elements/gradient_spec.rb +39 -39
- data/spec/prawn/svg/elements/line_spec.rb +22 -22
- data/spec/prawn/svg/elements/marker_spec.rb +36 -40
- data/spec/prawn/svg/elements/path_spec.rb +134 -110
- data/spec/prawn/svg/elements/polygon_spec.rb +18 -18
- data/spec/prawn/svg/elements/polyline_spec.rb +16 -16
- data/spec/prawn/svg/elements/text_spec.rb +149 -127
- data/spec/prawn/svg/font_registry_spec.rb +34 -34
- data/spec/prawn/svg/font_spec.rb +4 -4
- data/spec/prawn/svg/interface_spec.rb +47 -39
- data/spec/prawn/svg/loaders/data_spec.rb +21 -21
- data/spec/prawn/svg/loaders/file_spec.rb +43 -40
- data/spec/prawn/svg/loaders/web_spec.rb +15 -15
- data/spec/prawn/svg/pathable_spec.rb +21 -21
- data/spec/prawn/svg/properties_spec.rb +51 -51
- data/spec/prawn/svg/transform_parser_spec.rb +12 -12
- data/spec/prawn/svg/ttf_spec.rb +5 -5
- data/spec/prawn/svg/url_loader_spec.rb +25 -23
- data/spec/spec_helper.rb +4 -4
- metadata +21 -146
@@ -3,27 +3,27 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe Prawn::SVG::Properties do
|
4
4
|
subject { Prawn::SVG::Properties.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe '#load_default_stylesheet' do
|
7
|
+
it 'loads in the defaults and returns self' do
|
8
8
|
expect(subject.load_default_stylesheet).to eq subject
|
9
9
|
expect(subject.font_family).to eq 'sans-serif'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
13
|
+
describe '#set' do
|
14
|
+
it 'sets a property' do
|
15
15
|
result = subject.set('color', 'red')
|
16
16
|
expect(result).to be
|
17
17
|
expect(subject.color).to eq 'red'
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'handles property names that are not lower case' do
|
21
21
|
result = subject.set('COLor', 'red')
|
22
22
|
expect(result).to be
|
23
23
|
expect(subject.color).to eq 'red'
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'right-cases and strips keywords' do
|
27
27
|
subject.set('stroke-linecap', ' Round ')
|
28
28
|
expect(subject.stroke_linecap).to eq 'round'
|
29
29
|
end
|
@@ -39,19 +39,19 @@ RSpec.describe Prawn::SVG::Properties do
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
44
|
-
subject.load_hash(
|
42
|
+
describe '#load_hash' do
|
43
|
+
it 'uses #set to load in a hash of properties' do
|
44
|
+
subject.load_hash('stroke' => 'blue', 'fill' => 'green', 'stroke-linecap' => 'Round')
|
45
45
|
expect(subject.stroke).to eq 'blue'
|
46
46
|
expect(subject.fill).to eq 'green'
|
47
47
|
expect(subject.stroke_linecap).to eq 'round'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
51
|
+
describe '#compute_properties' do
|
52
52
|
let(:other) { Prawn::SVG::Properties.new }
|
53
53
|
|
54
|
-
it
|
54
|
+
it 'auto-inherits inheritable properties when the property is not supplied' do
|
55
55
|
subject.set('color', 'green')
|
56
56
|
subject.compute_properties(other)
|
57
57
|
expect(subject.color).to eq 'green'
|
@@ -63,122 +63,122 @@ RSpec.describe Prawn::SVG::Properties do
|
|
63
63
|
expect(subject.display).to eq 'inline'
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'inherits non-inheritable properties when specifically asked to' do
|
67
67
|
subject.set('display', 'none')
|
68
68
|
other.set('display', 'inherit')
|
69
69
|
subject.compute_properties(other)
|
70
70
|
expect(subject.display).to eq 'none'
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'uses the new property value' do
|
74
74
|
subject.set('color', 'green')
|
75
75
|
other.set('color', 'red')
|
76
76
|
subject.compute_properties(other)
|
77
77
|
expect(subject.color).to eq 'red'
|
78
78
|
end
|
79
79
|
|
80
|
-
describe
|
80
|
+
describe 'font size' do
|
81
81
|
before do
|
82
|
-
subject.font_size =
|
82
|
+
subject.font_size = '15'
|
83
83
|
other.font_size = font_size
|
84
84
|
end
|
85
85
|
|
86
|
-
context
|
87
|
-
let(:font_size) {
|
86
|
+
context 'when given a % as a font-size' do
|
87
|
+
let(:font_size) { '120%' }
|
88
88
|
|
89
|
-
it
|
89
|
+
it 'calculates the new font size' do
|
90
90
|
subject.compute_properties(other)
|
91
|
-
expect(subject.font_size).to eq
|
91
|
+
expect(subject.font_size).to eq '18.0'
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
context "when given 'larger' as a font-size" do
|
96
|
-
let(:font_size) {
|
96
|
+
let(:font_size) { 'larger' }
|
97
97
|
|
98
|
-
it
|
98
|
+
it 'calculates the new font size' do
|
99
99
|
subject.compute_properties(other)
|
100
|
-
expect(subject.font_size).to eq
|
100
|
+
expect(subject.font_size).to eq '19.0'
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
context "when given 'smaller' as a font-size" do
|
105
|
-
let(:font_size) {
|
105
|
+
let(:font_size) { 'smaller' }
|
106
106
|
|
107
|
-
it
|
107
|
+
it 'calculates the new font size' do
|
108
108
|
subject.compute_properties(other)
|
109
|
-
expect(subject.font_size).to eq
|
109
|
+
expect(subject.font_size).to eq '11.0'
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
context "when given a value in 'em' as a font-size" do
|
114
|
-
let(:font_size) {
|
114
|
+
let(:font_size) { '2.5em' }
|
115
115
|
|
116
|
-
it
|
116
|
+
it 'calculates the new font size' do
|
117
117
|
subject.compute_properties(other)
|
118
|
-
expect(subject.font_size).to eq
|
118
|
+
expect(subject.font_size).to eq '37.5'
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
context "when given a value in 'rem' as a font-size" do
|
123
|
-
let(:font_size) {
|
123
|
+
let(:font_size) { '2.5rem' }
|
124
124
|
|
125
|
-
it
|
125
|
+
it 'calculates the new font size' do
|
126
126
|
subject.compute_properties(other)
|
127
|
-
expect(subject.font_size).to eq
|
127
|
+
expect(subject.font_size).to eq '40.0'
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
context "when given a value in 'px' as a font-size" do
|
132
|
-
let(:font_size) {
|
132
|
+
let(:font_size) { '19.5px' }
|
133
133
|
|
134
|
-
it
|
134
|
+
it 'uses the font size specified' do
|
135
135
|
subject.compute_properties(other)
|
136
|
-
expect(subject.font_size).to eq
|
136
|
+
expect(subject.font_size).to eq '19.5'
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
140
|
context "when given a value in 'pt' as a font-size" do
|
141
|
-
let(:font_size) {
|
141
|
+
let(:font_size) { '19.5pt' }
|
142
142
|
|
143
|
-
it
|
143
|
+
it 'uses the font size specified' do
|
144
144
|
subject.compute_properties(other)
|
145
|
-
expect(subject.font_size).to eq
|
145
|
+
expect(subject.font_size).to eq '19.5'
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
context
|
150
|
-
let(:font_size) {
|
149
|
+
context 'when given a value without units as a font-size' do
|
150
|
+
let(:font_size) { '19.5' }
|
151
151
|
|
152
|
-
it
|
152
|
+
it 'uses the font size specified' do
|
153
153
|
subject.compute_properties(other)
|
154
|
-
expect(subject.font_size).to eq
|
154
|
+
expect(subject.font_size).to eq '19.5'
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
158
|
context "when given the keyword 'inherit' as a font-size" do
|
159
|
-
let(:font_size) {
|
159
|
+
let(:font_size) { 'inherit' }
|
160
160
|
|
161
|
-
it
|
161
|
+
it 'uses the font size specified by the parent' do
|
162
162
|
subject.compute_properties(other)
|
163
|
-
expect(subject.font_size).to eq
|
163
|
+
expect(subject.font_size).to eq '15'
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
describe
|
170
|
-
context
|
171
|
-
before { subject.font_size =
|
169
|
+
describe '#numerical_font_size' do
|
170
|
+
context 'when the font size is a number' do
|
171
|
+
before { subject.font_size = '16.5' }
|
172
172
|
|
173
|
-
it
|
173
|
+
it 'returns the number as a float' do
|
174
174
|
expect(subject.numerical_font_size).to eq 16.5
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
context
|
179
|
-
before { subject.font_size =
|
178
|
+
context 'when the font size is one of the keyword size specifiers' do
|
179
|
+
before { subject.font_size = 'x-large' }
|
180
180
|
|
181
|
-
it
|
181
|
+
it 'returns the font size number corresponding with the keyword' do
|
182
182
|
expect(subject.numerical_font_size).to eq 24
|
183
183
|
end
|
184
184
|
end
|
@@ -28,27 +28,27 @@ RSpec.describe Prawn::SVG::TransformParser do
|
|
28
28
|
|
29
29
|
subject { Test.new.parse_transform_attribute(transform) }
|
30
30
|
|
31
|
-
context
|
31
|
+
context 'with no transform' do
|
32
32
|
let(:transform) { '' }
|
33
33
|
it { is_expected.to eq [1, 0, 0, 1, 0, 0] }
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
36
|
+
context 'with translate' do
|
37
37
|
let(:transform) { 'translate(10 20)' }
|
38
38
|
it { is_expected.to eq [1, 0, 0, 1, 10, -20] }
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
41
|
+
context 'with single argument translate' do
|
42
42
|
let(:transform) { 'translate(10)' }
|
43
43
|
it { is_expected.to eq [1, 0, 0, 1, 10, 0] }
|
44
44
|
end
|
45
45
|
|
46
|
-
context
|
46
|
+
context 'with translateX' do
|
47
47
|
let(:transform) { 'translateX(10)' }
|
48
48
|
it { is_expected.to eq [1, 0, 0, 1, 10, 0] }
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
51
|
+
context 'with translateY' do
|
52
52
|
let(:transform) { 'translateY(10)' }
|
53
53
|
it { is_expected.to eq [1, 0, 0, 1, 0, -10] }
|
54
54
|
end
|
@@ -57,37 +57,37 @@ RSpec.describe Prawn::SVG::TransformParser do
|
|
57
57
|
let(:cos30) { Math.cos(30 * Math::PI / 180.0) }
|
58
58
|
let(:tan30) { Math.tan(30 * Math::PI / 180.0) }
|
59
59
|
|
60
|
-
context
|
60
|
+
context 'with single argument rotate' do
|
61
61
|
let(:transform) { 'rotate(30)' }
|
62
62
|
it { is_expected.to eq [cos30, -sin30, sin30, cos30, 0, 0] }
|
63
63
|
end
|
64
64
|
|
65
|
-
context
|
65
|
+
context 'with triple argument rotate' do
|
66
66
|
let(:transform) { 'rotate(30 100 200)' }
|
67
67
|
it { is_expected.to eq [cos30, -sin30, sin30, cos30, 113.39745962155611, 23.205080756887753] }
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
70
|
+
context 'with scale' do
|
71
71
|
let(:transform) { 'scale(1.5)' }
|
72
72
|
it { is_expected.to eq [1.5, 0, 0, 1.5, 0, 0] }
|
73
73
|
end
|
74
74
|
|
75
|
-
context
|
75
|
+
context 'with skewX' do
|
76
76
|
let(:transform) { 'skewX(30)' }
|
77
77
|
it { is_expected.to eq [1, 0, -tan30, 1, 0, 0] }
|
78
78
|
end
|
79
79
|
|
80
|
-
context
|
80
|
+
context 'with skewY' do
|
81
81
|
let(:transform) { 'skewY(30)' }
|
82
82
|
it { is_expected.to eq [1, -tan30, 0, 1, 0, 0] }
|
83
83
|
end
|
84
84
|
|
85
|
-
context
|
85
|
+
context 'with matrix' do
|
86
86
|
let(:transform) { 'matrix(1 2 3 4 5 6)' }
|
87
87
|
it { is_expected.to eq [1, -2, -3, 4, 5, -6] }
|
88
88
|
end
|
89
89
|
|
90
|
-
context
|
90
|
+
context 'with multiple' do
|
91
91
|
let(:transform) { 'scale(2) translate(7) scale(3)' }
|
92
92
|
it { is_expected.to eq [6, 0, 0, 6, 14, 0] }
|
93
93
|
end
|
data/spec/prawn/svg/ttf_spec.rb
CHANGED
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe Prawn::SVG::TTF do
|
4
4
|
subject { Prawn::SVG::TTF.new(filename) }
|
5
5
|
|
6
|
-
context
|
6
|
+
context 'with a truetype font' do
|
7
7
|
let(:filename) { "#{File.dirname(__FILE__)}/../../sample_ttf/OpenSans-SemiboldItalic.ttf" }
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'gets the English family and subfamily from the font file' do
|
10
10
|
expect(subject.family).to eq 'Open Sans'
|
11
11
|
expect(subject.subfamily).to eq 'Semibold Italic'
|
12
12
|
end
|
@@ -15,16 +15,16 @@ RSpec.describe Prawn::SVG::TTF do
|
|
15
15
|
context "with a file that isn't a TTF" do
|
16
16
|
let(:filename) { __FILE__ }
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'has a nil family and subfamily' do
|
19
19
|
expect(subject.family).to be nil
|
20
20
|
expect(subject.subfamily).to be nil
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context "with a file that doesn't exist" do
|
25
|
-
let(:filename) {
|
25
|
+
let(:filename) { 'does_not_exist' }
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'has a nil family and subfamily' do
|
28
28
|
expect(subject.family).to be nil
|
29
29
|
expect(subject.subfamily).to be nil
|
30
30
|
end
|
@@ -3,17 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe Prawn::SVG::UrlLoader do
|
4
4
|
let(:enable_cache) { true }
|
5
5
|
let(:enable_web) { true }
|
6
|
-
let(:enable_file) {
|
7
|
-
let(:loader)
|
6
|
+
let(:enable_file) { '.' }
|
7
|
+
let(:loader) do
|
8
|
+
Prawn::SVG::UrlLoader.new(enable_cache: enable_cache, enable_web: enable_web, enable_file_with_root: enable_file)
|
9
|
+
end
|
8
10
|
|
9
|
-
describe
|
10
|
-
it
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'sets options' do
|
11
13
|
expect(loader.enable_cache).to be true
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
describe
|
16
|
-
let(:url) {
|
17
|
+
describe '#load' do
|
18
|
+
let(:url) { 'http://hello/there' }
|
17
19
|
let(:data_loader) { instance_double(Prawn::SVG::Loaders::Data) }
|
18
20
|
let(:web_loader) { instance_double(Prawn::SVG::Loaders::Web) }
|
19
21
|
let(:file_loader) { instance_double(Prawn::SVG::Loaders::File) }
|
@@ -26,29 +28,29 @@ describe Prawn::SVG::UrlLoader do
|
|
26
28
|
|
27
29
|
subject { loader.load(url) }
|
28
30
|
|
29
|
-
it
|
30
|
-
expect(data_loader).to receive(:from_url).with(url).and_return(
|
31
|
+
it 'calls the Data loader and returns its output if successful' do
|
32
|
+
expect(data_loader).to receive(:from_url).with(url).and_return('data')
|
31
33
|
expect(web_loader).not_to receive(:from_url)
|
32
34
|
|
33
35
|
expect(subject).to eq 'data'
|
34
36
|
end
|
35
37
|
|
36
|
-
it
|
38
|
+
it 'calls the Web loader if the Data loader returns nothing, and returns its output if successful' do
|
37
39
|
expect(data_loader).to receive(:from_url).with(url)
|
38
|
-
expect(web_loader).to receive(:from_url).with(url).and_return(
|
40
|
+
expect(web_loader).to receive(:from_url).with(url).and_return('data')
|
39
41
|
|
40
42
|
expect(subject).to eq 'data'
|
41
43
|
end
|
42
44
|
|
43
|
-
it
|
45
|
+
it 'calls the File loader if the Data and Web loaders return nothing, and returns its output if successful' do
|
44
46
|
expect(data_loader).to receive(:from_url).with(url)
|
45
47
|
expect(web_loader).to receive(:from_url).with(url)
|
46
|
-
expect(file_loader).to receive(:from_url).with(url).and_return(
|
48
|
+
expect(file_loader).to receive(:from_url).with(url).and_return('data')
|
47
49
|
|
48
50
|
expect(subject).to eq 'data'
|
49
51
|
end
|
50
52
|
|
51
|
-
it
|
53
|
+
it 'raises if none of the loaders return any data' do
|
52
54
|
expect(data_loader).to receive(:from_url).with(url)
|
53
55
|
expect(web_loader).to receive(:from_url).with(url)
|
54
56
|
expect(file_loader).to receive(:from_url).with(url)
|
@@ -56,28 +58,28 @@ describe Prawn::SVG::UrlLoader do
|
|
56
58
|
expect { subject }.to raise_error(Prawn::SVG::UrlLoader::Error, /No handler available/)
|
57
59
|
end
|
58
60
|
|
59
|
-
context
|
60
|
-
it
|
61
|
-
expect(data_loader).to receive(:from_url).with(url).and_return(
|
61
|
+
context 'when caching is enabled' do
|
62
|
+
it 'caches the result' do
|
63
|
+
expect(data_loader).to receive(:from_url).with(url).and_return('data')
|
62
64
|
expect(subject).to eq 'data'
|
63
65
|
expect(loader.retrieve_from_cache(url)).to eq 'data'
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
|
-
context
|
69
|
+
context 'when caching is disabled' do
|
68
70
|
let(:enable_cache) { false }
|
69
71
|
|
70
|
-
it
|
71
|
-
expect(data_loader).to receive(:from_url).with(url).and_return(
|
72
|
+
it 'does not cache the result' do
|
73
|
+
expect(data_loader).to receive(:from_url).with(url).and_return('data')
|
72
74
|
expect(subject).to eq 'data'
|
73
75
|
expect(loader.retrieve_from_cache(url)).to be nil
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
context
|
79
|
+
context 'when the cache is populated' do
|
78
80
|
before { loader.add_to_cache(url, 'data') }
|
79
81
|
|
80
|
-
it
|
82
|
+
it 'returns the cached value without calling a loader' do
|
81
83
|
expect(data_loader).not_to receive(:from_url)
|
82
84
|
expect(web_loader).not_to receive(:from_url)
|
83
85
|
|
@@ -85,7 +87,7 @@ describe Prawn::SVG::UrlLoader do
|
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
|
-
context
|
90
|
+
context 'when web requests are disabled' do
|
89
91
|
let(:enable_web) { false }
|
90
92
|
|
91
93
|
it "doesn't use the web loader" do
|
@@ -97,7 +99,7 @@ describe Prawn::SVG::UrlLoader do
|
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
|
-
context
|
102
|
+
context 'when file requests are disabled' do
|
101
103
|
let(:enable_file) { nil }
|
102
104
|
|
103
105
|
it "doesn't use the file loader" do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ Bundler.require(:default, :development)
|
|
3
3
|
|
4
4
|
# Requires supporting files with custom matchers and macros, etc,
|
5
5
|
# in ./support/ and its subdirectories.
|
6
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
6
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
7
7
|
|
8
8
|
module Support
|
9
9
|
def flatten_calls(_calls)
|
@@ -49,15 +49,15 @@ RSpec.configure do |config|
|
|
49
49
|
|
50
50
|
config.after(:suite) do
|
51
51
|
# print out the PDFs that have changed
|
52
|
-
changed = $hashes.
|
52
|
+
changed = $hashes.reject do |file, hash|
|
53
53
|
new_hash = Digest::MD5.file(file).hexdigest
|
54
|
-
new_hash
|
54
|
+
new_hash == hash
|
55
55
|
end
|
56
56
|
|
57
57
|
if changed.any?
|
58
58
|
puts "\nThese PDFs have changed since the last test run:"
|
59
59
|
cwd = "#{Dir.pwd}/"
|
60
|
-
changed.
|
60
|
+
changed.each_key { |file| puts " #{file.sub(cwd, '')}" }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|