@@ -86,9 +86,7 @@ def transform(doc)
86
86
with ( 'missing.svg' ) .
87
87
and_raise ( InlineSvg ::AssetFile ::FileNotFound . new )
88
88
89
- fallback_file = <<-SVG
90
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
91
- SVG
89
+ fallback_file = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
92
90
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'fallback.svg' ) . and_return ( fallback_file )
93
91
expect ( helper . send ( helper_method , 'missing.svg' , fallback : 'fallback.svg' ) ) . to eq fallback_file
94
92
end
@@ -99,74 +97,52 @@ def transform(doc)
99
97
100
98
context "and no options" do
101
99
it "returns a html safe version of the file's contents" do
102
- example_file = <<-SVG
103
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
104
- SVG
100
+ example_file = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
105
101
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( example_file )
106
102
expect ( helper . send ( helper_method , 'some-file' ) ) . to eq example_file
107
103
end
108
104
end
109
105
110
106
context "and the 'title' option" do
111
107
it "adds the title node to the SVG output" do
112
- input_svg = <<-SVG
113
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>
114
- SVG
115
- expected_output = <<-SVG
116
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title></svg>
117
- SVG
108
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>'
109
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title></svg>'
118
110
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
119
111
expect ( helper . send ( helper_method , 'some-file' , title : 'A title' ) ) . to eq expected_output
120
112
end
121
113
end
122
114
123
115
context "and the 'desc' option" do
124
116
it "adds the description node to the SVG output" do
125
- input_svg = <<-SVG
126
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>
127
- SVG
128
- expected_output = <<-SVG
129
- <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><desc>A description</desc></svg>
130
- SVG
117
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>'
118
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><desc>A description</desc></svg>'
131
119
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
132
120
expect ( helper . send ( helper_method , 'some-file' , desc : 'A description' ) ) . to eq expected_output
133
121
end
134
122
end
135
123
136
124
context "and the 'nocomment' option" do
137
125
it "strips comments and other unknown/unsafe nodes from the output" do
138
- input_svg = <<-SVG
139
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
140
- SVG
141
- expected_output = <<-SVG
142
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
143
- SVG
126
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
127
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>'
144
128
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
145
129
expect ( helper . send ( helper_method , 'some-file' , nocomment : true ) ) . to eq expected_output
146
130
end
147
131
end
148
132
149
133
context "and the 'aria_hidden' option" do
150
134
it "sets 'aria-hidden=true' in the output" do
151
- input_svg = <<-SVG
152
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
153
- SVG
154
- expected_output = <<-SVG
155
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>
156
- SVG
135
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>'
136
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>'
157
137
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
158
138
expect ( helper . send ( helper_method , 'some-file' , aria_hidden : true ) ) . to eq expected_output
159
139
end
160
140
end
161
141
162
142
context "and all options" do
163
143
it "applies all expected transformations to the output" do
164
- input_svg = <<-SVG
165
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
166
- SVG
167
- expected_output = <<-SVG
168
- <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><title>A title</title><desc>A description</desc></svg>
169
- SVG
144
+ input_svg = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
145
+ expected_output = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><title>A title</title><desc>A description</desc></svg>'
170
146
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
171
147
expect ( helper . send ( helper_method , 'some-file' , title : 'A title' , desc : 'A description' , nocomment : true ) ) . to eq expected_output
172
148
end
@@ -184,12 +160,8 @@ def transform(doc)
184
160
end
185
161
186
162
it "applies custm transformations to the output" do
187
- input_svg = <<-SVG
188
- <svg></svg>
189
- SVG
190
- expected_output = <<-SVG
191
- <svg custom="some value"></svg>
192
- SVG
163
+ input_svg = '<svg></svg>'
164
+ expected_output = '<svg custom="some value"></svg>'
193
165
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
194
166
expect ( helper . send ( helper_method , 'some-file' , custom : 'some value' ) ) . to eq expected_output
195
167
end
@@ -212,7 +184,7 @@ def transform(doc)
212
184
213
185
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
214
186
215
- expect ( helper . send ( helper_method , 'some-file' ) ) . to eq "<svg custom=\" default value\" ></svg>\n "
187
+ expect ( helper . send ( helper_method , 'some-file' ) ) . to eq "<svg custom=\" default value\" ></svg>"
216
188
end
217
189
end
218
190
@@ -222,7 +194,7 @@ def transform(doc)
222
194
223
195
allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
224
196
225
- expect ( helper . send ( helper_method , 'some-file' , custom : 'some value' ) ) . to eq "<svg custom=\" some value\" ></svg>\n "
197
+ expect ( helper . send ( helper_method , 'some-file' , custom : 'some value' ) ) . to eq "<svg custom=\" some value\" ></svg>"
226
198
end
227
199
end
228
200
end
@@ -251,17 +223,27 @@ def transform(doc)
251
223
expect ( InlineSvg ::IOResource ) . to receive ( :=== ) . with ( io_object ) . and_return ( true )
252
224
expect ( InlineSvg ::IOResource ) . to receive ( :read ) . with ( io_object ) . and_return ( "<svg><!-- Test IO --></svg>" )
253
225
output = helper . send ( helper_method , io_object )
254
- expect ( output ) . to eq "<svg><!-- Test IO --></svg>\n "
226
+ expect ( output ) . to eq "<svg><!-- Test IO --></svg>"
255
227
expect ( output ) . to be_html_safe
256
228
end
257
229
258
230
it 'return valid svg for file' do
259
231
output = helper . send ( helper_method , File . new ( file_path ) )
260
- expect ( output ) . to eq "<svg xmlns=\" http://www.w3.org/2000/svg\" xml:lang=\" en\" role=\" presentation\" ><!-- This is a test comment --></svg>\n "
232
+ expect ( output ) . to eq "<svg xmlns=\" http://www.w3.org/2000/svg\" xml:lang=\" en\" role=\" presentation\" ><!-- This is a test comment --></svg>"
261
233
expect ( output ) . to be_html_safe
262
234
end
263
235
264
236
end
237
+
238
+ context 'default output' do
239
+ it "returns an SVG tag without any pre or post whitespace characters" do
240
+ input_svg = '<svg></svg>'
241
+
242
+ allow ( InlineSvg ::AssetFile ) . to receive ( :named ) . with ( 'some-file' ) . and_return ( input_svg )
243
+
244
+ expect ( helper . send ( helper_method , 'some-file' ) ) . to eq "<svg></svg>"
245
+ end
246
+ end
265
247
end
266
248
267
249
describe '#inline_svg' do
0 commit comments