nori 2.7.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,650 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Nori do
4
-
5
- Nori::PARSERS.each do |parser, class_name|
6
- context "using the :#{parser} parser" do
7
-
8
- let(:parser) { parser }
9
-
10
- it "should work with unnormalized characters" do
11
- xml = '<root>&amp;</root>'
12
- expect(parse(xml)).to eq({ 'root' => "&" })
13
- end
14
-
15
- it "should transform a simple tag with content" do
16
- xml = "<tag>This is the contents</tag>"
17
- expect(parse(xml)).to eq({ 'tag' => 'This is the contents' })
18
- end
19
-
20
- it "should work with cdata tags" do
21
- xml = <<-END
22
- <tag>
23
- <![CDATA[
24
- text inside cdata &lt; test
25
- ]]>
26
- </tag>
27
- END
28
- expect(parse(xml)["tag"].strip).to eq("text inside cdata &lt; test")
29
- end
30
-
31
- it "should scrub bad characters" do
32
- xml = "<tag>a\xfbc</tag>".force_encoding('UTF-8')
33
- expect(parse(xml)["tag"]).to eq("a\uFFFDc")
34
- end
35
-
36
- it "should transform a simple tag with attributes" do
37
- xml = "<tag attr1='1' attr2='2'></tag>"
38
- hash = { 'tag' => { '@attr1' => '1', '@attr2' => '2' } }
39
- expect(parse(xml)).to eq(hash)
40
- end
41
-
42
- it "should transform repeating siblings into an array" do
43
- xml =<<-XML
44
- <opt>
45
- <user login="grep" fullname="Gary R Epstein" />
46
- <user login="stty" fullname="Simon T Tyson" />
47
- </opt>
48
- XML
49
-
50
- expect(parse(xml)['opt']['user'].class).to eq(Array)
51
-
52
- hash = {
53
- 'opt' => {
54
- 'user' => [{
55
- '@login' => 'grep',
56
- '@fullname' => 'Gary R Epstein'
57
- },{
58
- '@login' => 'stty',
59
- '@fullname' => 'Simon T Tyson'
60
- }]
61
- }
62
- }
63
-
64
- expect(parse(xml)).to eq(hash)
65
- end
66
-
67
- it "should not transform non-repeating siblings into an array" do
68
- xml =<<-XML
69
- <opt>
70
- <user login="grep" fullname="Gary R Epstein" />
71
- </opt>
72
- XML
73
-
74
- expect(parse(xml)['opt']['user'].class).to eq(Hash)
75
-
76
- hash = {
77
- 'opt' => {
78
- 'user' => {
79
- '@login' => 'grep',
80
- '@fullname' => 'Gary R Epstein'
81
- }
82
- }
83
- }
84
-
85
- expect(parse(xml)).to eq(hash)
86
- end
87
-
88
- it "should prefix attributes with an @-sign to avoid problems with overwritten values" do
89
- xml =<<-XML
90
- <multiRef id="id1">
91
- <login>grep</login>
92
- <id>76737</id>
93
- </multiRef>
94
- XML
95
-
96
- expect(parse(xml)["multiRef"]).to eq({ "login" => "grep", "@id" => "id1", "id" => "76737" })
97
- end
98
-
99
- context "without advanced typecasting" do
100
- it "should not transform 'true'" do
101
- hash = parse("<value>true</value>", :advanced_typecasting => false)
102
- expect(hash["value"]).to eq("true")
103
- end
104
-
105
- it "should not transform 'false'" do
106
- hash = parse("<value>false</value>", :advanced_typecasting => false)
107
- expect(hash["value"]).to eq("false")
108
- end
109
-
110
- it "should not transform Strings matching the xs:time format" do
111
- hash = parse("<value>09:33:55Z</value>", :advanced_typecasting => false)
112
- expect(hash["value"]).to eq("09:33:55Z")
113
- end
114
-
115
- it "should not transform Strings matching the xs:date format" do
116
- hash = parse("<value>1955-04-18-05:00</value>", :advanced_typecasting => false)
117
- expect(hash["value"]).to eq("1955-04-18-05:00")
118
- end
119
-
120
- it "should not transform Strings matching the xs:dateTime format" do
121
- hash = parse("<value>1955-04-18T11:22:33-05:00</value>", :advanced_typecasting => false)
122
- expect(hash["value"]).to eq("1955-04-18T11:22:33-05:00")
123
- end
124
- end
125
-
126
- context "with advanced typecasting" do
127
- it "should transform 'true' to TrueClass" do
128
- expect(parse("<value>true</value>")["value"]).to eq(true)
129
- end
130
-
131
- it "should transform 'false' to FalseClass" do
132
- expect(parse("<value>false</value>")["value"]).to eq(false)
133
- end
134
-
135
- it "should transform Strings matching the xs:time format to Time objects" do
136
- expect(parse("<value>09:33:55.7Z</value>")["value"]).to eq(Time.parse("09:33:55.7Z"))
137
- end
138
-
139
- it "should transform Strings matching the xs:time format ahead of utc to Time objects" do
140
- expect(parse("<value>09:33:55+02:00</value>")["value"]).to eq(Time.parse("09:33:55+02:00"))
141
- end
142
-
143
- it "should transform Strings matching the xs:date format to Date objects" do
144
- expect(parse("<value>1955-04-18-05:00</value>")["value"]).to eq(Date.parse("1955-04-18-05:00"))
145
- end
146
-
147
- it "should transform Strings matching the xs:dateTime format ahead of utc to Date objects" do
148
- expect(parse("<value>1955-04-18+02:00</value>")["value"]).to eq(Date.parse("1955-04-18+02:00"))
149
- end
150
-
151
- it "should transform Strings matching the xs:dateTime format to DateTime objects" do
152
- expect(parse("<value>1955-04-18T11:22:33.5Z</value>")["value"]).to eq(
153
- DateTime.parse("1955-04-18T11:22:33.5Z")
154
- )
155
- end
156
-
157
- it "should transform Strings matching the xs:dateTime format ahead of utc to DateTime objects" do
158
- expect(parse("<value>1955-04-18T11:22:33+02:00</value>")["value"]).to eq(
159
- DateTime.parse("1955-04-18T11:22:33+02:00")
160
- )
161
- end
162
-
163
- it "should transform Strings matching the xs:dateTime format with seconds and an offset to DateTime objects" do
164
- expect(parse("<value>2004-04-12T13:20:15.5-05:00</value>")["value"]).to eq(
165
- DateTime.parse("2004-04-12T13:20:15.5-05:00")
166
- )
167
- end
168
-
169
- it "should not transform Strings containing an xs:time String and more" do
170
- expect(parse("<value>09:33:55Z is a time</value>")["value"]).to eq("09:33:55Z is a time")
171
- expect(parse("<value>09:33:55Z_is_a_file_name</value>")["value"]).to eq("09:33:55Z_is_a_file_name")
172
- end
173
-
174
- it "should not transform Strings containing an xs:date String and more" do
175
- expect(parse("<value>1955-04-18-05:00 is a date</value>")["value"]).to eq("1955-04-18-05:00 is a date")
176
- expect(parse("<value>1955-04-18-05:00_is_a_file_name</value>")["value"]).to eq("1955-04-18-05:00_is_a_file_name")
177
- end
178
-
179
- it "should not transform Strings containing an xs:dateTime String and more" do
180
- expect(parse("<value>1955-04-18T11:22:33-05:00 is a dateTime</value>")["value"]).to eq(
181
- "1955-04-18T11:22:33-05:00 is a dateTime"
182
- )
183
- expect(parse("<value>1955-04-18T11:22:33-05:00_is_a_file_name</value>")["value"]).to eq(
184
- "1955-04-18T11:22:33-05:00_is_a_file_name"
185
- )
186
- end
187
-
188
- ["00-00-00", "0000-00-00", "0000-00-00T00:00:00", "0569-23-0141", "DS2001-19-1312654773", "e6:53:01:00:ce:b4:06"].each do |date_string|
189
- it "should not transform a String like '#{date_string}' to date or time" do
190
- expect(parse("<value>#{date_string}</value>")["value"]).to eq(date_string)
191
- end
192
- end
193
- end
194
-
195
- context "Parsing xml with text and attributes" do
196
- before do
197
- xml =<<-XML
198
- <opt>
199
- <user login="grep">Gary R Epstein</user>
200
- <user>Simon T Tyson</user>
201
- </opt>
202
- XML
203
- @data = parse(xml)
204
- end
205
-
206
- it "correctly parse text nodes" do
207
- expect(@data).to eq({
208
- 'opt' => {
209
- 'user' => [
210
- 'Gary R Epstein',
211
- 'Simon T Tyson'
212
- ]
213
- }
214
- })
215
- end
216
-
217
- it "parses attributes for text node if present" do
218
- expect(@data['opt']['user'][0].attributes).to eq({'login' => 'grep'})
219
- end
220
-
221
- it "default attributes to empty hash if not present" do
222
- expect(@data['opt']['user'][1].attributes).to eq({})
223
- end
224
-
225
- it "add 'attributes' accessor methods to parsed instances of String" do
226
- expect(@data['opt']['user'][0]).to respond_to(:attributes)
227
- expect(@data['opt']['user'][0]).to respond_to(:attributes=)
228
- end
229
-
230
- it "not add 'attributes' accessor methods to all instances of String" do
231
- expect("some-string").not_to respond_to(:attributes)
232
- expect("some-string").not_to respond_to(:attributes=)
233
- end
234
- end
235
-
236
- it "should typecast an integer" do
237
- xml = "<tag type='integer'>10</tag>"
238
- expect(parse(xml)['tag']).to eq(10)
239
- end
240
-
241
- it "should typecast a true boolean" do
242
- xml = "<tag type='boolean'>true</tag>"
243
- expect(parse(xml)['tag']).to be(true)
244
- end
245
-
246
- it "should typecast a false boolean" do
247
- ["false"].each do |w|
248
- expect(parse("<tag type='boolean'>#{w}</tag>")['tag']).to be(false)
249
- end
250
- end
251
-
252
- it "should typecast a datetime" do
253
- xml = "<tag type='datetime'>2007-12-31 10:32</tag>"
254
- expect(parse(xml)['tag']).to eq(Time.parse( '2007-12-31 10:32' ).utc)
255
- end
256
-
257
- it "should typecast a date" do
258
- xml = "<tag type='date'>2007-12-31</tag>"
259
- expect(parse(xml)['tag']).to eq(Date.parse('2007-12-31'))
260
- end
261
-
262
- xml_entities = {
263
- "<" => "&lt;",
264
- ">" => "&gt;",
265
- '"' => "&quot;",
266
- "'" => "&apos;",
267
- "&" => "&amp;"
268
- }
269
-
270
- it "should unescape html entities" do
271
- xml_entities.each do |k,v|
272
- xml = "<tag>Some content #{v}</tag>"
273
- expect(parse(xml)['tag']).to match(Regexp.new(k))
274
- end
275
- end
276
-
277
- it "should unescape XML entities in attributes" do
278
- xml_entities.each do |key, value|
279
- xml = "<tag attr='Some content #{value}'></tag>"
280
- expect(parse(xml)['tag']['@attr']).to match(Regexp.new(key))
281
- end
282
- end
283
-
284
- it "should undasherize keys as tags" do
285
- xml = "<tag-1>Stuff</tag-1>"
286
- expect(parse(xml).keys).to include('tag_1')
287
- end
288
-
289
- it "should undasherize keys as attributes" do
290
- xml = "<tag1 attr-1='1'></tag1>"
291
- expect(parse(xml)['tag1'].keys).to include('@attr_1')
292
- end
293
-
294
- it "should undasherize keys as tags and attributes" do
295
- xml = "<tag-1 attr-1='1'></tag-1>"
296
- expect(parse(xml).keys).to include('tag_1')
297
- expect(parse(xml)['tag_1'].keys).to include('@attr_1')
298
- end
299
-
300
- it "should render nested content correctly" do
301
- xml = "<root><tag1>Tag1 Content <em><strong>This is strong</strong></em></tag1></root>"
302
- expect(parse(xml)['root']['tag1']).to eq("Tag1 Content <em><strong>This is strong</strong></em>")
303
- end
304
-
305
- it "should render nested content with text nodes correctly" do
306
- xml = "<root>Tag1 Content<em>Stuff</em> Hi There</root>"
307
- expect(parse(xml)['root']).to eq("Tag1 Content<em>Stuff</em> Hi There")
308
- end
309
-
310
- it "should ignore attributes when a child is a text node" do
311
- xml = "<root attr1='1'>Stuff</root>"
312
- expect(parse(xml)).to eq({ "root" => "Stuff" })
313
- end
314
-
315
- it "should ignore attributes when any child is a text node" do
316
- xml = "<root attr1='1'>Stuff <em>in italics</em></root>"
317
- expect(parse(xml)).to eq({ "root" => "Stuff <em>in italics</em>" })
318
- end
319
-
320
- it "should correctly transform multiple children" do
321
- xml = <<-XML
322
- <user gender='m'>
323
- <age type='integer'>35</age>
324
- <name>Home Simpson</name>
325
- <dob type='date'>1988-01-01</dob>
326
- <joined-at type='datetime'>2000-04-28 23:01</joined-at>
327
- <is-cool type='boolean'>true</is-cool>
328
- </user>
329
- XML
330
-
331
- hash = {
332
- "user" => {
333
- "@gender" => "m",
334
- "age" => 35,
335
- "name" => "Home Simpson",
336
- "dob" => Date.parse('1988-01-01'),
337
- "joined_at" => Time.parse("2000-04-28 23:01"),
338
- "is_cool" => true
339
- }
340
- }
341
-
342
- expect(parse(xml)).to eq(hash)
343
- end
344
-
345
- it "should properly handle nil values (ActiveSupport Compatible)" do
346
- topic_xml = <<-EOT
347
- <topic>
348
- <title></title>
349
- <id type="integer"></id>
350
- <approved type="boolean"></approved>
351
- <written-on type="date"></written-on>
352
- <viewed-at type="datetime"></viewed-at>
353
- <content type="yaml"></content>
354
- <parent-id></parent-id>
355
- <nil_true nil="true"/>
356
- <namespaced xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
357
- </topic>
358
- EOT
359
-
360
- expected_topic_hash = {
361
- 'title' => nil,
362
- 'id' => nil,
363
- 'approved' => nil,
364
- 'written_on' => nil,
365
- 'viewed_at' => nil,
366
- # don't execute arbitary YAML code
367
- 'content' => { "@type" => "yaml" },
368
- 'parent_id' => nil,
369
- 'nil_true' => nil,
370
- 'namespaced' => nil
371
- }
372
- expect(parse(topic_xml)["topic"]).to eq(expected_topic_hash)
373
- end
374
-
375
- it "should handle a single record from xml (ActiveSupport Compatible)" do
376
- topic_xml = <<-EOT
377
- <topic>
378
- <title>The First Topic</title>
379
- <author-name>David</author-name>
380
- <id type="integer">1</id>
381
- <approved type="boolean"> true </approved>
382
- <replies-count type="integer">0</replies-count>
383
- <replies-close-in type="integer">2592000000</replies-close-in>
384
- <written-on type="date">2003-07-16</written-on>
385
- <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
386
- <content type="yaml">--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true</content>
387
- <author-email-address>david@loudthinking.com</author-email-address>
388
- <parent-id></parent-id>
389
- <ad-revenue type="decimal">1.5</ad-revenue>
390
- <optimum-viewing-angle type="float">135</optimum-viewing-angle>
391
- <resident type="symbol">yes</resident>
392
- </topic>
393
- EOT
394
-
395
- expected_topic_hash = {
396
- 'title' => "The First Topic",
397
- 'author_name' => "David",
398
- 'id' => 1,
399
- 'approved' => true,
400
- 'replies_count' => 0,
401
- 'replies_close_in' => 2592000000,
402
- 'written_on' => Date.new(2003, 7, 16),
403
- 'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
404
- # Changed this line where the key is :message. The yaml specifies this as a symbol, and who am I to change what you specify
405
- # The line in ActiveSupport is
406
- # 'content' => { 'message' => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
407
- 'content' => "--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true",
408
- 'author_email_address' => "david@loudthinking.com",
409
- 'parent_id' => nil,
410
- 'ad_revenue' => BigDecimal("1.50"),
411
- 'optimum_viewing_angle' => 135.0,
412
- # don't create symbols from arbitary remote code
413
- 'resident' => "yes"
414
- }
415
-
416
- parse(topic_xml)["topic"].each do |k,v|
417
- expect(v).to eq(expected_topic_hash[k])
418
- end
419
- end
420
-
421
- it "should handle multiple records (ActiveSupport Compatible)" do
422
- topics_xml = <<-EOT
423
- <topics type="array">
424
- <topic>
425
- <title>The First Topic</title>
426
- <author-name>David</author-name>
427
- <id type="integer">1</id>
428
- <approved type="boolean">false</approved>
429
- <replies-count type="integer">0</replies-count>
430
- <replies-close-in type="integer">2592000000</replies-close-in>
431
- <written-on type="date">2003-07-16</written-on>
432
- <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
433
- <content>Have a nice day</content>
434
- <author-email-address>david@loudthinking.com</author-email-address>
435
- <parent-id nil="true"></parent-id>
436
- </topic>
437
- <topic>
438
- <title>The Second Topic</title>
439
- <author-name>Jason</author-name>
440
- <id type="integer">1</id>
441
- <approved type="boolean">false</approved>
442
- <replies-count type="integer">0</replies-count>
443
- <replies-close-in type="integer">2592000000</replies-close-in>
444
- <written-on type="date">2003-07-16</written-on>
445
- <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
446
- <content>Have a nice day</content>
447
- <author-email-address>david@loudthinking.com</author-email-address>
448
- <parent-id></parent-id>
449
- </topic>
450
- </topics>
451
- EOT
452
-
453
- expected_topic_hash = {
454
- 'title' => "The First Topic",
455
- 'author_name' => "David",
456
- 'id' => 1,
457
- 'approved' => false,
458
- 'replies_count' => 0,
459
- 'replies_close_in' => 2592000000,
460
- 'written_on' => Date.new(2003, 7, 16),
461
- 'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
462
- 'content' => "Have a nice day",
463
- 'author_email_address' => "david@loudthinking.com",
464
- 'parent_id' => nil
465
- }
466
-
467
- # puts Nori.parse(topics_xml)['topics'].first.inspect
468
- parse(topics_xml)["topics"].first.each do |k,v|
469
- expect(v).to eq(expected_topic_hash[k])
470
- end
471
- end
472
-
473
- context "with convert_attributes_to set to a custom formula" do
474
- it "alters attributes and values" do
475
- converter = lambda {|key, value| ["#{key}_k", "#{value}_v"] }
476
- xml = <<-XML
477
- <user name="value"><age>21</age></user>
478
- XML
479
-
480
- expect(parse(xml, :convert_attributes_to => converter)).to eq({'user' => {'@name_k' => 'value_v', 'age' => '21'}})
481
- end
482
- end
483
-
484
- it "should handle a single record from_xml with attributes other than type (ActiveSupport Compatible)" do
485
- topic_xml = <<-EOT
486
- <rsp stat="ok">
487
- <photos page="1" pages="1" perpage="100" total="16">
488
- <photo id="175756086" owner="55569174@N00" secret="0279bf37a1" server="76" title="Colored Pencil PhotoBooth Fun" ispublic="1" isfriend="0" isfamily="0"/>
489
- </photos>
490
- </rsp>
491
- EOT
492
-
493
- expected_topic_hash = {
494
- '@id' => "175756086",
495
- '@owner' => "55569174@N00",
496
- '@secret' => "0279bf37a1",
497
- '@server' => "76",
498
- '@title' => "Colored Pencil PhotoBooth Fun",
499
- '@ispublic' => "1",
500
- '@isfriend' => "0",
501
- '@isfamily' => "0",
502
- }
503
-
504
- parse(topic_xml)["rsp"]["photos"]["photo"].each do |k, v|
505
- expect(v).to eq(expected_topic_hash[k])
506
- end
507
- end
508
-
509
- it "should handle an emtpy array (ActiveSupport Compatible)" do
510
- blog_xml = <<-XML
511
- <blog>
512
- <posts type="array"></posts>
513
- </blog>
514
- XML
515
- expected_blog_hash = {"blog" => {"posts" => []}}
516
- expect(parse(blog_xml)).to eq(expected_blog_hash)
517
- end
518
-
519
- it "should handle empty array with whitespace from xml (ActiveSupport Compatible)" do
520
- blog_xml = <<-XML
521
- <blog>
522
- <posts type="array">
523
- </posts>
524
- </blog>
525
- XML
526
- expected_blog_hash = {"blog" => {"posts" => []}}
527
- expect(parse(blog_xml)).to eq(expected_blog_hash)
528
- end
529
-
530
- it "should handle array with one entry from_xml (ActiveSupport Compatible)" do
531
- blog_xml = <<-XML
532
- <blog>
533
- <posts type="array">
534
- <post>a post</post>
535
- </posts>
536
- </blog>
537
- XML
538
- expected_blog_hash = {"blog" => {"posts" => ["a post"]}}
539
- expect(parse(blog_xml)).to eq(expected_blog_hash)
540
- end
541
-
542
- it "should handle array with multiple entries from xml (ActiveSupport Compatible)" do
543
- blog_xml = <<-XML
544
- <blog>
545
- <posts type="array">
546
- <post>a post</post>
547
- <post>another post</post>
548
- </posts>
549
- </blog>
550
- XML
551
- expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}}
552
- expect(parse(blog_xml)).to eq(expected_blog_hash)
553
- end
554
-
555
- it "should handle file types (ActiveSupport Compatible)" do
556
- blog_xml = <<-XML
557
- <blog>
558
- <logo type="file" name="logo.png" content_type="image/png">
559
- </logo>
560
- </blog>
561
- XML
562
- hash = parse(blog_xml)
563
- expect(hash.keys).to include('blog')
564
- expect(hash['blog'].keys).to include('logo')
565
-
566
- file = hash['blog']['logo']
567
- expect(file.original_filename).to eq('logo.png')
568
- expect(file.content_type).to eq('image/png')
569
- end
570
-
571
- it "should handle file from xml with defaults (ActiveSupport Compatible)" do
572
- blog_xml = <<-XML
573
- <blog>
574
- <logo type="file">
575
- </logo>
576
- </blog>
577
- XML
578
- file = parse(blog_xml)['blog']['logo']
579
- expect(file.original_filename).to eq('untitled')
580
- expect(file.content_type).to eq('application/octet-stream')
581
- end
582
-
583
- it "should handle xsd like types from xml (ActiveSupport Compatible)" do
584
- bacon_xml = <<-EOT
585
- <bacon>
586
- <weight type="double">0.5</weight>
587
- <price type="decimal">12.50</price>
588
- <chunky type="boolean"> 1 </chunky>
589
- <expires-at type="dateTime">2007-12-25T12:34:56+0000</expires-at>
590
- <notes type="string"></notes>
591
- <illustration type="base64Binary">YmFiZS5wbmc=</illustration>
592
- </bacon>
593
- EOT
594
-
595
- expected_bacon_hash = {
596
- 'weight' => 0.5,
597
- 'chunky' => true,
598
- 'price' => BigDecimal("12.50"),
599
- 'expires_at' => Time.utc(2007,12,25,12,34,56),
600
- 'notes' => "",
601
- 'illustration' => "babe.png"
602
- }
603
-
604
- expect(parse(bacon_xml)["bacon"]).to eq(expected_bacon_hash)
605
- end
606
-
607
- it "should let type trickle through when unknown (ActiveSupport Compatible)" do
608
- product_xml = <<-EOT
609
- <product>
610
- <weight type="double">0.5</weight>
611
- <image type="ProductImage"><filename>image.gif</filename></image>
612
-
613
- </product>
614
- EOT
615
-
616
- expected_product_hash = {
617
- 'weight' => 0.5,
618
- 'image' => {'@type' => 'ProductImage', 'filename' => 'image.gif' },
619
- }
620
-
621
- expect(parse(product_xml)["product"]).to eq(expected_product_hash)
622
- end
623
-
624
- it "should handle unescaping from xml (ActiveResource Compatible)" do
625
- xml_string = '<person><bare-string>First &amp; Last Name</bare-string><pre-escaped-string>First &amp;amp; Last Name</pre-escaped-string></person>'
626
- expected_hash = {
627
- 'bare_string' => 'First & Last Name',
628
- 'pre_escaped_string' => 'First &amp; Last Name'
629
- }
630
-
631
- expect(parse(xml_string)['person']).to eq(expected_hash)
632
- end
633
-
634
- it "handle an empty xml string" do
635
- expect(parse('')).to eq({})
636
- end
637
-
638
- # As returned in the response body by the unfuddle XML API when creating objects
639
- it "handle an xml string containing a single space" do
640
- expect(parse(' ')).to eq({})
641
- end
642
-
643
- end
644
- end
645
-
646
- def parse(xml, options = {})
647
- defaults = {:parser => parser}
648
- Nori.new(defaults.merge(options)).parse(xml)
649
- end
650
- end
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Nori::StringUtils do
4
-
5
- describe ".snakecase" do
6
- it "lowercases one word CamelCase" do
7
- expect(Nori::StringUtils.snakecase("Merb")).to eq("merb")
8
- end
9
-
10
- it "makes one underscore snakecase two word CamelCase" do
11
- expect(Nori::StringUtils.snakecase("MerbCore")).to eq("merb_core")
12
- end
13
-
14
- it "handles CamelCase with more than 2 words" do
15
- expect(Nori::StringUtils.snakecase("SoYouWantContributeToMerbCore")).to eq("so_you_want_contribute_to_merb_core")
16
- end
17
-
18
- it "handles CamelCase with more than 2 capital letter in a row" do
19
- expect(Nori::StringUtils.snakecase("CNN")).to eq("cnn")
20
- expect(Nori::StringUtils.snakecase("CNNNews")).to eq("cnn_news")
21
- expect(Nori::StringUtils.snakecase("HeadlineCNNNews")).to eq("headline_cnn_news")
22
- end
23
-
24
- it "does NOT change one word lowercase" do
25
- expect(Nori::StringUtils.snakecase("merb")).to eq("merb")
26
- end
27
-
28
- it "leaves snake_case as is" do
29
- expect(Nori::StringUtils.snakecase("merb_core")).to eq("merb_core")
30
- end
31
- end
32
-
33
- end
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require "bundler"
2
- Bundler.require :default, :development