roxml 3.2.2 → 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +13 -0
- data/Gemfile +9 -6
- data/Gemfile.lock +98 -40
- data/History.txt +15 -0
- data/README.rdoc +3 -2
- data/Rakefile +9 -21
- data/VERSION +1 -1
- data/examples/search_query.rb +17 -0
- data/lib/roxml.rb +9 -3
- data/lib/roxml/definition.rb +4 -9
- data/lib/roxml/xml/parsers/libxml.rb +11 -27
- data/lib/roxml/xml/parsers/nokogiri.rb +13 -26
- data/lib/roxml/xml/references.rb +33 -21
- data/roxml.gemspec +40 -40
- data/spec/definition_spec.rb +85 -104
- data/spec/examples/active_record_spec.rb +13 -13
- data/spec/examples/amazon_spec.rb +13 -13
- data/spec/examples/current_weather_spec.rb +6 -6
- data/spec/examples/dashed_elements_spec.rb +3 -3
- data/spec/examples/library_spec.rb +3 -3
- data/spec/examples/library_with_fines_spec.rb +7 -7
- data/spec/examples/person_spec.rb +27 -27
- data/spec/examples/post_spec.rb +4 -4
- data/spec/examples/search_query_spec.rb +26 -0
- data/spec/examples/twitter_spec.rb +4 -4
- data/spec/reference_spec.rb +2 -2
- data/spec/regression_spec.rb +13 -8
- data/spec/roxml_spec.rb +56 -61
- data/spec/shared_specs.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/xml/array_spec.rb +2 -2
- data/spec/xml/attributes_spec.rb +7 -7
- data/spec/xml/encoding_spec.rb +9 -9
- data/spec/xml/namespace_spec.rb +40 -21
- data/spec/xml/namespaces_spec.rb +3 -3
- data/spec/xml/object_spec.rb +7 -7
- data/spec/xml/parser_spec.rb +2 -8
- data/spec/xml/text_spec.rb +6 -6
- data/test/fixtures/book_with_octal_pages.xml +2 -3
- data/test/test_helper.rb +1 -2
- data/test/unit/definition_test.rb +26 -27
- data/test/unit/deprecations_test.rb +23 -2
- data/test/unit/to_xml_test.rb +9 -9
- data/test/unit/xml_attribute_test.rb +3 -2
- data/test/unit/xml_block_test.rb +3 -2
- data/test/unit/xml_bool_test.rb +7 -8
- data/test/unit/xml_convention_test.rb +4 -3
- data/test/unit/xml_hash_test.rb +5 -13
- data/test/unit/xml_initialize_test.rb +4 -3
- data/test/unit/xml_name_test.rb +3 -2
- data/test/unit/xml_namespace_test.rb +4 -3
- data/test/unit/xml_object_test.rb +8 -7
- data/test/unit/xml_required_test.rb +7 -6
- data/test/unit/xml_text_test.rb +3 -2
- data/website/index.html +11 -11
- metadata +114 -61
- data/test/load_test.rb +0 -6
data/spec/shared_specs.rb
CHANGED
@@ -2,13 +2,13 @@ if defined?(shared_examples_for)
|
|
2
2
|
shared_examples_for "freezable xml reference" do
|
3
3
|
describe "with :frozen option" do
|
4
4
|
it "should be frozen" do
|
5
|
-
@frozen.frozen
|
5
|
+
expect(@frozen.frozen?).to be_truthy
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "without :frozen option" do
|
10
10
|
it "should not be frozen" do
|
11
|
-
@unfrozen.frozen
|
11
|
+
expect(@unfrozen.frozen?).to be_falsey
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'ostruct'
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'pathname'
|
4
4
|
require 'ostruct'
|
5
|
+
require 'rspec/matchers' # req by equivalent-xml custom matcher `be_equivalent_to`
|
6
|
+
require 'equivalent-xml'
|
5
7
|
|
6
8
|
require_relative './../test/support/fixtures'
|
7
9
|
require_relative './../lib/roxml'
|
data/spec/xml/array_spec.rb
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
describe ":as => []" do
|
23
23
|
context "with plural from" do
|
24
24
|
it "should accept the plural name as the name for each item" do
|
25
|
-
ArraySpec::MyXml.from_xml(%(
|
25
|
+
expect(ArraySpec::MyXml.from_xml(%(
|
26
26
|
<myxml>
|
27
27
|
<store>
|
28
28
|
<books><id>1</id><title>first book</title></books>
|
@@ -30,7 +30,7 @@ describe ":as => []" do
|
|
30
30
|
<books><id>3</id><title>third book</title></books>
|
31
31
|
</store>
|
32
32
|
</myxml>
|
33
|
-
)).store.books.size.
|
33
|
+
)).store.books.size).to eq(3)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/spec/xml/attributes_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe ROXML::XMLAttributeRef do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should return one instance" do
|
19
|
-
@ref.value_in(@xml).
|
19
|
+
expect(@ref.value_in(@xml)).to eq("first")
|
20
20
|
end
|
21
21
|
it "should output one instance"
|
22
22
|
end
|
@@ -27,13 +27,13 @@ describe ROXML::XMLAttributeRef do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should collect all instances" do
|
30
|
-
@ref.value_in(@xml).
|
30
|
+
expect(@ref.value_in(@xml)).to eq(["first", "second", "third"])
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should output all instances" do
|
34
34
|
xml = ROXML::XML.new_node('myxml')
|
35
35
|
@ref.update_xml(xml, ["first", "second", "third"])
|
36
|
-
xml.to_s.squeeze(' ').
|
36
|
+
expect(xml.to_s.squeeze(' ')).to eq(@xml.root.to_s.squeeze(' '))
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -56,15 +56,15 @@ describe ROXML::XMLAttributeRef do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should collect all instances" do
|
59
|
-
|
60
|
-
@ref.value_in(@xml).
|
59
|
+
skip "Test bug?"
|
60
|
+
expect(@ref.value_in(@xml)).to eq(["first", "second", "third"])
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should output all instances with namespaces" do
|
64
|
-
|
64
|
+
skip "Full namespace write support"
|
65
65
|
xml = ROXML::XML.new_node('result')
|
66
66
|
@ref.update_xml(xml, ["first", "second", "third"])
|
67
|
-
xml.
|
67
|
+
expect(xml).to eq(@xml.root)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/spec/xml/encoding_spec.rb
CHANGED
@@ -13,41 +13,41 @@ describe ROXML, "encoding" do
|
|
13
13
|
res.message = "sadfk одловыа jjklsd " #random russian and english charecters
|
14
14
|
doc = ROXML::XML::Document.new
|
15
15
|
doc.root = res.to_xml
|
16
|
-
if defined?(Nokogiri)
|
16
|
+
expect(if defined?(Nokogiri)
|
17
17
|
doc.at('message').inner_text
|
18
18
|
else
|
19
19
|
doc.find_first('message').inner_xml
|
20
|
-
end.
|
20
|
+
end).to eq("sadfk одловыа jjklsd ")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should output those characters as input via xml" do
|
24
24
|
res = TestResult.from_xml("<test_result><message>sadfk одловыа jjklsd </message></test_result>")
|
25
25
|
doc = ROXML::XML::Document.new
|
26
26
|
doc.root = res.to_xml
|
27
|
-
if defined?(Nokogiri)
|
27
|
+
expect(if defined?(Nokogiri)
|
28
28
|
doc.at('message').inner_text
|
29
29
|
else
|
30
30
|
doc.find_first('message').inner_xml
|
31
|
-
end.
|
31
|
+
end).to eq("sadfk одловыа jjklsd ")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should allow override via the document" do
|
35
35
|
res = TestResult.from_xml("<test_result><message>sadfk одловыа jjklsd </message></test_result>")
|
36
|
-
if defined?(Nokogiri)
|
36
|
+
expect(if defined?(Nokogiri)
|
37
37
|
xml = res.to_xml
|
38
38
|
doc = xml.document
|
39
39
|
doc.root = xml
|
40
40
|
doc.encoding = 'ISO-8859-1'
|
41
|
-
doc.to_s.
|
41
|
+
expect(doc.to_s).to include('ISO-8859-1')
|
42
42
|
doc.at('message').inner_text
|
43
43
|
else
|
44
44
|
doc = LibXML::XML::Document.new
|
45
45
|
doc.encoding = LibXML::XML::Encoding::ASCII
|
46
46
|
doc.root = res.to_xml
|
47
|
-
|
48
|
-
doc.to_s.
|
47
|
+
skip "Libxml bug"
|
48
|
+
expect(doc.to_s).to include('ISO-8859-1')
|
49
49
|
doc.find_first('message').inner_xml
|
50
|
-
end.
|
50
|
+
end).to eq("sadfk одловыа jjklsd ")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/spec/xml/namespace_spec.rb
CHANGED
@@ -28,7 +28,7 @@ EOS
|
|
28
28
|
|
29
29
|
xml_name 'NetworkConfig'
|
30
30
|
xml_reader :name, :from => '@name'
|
31
|
-
xml_reader :errors, :as => []
|
31
|
+
xml_reader :errors, :as => [], :from => 'gronk:error'
|
32
32
|
xml_accessor :fence_mode, :from => 'vmw:FenceMode'
|
33
33
|
xml_accessor :dhcp?, :from => 'vmw:Dhcp'
|
34
34
|
end
|
@@ -50,9 +50,8 @@ EOS
|
|
50
50
|
describe "#to_xml" do
|
51
51
|
it "should reproduce the input xml" do
|
52
52
|
output = ROXML::XML::Document.new
|
53
|
-
output.root = VApp.from_xml(@xml).to_xml
|
54
|
-
|
55
|
-
output.should == ROXML::XML.parse_string(@xml)
|
53
|
+
output.root = VApp.from_xml(@xml).to_xml(:namespaces => {'vmw' => "http://foo.example.com", 'gronk' => "http://gronk.example.com"})
|
54
|
+
expect(ROXML::XML.parse_string(output.to_s)).to be_equivalent_to(ROXML::XML.parse_string(@xml))
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -61,23 +60,23 @@ EOS
|
|
61
60
|
context "with a namespacey :from" do
|
62
61
|
context "and an explicit :namespace" do
|
63
62
|
it "should raise" do
|
64
|
-
|
63
|
+
expect do
|
65
64
|
Class.new do
|
66
65
|
include ROXML
|
67
66
|
xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespacey_from', :namespace => 'explicit'
|
68
67
|
end
|
69
|
-
end.
|
68
|
+
end.to raise_error(ROXML::ContradictoryNamespaces)
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
72
|
context "and :namespace => false" do
|
74
73
|
it "should raise" do
|
75
|
-
|
74
|
+
expect do
|
76
75
|
Class.new do
|
77
76
|
include ROXML
|
78
77
|
xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespacey_from', :namespace => false
|
79
78
|
end
|
80
|
-
end.
|
79
|
+
end.to raise_error(ROXML::ContradictoryNamespaces)
|
81
80
|
end
|
82
81
|
end
|
83
82
|
end
|
@@ -87,12 +86,12 @@ EOS
|
|
87
86
|
it_should_behave_like "roxml namespacey declaration"
|
88
87
|
|
89
88
|
it "should use the default namespace" do
|
90
|
-
@instance.default_namespace.
|
89
|
+
expect(@instance.default_namespace).to eq('default namespace node')
|
91
90
|
end
|
92
91
|
|
93
92
|
context "and :namespace => false" do
|
94
93
|
it "should find the namespace-less node" do
|
95
|
-
@instance.default_namespace_with_namespace_false.
|
94
|
+
expect(@instance.default_namespace_with_namespace_false).to eq('namespaceless node')
|
96
95
|
end
|
97
96
|
end
|
98
97
|
|
@@ -104,25 +103,37 @@ EOS
|
|
104
103
|
|
105
104
|
context "with a namespace-less :from" do
|
106
105
|
it "should use the default namespace" do
|
107
|
-
@instance.default_namespace_with_namespaceless_from.
|
106
|
+
expect(@instance.default_namespace_with_namespaceless_from).to eq('default namespace node')
|
108
107
|
end
|
109
108
|
|
110
109
|
context "and :namespace => false" do
|
111
110
|
it "should find the namespace-less node" do
|
112
|
-
@instance.default_namespace_with_namespaceless_from_and_namespace_false.
|
111
|
+
expect(@instance.default_namespace_with_namespaceless_from_and_namespace_false).to eq('namespaceless node')
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
116
115
|
context "and an explicit :namespace" do
|
117
116
|
it "should use the explicit namespace" do
|
118
|
-
@instance.default_namespace_with_namespaceless_from_and_explicit_namespace.
|
117
|
+
expect(@instance.default_namespace_with_namespaceless_from_and_explicit_namespace).to eq('explicit namespace node')
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
122
|
context "with a namespacey :from" do
|
124
123
|
it "should use the :from namespace" do
|
125
|
-
@instance.default_namespace_with_namespacey_from.
|
124
|
+
expect(@instance.default_namespace_with_namespacey_from).to eq('namespacey node')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with an namespacey XPath :from" do
|
129
|
+
it "should use the given namespace" do
|
130
|
+
expect(@instance.default_namespace_with_namespacey_xpath_from).to eq('namespacey xpath node')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "with an XPath :from" do
|
135
|
+
it "should use the default namespace" do
|
136
|
+
expect(@instance.default_namespace_with_xpath_from).to eq('default namespace with xpath node')
|
126
137
|
end
|
127
138
|
end
|
128
139
|
end
|
@@ -139,6 +150,8 @@ EOS
|
|
139
150
|
xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit'
|
140
151
|
xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false
|
141
152
|
xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from'
|
153
|
+
xml_reader :default_namespace_with_namespacey_xpath_from, :from => 'xpath/namespacey:default_namespace'
|
154
|
+
xml_reader :default_namespace_with_xpath_from, :from => 'xpath/default_namespace'
|
142
155
|
|
143
156
|
# These are handled in the "roxml namespacey declaration" shared spec
|
144
157
|
# xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false
|
@@ -155,6 +168,8 @@ EOS
|
|
155
168
|
<default_declared:with_namespaceless_from>default namespace node</default_declared:with_namespaceless_from>
|
156
169
|
<explicit:default_and_explicit_namespace>explicit namespace node</explicit:default_and_explicit_namespace>
|
157
170
|
<default_namespace_with_namespace_false>namespaceless node</default_namespace_with_namespace_false>
|
171
|
+
<default_declared:xpath><namespacey:default_namespace>namespacey xpath node</namespacey:default_namespace></default_declared:xpath>
|
172
|
+
<default_declared:xpath><default_declared:default_namespace>default namespace with xpath node</default_declared:default_namespace></default_declared:xpath>
|
158
173
|
</book>
|
159
174
|
})
|
160
175
|
end
|
@@ -172,6 +187,8 @@ EOS
|
|
172
187
|
xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit'
|
173
188
|
xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false
|
174
189
|
xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from'
|
190
|
+
xml_reader :default_namespace_with_namespacey_xpath_from, :from => 'xpath/namespacey:default_namespace'
|
191
|
+
xml_reader :default_namespace_with_xpath_from, :from => 'xpath/default_namespace'
|
175
192
|
|
176
193
|
# These are handled in the "roxml namespacey declaration" shared spec
|
177
194
|
# xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false
|
@@ -188,6 +205,8 @@ EOS
|
|
188
205
|
<with_namespaceless_from>default namespace node</with_namespaceless_from>
|
189
206
|
<explicit:default_and_explicit_namespace>explicit namespace node</explicit:default_and_explicit_namespace>
|
190
207
|
<default_namespace_with_namespace_false xmlns="">namespaceless node</default_namespace_with_namespace_false>
|
208
|
+
<xpath><namespacey:default_namespace>namespacey xpath node</namespacey:default_namespace></xpath>
|
209
|
+
<xpath><default_namespace>default namespace with xpath node</default_namespace></xpath>
|
191
210
|
</book>
|
192
211
|
})
|
193
212
|
end
|
@@ -228,42 +247,42 @@ EOS
|
|
228
247
|
it_should_behave_like "roxml namespacey declaration"
|
229
248
|
|
230
249
|
it "should find the namespace-less node" do
|
231
|
-
@instance.no_default_namespace.
|
250
|
+
expect(@instance.no_default_namespace).to eq('namespaceless node')
|
232
251
|
end
|
233
252
|
|
234
253
|
context "with :namespace => false" do
|
235
254
|
it "should find the namespace-less node" do
|
236
|
-
@instance.no_default_namespace_with_namespace_false.
|
255
|
+
expect(@instance.no_default_namespace_with_namespace_false).to eq('namespaceless node')
|
237
256
|
end
|
238
257
|
end
|
239
258
|
|
240
259
|
context "with an explicit :namespace" do
|
241
260
|
it "should use the explicit namespace" do
|
242
|
-
@instance.no_default_but_an_explicit_namespace.
|
261
|
+
expect(@instance.no_default_but_an_explicit_namespace).to eq('explicit namespace node')
|
243
262
|
end
|
244
263
|
end
|
245
264
|
|
246
265
|
context "with a namespace-less :from" do
|
247
266
|
it "should find the namespace-less node" do
|
248
|
-
@instance.no_default_namespace_with_namespaceless_from.
|
267
|
+
expect(@instance.no_default_namespace_with_namespaceless_from).to eq('namespaceless node')
|
249
268
|
end
|
250
269
|
|
251
270
|
context "and an explicit :namespace" do
|
252
271
|
it "should use the explicit namespace" do
|
253
|
-
@instance.no_default_namespace_with_namespaceless_from_and_explicit_namespace.
|
272
|
+
expect(@instance.no_default_namespace_with_namespaceless_from_and_explicit_namespace).to eq('explicit namespace node')
|
254
273
|
end
|
255
274
|
end
|
256
275
|
|
257
276
|
context "with :namespace => false" do
|
258
277
|
it "should find the namespace-less node" do
|
259
|
-
@instance.no_default_namespace_with_namespaceless_from_and_namespace_false.
|
278
|
+
expect(@instance.no_default_namespace_with_namespaceless_from_and_namespace_false).to eq('namespaceless node')
|
260
279
|
end
|
261
280
|
end
|
262
281
|
end
|
263
282
|
|
264
283
|
context "with a namespacey :from" do
|
265
284
|
it "should use the :from namespace" do
|
266
|
-
@instance.no_default_namespace_with_namespacey_from.
|
285
|
+
expect(@instance.no_default_namespace_with_namespacey_from).to eq('namespacey node')
|
267
286
|
end
|
268
287
|
end
|
269
288
|
end
|
data/spec/xml/namespaces_spec.rb
CHANGED
@@ -25,16 +25,16 @@ describe ROXML, "#xml_namespaces" do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should remap default namespaces" do
|
28
|
-
Tires.from_xml(@xml).car_tires.
|
28
|
+
expect(Tires.from_xml(@xml).car_tires).to match_array(['super slick racing tire', 'all weather tire'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should remap prefix namespaces" do
|
32
|
-
Tires.from_xml(@xml).bike_tires.
|
32
|
+
expect(Tires.from_xml(@xml).bike_tires).to eq(['skinny street'])
|
33
33
|
end
|
34
34
|
|
35
35
|
context "with namespace-indifferent option" do
|
36
36
|
it "should return all tires" do
|
37
|
-
Tires.from_xml(@xml).tires.
|
37
|
+
expect(Tires.from_xml(@xml).tires).to match_array(['super slick racing tire', 'all weather tire', 'skinny street'])
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/xml/object_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe ROXML::XMLObjectRef do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should return one instance" do
|
31
|
-
@ref.value_in(@xml).value.
|
31
|
+
expect(@ref.value_in(@xml).value).to eq("first")
|
32
32
|
end
|
33
33
|
it "should output one instance"
|
34
34
|
end
|
@@ -39,13 +39,13 @@ describe ROXML::XMLObjectRef do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should collect all instances" do
|
42
|
-
@ref.value_in(@xml).map(&:value).
|
42
|
+
expect(@ref.value_in(@xml).map(&:value)).to eq(["first", "second", "third"])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should output all instances" do
|
46
46
|
xml = ROXML::XML.new_node('myxml')
|
47
47
|
@ref.update_xml(xml, ["first", "second", "third"].map {|value| SubObject.new(value) })
|
48
|
-
xml.to_s.squeeze(' ').
|
48
|
+
expect(xml.to_s.squeeze(' ')).to eq(@xml.root.to_s.squeeze(' '))
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -67,15 +67,15 @@ describe ROXML::XMLObjectRef do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should collect all instances" do
|
70
|
-
|
71
|
-
@ref.value_in(@xml).map(&:value).
|
70
|
+
skip "Test bug?"
|
71
|
+
expect(@ref.value_in(@xml).map(&:value)).to eq(["first", "second", "third"])
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should output all instances with namespaces" do
|
75
|
-
|
75
|
+
skip "Full namespace write support"
|
76
76
|
xml = ROXML::XML.new_node('myxml')
|
77
77
|
@ref.update_xml(xml, ["first", "second", "third"].map {|value| SubObject.new(value) })
|
78
|
-
xml.
|
78
|
+
expect(xml).to eq(@xml.root)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/spec/xml/parser_spec.rb
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
require_relative './../spec_helper.rb'
|
2
2
|
|
3
3
|
describe ROXML::XML do
|
4
|
-
it "should raise on malformed xml" do
|
5
|
-
if ROXML::XML_PARSER == 'libxml' # nokogiri is less strict and auto-closes for some reason
|
6
|
-
proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(LibXML::XML::Error)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
it "should escape invalid characters on output to text node" do
|
11
5
|
node = ROXML::XML.new_node("entities")
|
12
6
|
ROXML::XML.set_content(node, " < > ' \" & ")
|
13
|
-
node.to_s.
|
7
|
+
expect(node.to_s).to eq("<entities> < > ' \" & </entities>")
|
14
8
|
end
|
15
9
|
|
16
10
|
it "should esape invalid characters for attribute name" do
|
17
11
|
node = ROXML::XML.new_node("attr_holder")
|
18
12
|
ROXML::XML.set_attribute(node, "entities", "\"'<>&")
|
19
|
-
node.to_s.
|
13
|
+
expect(node.to_s).to eq(%{<attr_holder entities=""'<>&"/>})
|
20
14
|
end
|
21
15
|
end
|
data/spec/xml/text_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe ROXML::XMLTextRef do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return one instance" do
|
21
|
-
@ref.value_in(@xml).
|
21
|
+
expect(@ref.value_in(@xml)).to eq("first")
|
22
22
|
end
|
23
23
|
it "should output one instance"
|
24
24
|
end
|
@@ -29,13 +29,13 @@ describe ROXML::XMLTextRef do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should collect all instances" do
|
32
|
-
@ref.value_in(@xml).
|
32
|
+
expect(@ref.value_in(@xml)).to eq(["first", "second", "third"])
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should output all instances" do
|
36
36
|
xml = ROXML::XML.new_node('myxml')
|
37
37
|
@ref.update_xml(xml, ["first", "second", "third"])
|
38
|
-
xml.to_s.squeeze(' ').
|
38
|
+
expect(xml.to_s.squeeze(' ')).to eq(@xml.root.to_s.squeeze(' '))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -57,14 +57,14 @@ describe ROXML::XMLTextRef do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should collect all instances" do
|
60
|
-
@ref.value_in(@xml).
|
60
|
+
expect(@ref.value_in(@xml)).to eq(["first", "second", "third"])
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should output all instances with namespaces" do
|
64
|
-
|
64
|
+
skip "Full namespace write support"
|
65
65
|
xml = ROXML::XML.new_node('myxml')
|
66
66
|
@ref.update_xml(xml, ["first", "second", "third"])
|
67
|
-
xml.
|
67
|
+
expect(xml).to eq(@xml.root)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|