xmlparsable 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xmlparsable/elements/record.rb +1 -1
- data/spec/examples/repeated.example +74 -0
- metadata +3 -1
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe XmlParsable do
|
4
|
+
|
5
|
+
# Shortcut declaration syntax
|
6
|
+
describe "repeated elements" do
|
7
|
+
let(:parser) do
|
8
|
+
Class.new do
|
9
|
+
inner = Class.new do
|
10
|
+
include XmlParsable
|
11
|
+
repeated :a, accessor: "as"
|
12
|
+
end
|
13
|
+
|
14
|
+
include XmlParsable
|
15
|
+
element :root, inner
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "accumulates repeated elements" do
|
20
|
+
expected = ["Y", "N", "?"]
|
21
|
+
input = "<root><a>Y</a><a>N</a><a>?</a></root>"
|
22
|
+
|
23
|
+
xml = parser.parse(input)
|
24
|
+
xml.root.as.should == expected
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Non-shortcut declaration syntax
|
29
|
+
describe "repeated elements" do
|
30
|
+
let(:parser) do
|
31
|
+
Class.new do
|
32
|
+
inner = Class.new do
|
33
|
+
include XmlParsable
|
34
|
+
element :a, repeated: true, accessor: "as"
|
35
|
+
end
|
36
|
+
|
37
|
+
include XmlParsable
|
38
|
+
element :root, inner
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "accumulates repeated elements" do
|
43
|
+
expected = ["Y", "N", "?"]
|
44
|
+
input = "<root><a>Y</a><a>N</a><a>?</a></root>"
|
45
|
+
|
46
|
+
xml = parser.parse(input)
|
47
|
+
xml.root.as.should == expected
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
describe "non-repeated elements" do
|
53
|
+
let(:parser) do
|
54
|
+
Class.new do
|
55
|
+
inner = Class.new do
|
56
|
+
include XmlParsable
|
57
|
+
element :a, accessor: "as"
|
58
|
+
end
|
59
|
+
|
60
|
+
include XmlParsable
|
61
|
+
element :root, inner
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "stores the last-occurring element" do
|
66
|
+
expected = "?"
|
67
|
+
input = "<root><a>Y</a><a>N</a><a>?</a></root>"
|
68
|
+
|
69
|
+
xml = parser.parse(input)
|
70
|
+
xml.root.as.should == expected
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlparsable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- spec/examples/elements/time.example
|
58
58
|
- spec/examples/elements/xml.example
|
59
59
|
- spec/examples/inheritance.example
|
60
|
+
- spec/examples/repeated.example
|
60
61
|
- spec/spec_helper.rb
|
61
62
|
homepage: https://github.com/kputnam/xmlparsable
|
62
63
|
licenses: []
|
@@ -93,3 +94,4 @@ test_files:
|
|
93
94
|
- spec/examples/elements/time.example
|
94
95
|
- spec/examples/elements/xml.example
|
95
96
|
- spec/examples/inheritance.example
|
97
|
+
- spec/examples/repeated.example
|