ROXML 3.0.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.
- data/.gitignore +6 -0
- data/.gitmodules +3 -0
- data/History.txt +299 -0
- data/MIT-LICENSE +18 -0
- data/README.rdoc +161 -0
- data/Rakefile +95 -0
- data/TODO +39 -0
- data/VERSION +1 -0
- data/config/website.yml +2 -0
- data/examples/amazon.rb +35 -0
- data/examples/current_weather.rb +27 -0
- data/examples/dashed_elements.rb +20 -0
- data/examples/library.rb +40 -0
- data/examples/posts.rb +27 -0
- data/examples/rails.rb +70 -0
- data/examples/twitter.rb +37 -0
- data/examples/xml/active_record.xml +70 -0
- data/examples/xml/amazon.xml +133 -0
- data/examples/xml/current_weather.xml +89 -0
- data/examples/xml/dashed_elements.xml +52 -0
- data/examples/xml/posts.xml +23 -0
- data/examples/xml/twitter.xml +422 -0
- data/lib/roxml.rb +547 -0
- data/lib/roxml/definition.rb +236 -0
- data/lib/roxml/hash_definition.rb +25 -0
- data/lib/roxml/xml.rb +43 -0
- data/lib/roxml/xml/parsers/libxml.rb +91 -0
- data/lib/roxml/xml/parsers/nokogiri.rb +77 -0
- data/lib/roxml/xml/references.rb +297 -0
- data/roxml.gemspec +201 -0
- data/spec/definition_spec.rb +486 -0
- data/spec/examples/active_record_spec.rb +40 -0
- data/spec/examples/amazon_spec.rb +54 -0
- data/spec/examples/current_weather_spec.rb +37 -0
- data/spec/examples/dashed_elements_spec.rb +20 -0
- data/spec/examples/library_spec.rb +46 -0
- data/spec/examples/post_spec.rb +24 -0
- data/spec/examples/twitter_spec.rb +32 -0
- data/spec/roxml_spec.rb +372 -0
- data/spec/shared_specs.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/libxml.rb +3 -0
- data/spec/support/nokogiri.rb +3 -0
- data/spec/xml/attributes_spec.rb +36 -0
- data/spec/xml/namespace_spec.rb +240 -0
- data/spec/xml/namespaces_spec.rb +32 -0
- data/spec/xml/parser_spec.rb +26 -0
- data/tasks/rdoc.rake +13 -0
- data/tasks/rspec.rake +25 -0
- data/tasks/test.rake +35 -0
- data/test/fixtures/book_malformed.xml +5 -0
- data/test/fixtures/book_pair.xml +8 -0
- data/test/fixtures/book_text_with_attribute.xml +5 -0
- data/test/fixtures/book_valid.xml +5 -0
- data/test/fixtures/book_with_authors.xml +7 -0
- data/test/fixtures/book_with_contributions.xml +9 -0
- data/test/fixtures/book_with_contributors.xml +7 -0
- data/test/fixtures/book_with_contributors_attrs.xml +7 -0
- data/test/fixtures/book_with_default_namespace.xml +9 -0
- data/test/fixtures/book_with_depth.xml +6 -0
- data/test/fixtures/book_with_octal_pages.xml +4 -0
- data/test/fixtures/book_with_publisher.xml +7 -0
- data/test/fixtures/book_with_wrapped_attr.xml +3 -0
- data/test/fixtures/dictionary_of_attr_name_clashes.xml +8 -0
- data/test/fixtures/dictionary_of_attrs.xml +6 -0
- data/test/fixtures/dictionary_of_guarded_names.xml +6 -0
- data/test/fixtures/dictionary_of_mixeds.xml +4 -0
- data/test/fixtures/dictionary_of_name_clashes.xml +10 -0
- data/test/fixtures/dictionary_of_names.xml +4 -0
- data/test/fixtures/dictionary_of_texts.xml +10 -0
- data/test/fixtures/library.xml +30 -0
- data/test/fixtures/library_uppercase.xml +30 -0
- data/test/fixtures/muffins.xml +3 -0
- data/test/fixtures/nameless_ageless_youth.xml +2 -0
- data/test/fixtures/node_with_attr_name_conflicts.xml +1 -0
- data/test/fixtures/node_with_name_conflicts.xml +4 -0
- data/test/fixtures/numerology.xml +4 -0
- data/test/fixtures/person.xml +1 -0
- data/test/fixtures/person_with_guarded_mothers.xml +13 -0
- data/test/fixtures/person_with_mothers.xml +10 -0
- data/test/mocks/dictionaries.rb +57 -0
- data/test/mocks/mocks.rb +279 -0
- data/test/support/fixtures.rb +11 -0
- data/test/test_helper.rb +34 -0
- data/test/unit/definition_test.rb +235 -0
- data/test/unit/deprecations_test.rb +24 -0
- data/test/unit/to_xml_test.rb +81 -0
- data/test/unit/xml_attribute_test.rb +39 -0
- data/test/unit/xml_block_test.rb +81 -0
- data/test/unit/xml_bool_test.rb +122 -0
- data/test/unit/xml_convention_test.rb +150 -0
- data/test/unit/xml_hash_test.rb +115 -0
- data/test/unit/xml_initialize_test.rb +49 -0
- data/test/unit/xml_name_test.rb +141 -0
- data/test/unit/xml_namespace_test.rb +31 -0
- data/test/unit/xml_object_test.rb +207 -0
- data/test/unit/xml_required_test.rb +94 -0
- data/test/unit/xml_text_test.rb +71 -0
- data/website/index.html +98 -0
- metadata +254 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe "freezable xml reference", :shared => true do
|
4
|
+
describe "with :frozen option" do
|
5
|
+
it "should be frozen" do
|
6
|
+
@frozen.frozen?.should be_true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "without :frozen option" do
|
11
|
+
it "should not be frozen" do
|
12
|
+
@unfrozen.frozen?.should be_false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pathname'
|
3
|
+
require 'test/support/fixtures'
|
4
|
+
require 'lib/roxml'
|
5
|
+
|
6
|
+
require 'spec/shared_specs' if defined?(Spec)
|
7
|
+
|
8
|
+
def xml_for(name)
|
9
|
+
Pathname.new(File.dirname(__FILE__)).expand_path.dirname.join("examples/xml/#{name}.xml")
|
10
|
+
end
|
11
|
+
|
12
|
+
class RoxmlObject
|
13
|
+
include ROXML
|
14
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ROXML::XMLAttributeRef do
|
4
|
+
before do
|
5
|
+
@xml = ROXML::XML::Parser.parse %(
|
6
|
+
<myxml>
|
7
|
+
<node name="first" />
|
8
|
+
<node name="second" />
|
9
|
+
<node name="third" />
|
10
|
+
</myxml>
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "plain vanilla" do
|
15
|
+
before do
|
16
|
+
@ref = ROXML::XMLAttributeRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => false), RoxmlObject.new)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return one instance" do
|
20
|
+
@ref.send(:fetch_value, @xml).should == "first"
|
21
|
+
end
|
22
|
+
it "should output one instance"
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with :as => []" do
|
26
|
+
before do
|
27
|
+
@ref = ROXML::XMLAttributeRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true), RoxmlObject.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should collect all instances" do
|
31
|
+
@ref.send(:fetch_value, @xml).should == ["first", "second", "third"]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should output all instances"
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
|
3
|
+
describe ROXML, "with namespaces" do
|
4
|
+
context "when an included namespace is not defined in the xml" do
|
5
|
+
context "where the missing namespace is the default" do
|
6
|
+
it "should raise"
|
7
|
+
|
8
|
+
context "but the namespace is declared in the body" do
|
9
|
+
it "should succeed"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "where the missing namespace is included in a namespacey from" do
|
14
|
+
it "should raise"
|
15
|
+
|
16
|
+
context "but the namespace is declared in the body" do
|
17
|
+
it "should succeed"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "where the missing namespace is included in an explicit :namespace" do
|
22
|
+
it "should raise"
|
23
|
+
|
24
|
+
context "but the namespace is declared in the body" do
|
25
|
+
it "should succeed"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "roxml namespacey declaration", :shared => true do
|
31
|
+
context "with a namespacey :from" do
|
32
|
+
context "and an explicit :namespace" do
|
33
|
+
it "should raise" do
|
34
|
+
proc do
|
35
|
+
Class.new do
|
36
|
+
include ROXML
|
37
|
+
xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespacey_from', :namespace => 'explicit'
|
38
|
+
end
|
39
|
+
end.should raise_error(ROXML::ContradictoryNamespaces)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "and :namespace => false" do
|
44
|
+
it "should raise" do
|
45
|
+
proc do
|
46
|
+
Class.new do
|
47
|
+
include ROXML
|
48
|
+
xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespacey_from', :namespace => false
|
49
|
+
end
|
50
|
+
end.should raise_error(ROXML::ContradictoryNamespaces)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "roxml namespacey declaration with default", :shared => true do
|
57
|
+
it_should_behave_like "roxml namespacey declaration"
|
58
|
+
|
59
|
+
it "should use the default namespace" do
|
60
|
+
@instance.default_namespace.should == 'default namespace node'
|
61
|
+
end
|
62
|
+
|
63
|
+
context "and :namespace => false" do
|
64
|
+
it "should find the namespace-less node" do
|
65
|
+
@instance.default_namespace_with_namespace_false.should == 'namespaceless node'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with an explicit :namespace" do
|
70
|
+
it "should use the explicit namespace" do
|
71
|
+
@instance.default_and_explicit_namespace == 'explicit namespace node'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with a namespace-less :from" do
|
76
|
+
it "should use the default namespace" do
|
77
|
+
@instance.default_namespace_with_namespaceless_from.should == 'default namespace node'
|
78
|
+
end
|
79
|
+
|
80
|
+
context "and :namespace => false" do
|
81
|
+
it "should find the namespace-less node" do
|
82
|
+
@instance.default_namespace_with_namespaceless_from_and_namespace_false.should == 'namespaceless node'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and an explicit :namespace" do
|
87
|
+
it "should use the explicit namespace" do
|
88
|
+
@instance.default_namespace_with_namespaceless_from_and_explicit_namespace.should == 'explicit namespace node'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with a namespacey :from" do
|
94
|
+
it "should use the :from namespace" do
|
95
|
+
@instance.default_namespace_with_namespacey_from.should == 'namespacey node'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with a default namespace declared" do
|
101
|
+
class DefaultNamespaceyObject
|
102
|
+
include ROXML
|
103
|
+
xml_namespace :default_declared
|
104
|
+
|
105
|
+
xml_reader :default_namespace
|
106
|
+
xml_reader :default_namespace_with_namespace_false, :namespace => false
|
107
|
+
xml_reader :default_and_explicit_namespace, :namespace => 'explicit'
|
108
|
+
xml_reader :default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from'
|
109
|
+
xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit'
|
110
|
+
xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false
|
111
|
+
xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from'
|
112
|
+
|
113
|
+
# These are handled in the "roxml namespacey declaration" shared spec
|
114
|
+
# xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false
|
115
|
+
# xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespaceless_from', :namespace => 'explicit'
|
116
|
+
end
|
117
|
+
|
118
|
+
before do
|
119
|
+
@instance = DefaultNamespaceyObject.from_xml(%{
|
120
|
+
<book xmlns:namespacey="http://www.aws.com/aws" xmlns:default_declared="http://www.aws.com/default" xmlns:explicit="http://www.aws.com/different">
|
121
|
+
<default_declared:default_namespace>default namespace node</default_declared:default_namespace>
|
122
|
+
<namespacey:with_namespacey_from>namespacey node</namespacey:with_namespacey_from>
|
123
|
+
<explicit:with_namespaceless_from>explicit namespace node</explicit:with_namespaceless_from>
|
124
|
+
<with_namespaceless_from>namespaceless node</with_namespaceless_from>
|
125
|
+
<default_declared:with_namespaceless_from>default namespace node</default_declared:with_namespaceless_from>
|
126
|
+
<explicit:default_and_explicit_namespace>explicit namespace node</explicit:default_and_explicit_namespace>
|
127
|
+
<default_namespace_with_namespace_false>namespaceless node</default_namespace_with_namespace_false>
|
128
|
+
</book>
|
129
|
+
})
|
130
|
+
end
|
131
|
+
|
132
|
+
it_should_behave_like "roxml namespacey declaration with default"
|
133
|
+
end
|
134
|
+
|
135
|
+
context "with a default namespace on the root node" do
|
136
|
+
class XmlDefaultNamespaceyObject
|
137
|
+
include ROXML
|
138
|
+
xml_reader :default_namespace
|
139
|
+
xml_reader :default_namespace_with_namespace_false, :namespace => false
|
140
|
+
xml_reader :default_and_explicit_namespace, :namespace => 'explicit'
|
141
|
+
xml_reader :default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from'
|
142
|
+
xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit'
|
143
|
+
xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false
|
144
|
+
xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from'
|
145
|
+
|
146
|
+
# These are handled in the "roxml namespacey declaration" shared spec
|
147
|
+
# xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false
|
148
|
+
# xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespaceless_from', :namespace => 'explicit'
|
149
|
+
end
|
150
|
+
|
151
|
+
before do
|
152
|
+
@instance = XmlDefaultNamespaceyObject.from_xml(%{
|
153
|
+
<book xmlns="http://www.aws.com/xml_default" xmlns:namespacey="http://www.aws.com/aws" xmlns:default_declared="http://www.aws.com/default" xmlns:explicit="http://www.aws.com/different">
|
154
|
+
<default_namespace>default namespace node</default_namespace>
|
155
|
+
<namespacey:with_namespacey_from>namespacey node</namespacey:with_namespacey_from>
|
156
|
+
<explicit:with_namespaceless_from>explicit namespace node</explicit:with_namespaceless_from>
|
157
|
+
<with_namespaceless_from xmlns="">namespaceless node</with_namespaceless_from>
|
158
|
+
<with_namespaceless_from>default namespace node</with_namespaceless_from>
|
159
|
+
<explicit:default_and_explicit_namespace>explicit namespace node</explicit:default_and_explicit_namespace>
|
160
|
+
<default_namespace_with_namespace_false xmlns="">namespaceless node</default_namespace_with_namespace_false>
|
161
|
+
</book>
|
162
|
+
})
|
163
|
+
end
|
164
|
+
|
165
|
+
it_should_behave_like "roxml namespacey declaration with default"
|
166
|
+
end
|
167
|
+
|
168
|
+
context "without a default namespace" do
|
169
|
+
class NamespaceyObject
|
170
|
+
include ROXML
|
171
|
+
|
172
|
+
xml_reader :no_default_namespace
|
173
|
+
xml_reader :no_default_namespace_with_namespace_false, :namespace => false
|
174
|
+
xml_reader :no_default_but_an_explicit_namespace, :namespace => 'explicit'
|
175
|
+
xml_reader :no_default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from'
|
176
|
+
xml_reader :no_default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit'
|
177
|
+
xml_reader :no_default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false
|
178
|
+
xml_reader :no_default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from'
|
179
|
+
|
180
|
+
# These are handled in the "roxml namespacey declaration" shared spec
|
181
|
+
# xml_reader :no_default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespacey_from', :namespace => 'explicit'
|
182
|
+
# xml_reader :no_default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespacey_from', :namespace => false
|
183
|
+
end
|
184
|
+
|
185
|
+
before do
|
186
|
+
@instance = NamespaceyObject.from_xml(%{
|
187
|
+
<book xmlns:namespacey="http://www.aws.com/aws" xmlns:explicit="http://www.aws.com/different">
|
188
|
+
<namespacey:with_namespacey_from>namespacey node</namespacey:with_namespacey_from>
|
189
|
+
<explicit:with_namespaceless_from>explicit namespace node</explicit:with_namespaceless_from>
|
190
|
+
<with_namespaceless_from>namespaceless node</with_namespaceless_from>
|
191
|
+
<explicit:no_default_but_an_explicit_namespace>explicit namespace node</explicit:no_default_but_an_explicit_namespace>
|
192
|
+
<no_default_namespace_with_namespace_false>namespaceless node</no_default_namespace_with_namespace_false>
|
193
|
+
<no_default_namespace>namespaceless node</no_default_namespace>
|
194
|
+
</book>
|
195
|
+
})
|
196
|
+
end
|
197
|
+
|
198
|
+
it_should_behave_like "roxml namespacey declaration"
|
199
|
+
|
200
|
+
it "should find the namespace-less node" do
|
201
|
+
@instance.no_default_namespace.should == 'namespaceless node'
|
202
|
+
end
|
203
|
+
|
204
|
+
context "with :namespace => false" do
|
205
|
+
it "should find the namespace-less node" do
|
206
|
+
@instance.no_default_namespace_with_namespace_false.should == 'namespaceless node'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "with an explicit :namespace" do
|
211
|
+
it "should use the explicit namespace" do
|
212
|
+
@instance.no_default_but_an_explicit_namespace.should == 'explicit namespace node'
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "with a namespace-less :from" do
|
217
|
+
it "should find the namespace-less node" do
|
218
|
+
@instance.no_default_namespace_with_namespaceless_from.should == 'namespaceless node'
|
219
|
+
end
|
220
|
+
|
221
|
+
context "and an explicit :namespace" do
|
222
|
+
it "should use the explicit namespace" do
|
223
|
+
@instance.no_default_namespace_with_namespaceless_from_and_explicit_namespace.should == 'explicit namespace node'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context "with :namespace => false" do
|
228
|
+
it "should find the namespace-less node" do
|
229
|
+
@instance.no_default_namespace_with_namespaceless_from_and_namespace_false.should == 'namespaceless node'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "with a namespacey :from" do
|
235
|
+
it "should use the :from namespace" do
|
236
|
+
@instance.no_default_namespace_with_namespacey_from.should == 'namespacey node'
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
|
3
|
+
describe ROXML, "#xml_namespaces" do
|
4
|
+
class Tires
|
5
|
+
include ROXML
|
6
|
+
|
7
|
+
xml_namespaces \
|
8
|
+
:bobsbike => 'http://bobsbikes.example.com',
|
9
|
+
:alicesauto => 'http://alicesautosupply.example.com/'
|
10
|
+
|
11
|
+
xml_reader :bike_tires, :as => [], :from => '@name', :in => 'bobsbike:tire'
|
12
|
+
xml_reader :car_tires, :as => [], :from => '@name', :in => 'alicesauto:tire'
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
@xml = %{<?xml version="1.0"?>
|
17
|
+
<inventory xmlns="http://alicesautosupply.example.com/" xmlns:bike="http://bobsbikes.example.com">
|
18
|
+
<tire name="super slick racing tire" />
|
19
|
+
<tire name="all weather tire" />
|
20
|
+
<bike:tire name="skinny street" />
|
21
|
+
</inventory>
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should remap default namespaces" do
|
26
|
+
Tires.from_xml(@xml).car_tires.should =~ ['super slick racing tire', 'all weather tire']
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should remap prefix namespaces" do
|
30
|
+
Tires.from_xml(@xml).bike_tires.should == ['skinny street']
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
|
3
|
+
describe ROXML::XML::Parser do
|
4
|
+
before do
|
5
|
+
# quiet the error handler
|
6
|
+
ROXML::XML::Error.reset_handler if ROXML::XML::Error.respond_to?(:reset_handler)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise on malformed xml" do
|
10
|
+
unless ROXML::XML_PARSER == 'nokogiri' # nokogiri is less strict and auto-closes for some reason
|
11
|
+
proc { Book.from_xml(fixture(:book_malformed)) }.should raise_error(ROXML::XML::Error)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should escape invalid characters on output to text node" do
|
16
|
+
node = ROXML::XML::Node.create("entities")
|
17
|
+
node.content = " < > ' \" & "
|
18
|
+
node.to_s.should == "<entities> < > ' \" & </entities>"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should esape invalid characters for attribute name" do
|
22
|
+
node = ROXML::XML::Node.create("attr_holder")
|
23
|
+
node.attributes["entities"] = "\"'<>&"
|
24
|
+
node.to_s.should == %{<attr_holder entities=""'<>&"/>}
|
25
|
+
end
|
26
|
+
end
|
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rake/rdoctask'
|
2
|
+
Rake::RDocTask.new do |rdoc|
|
3
|
+
if File.exist?('VERSION')
|
4
|
+
version = File.read('VERSION')
|
5
|
+
else
|
6
|
+
version = ""
|
7
|
+
end
|
8
|
+
|
9
|
+
rdoc.rdoc_dir = 'rdoc'
|
10
|
+
rdoc.title = "roxml-new #{version}"
|
11
|
+
rdoc.rdoc_files.include('README*')
|
12
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
13
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
desc "Run specs"
|
3
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
4
|
+
spec.libs << 'lib' << 'spec' << 'examples'
|
5
|
+
spec.spec_opts = ['--options', "spec/spec.opts"]
|
6
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :spec do
|
10
|
+
[:libxml, :nokogiri].each do |parser|
|
11
|
+
desc "Spec ROXML under the #{parser} parser"
|
12
|
+
Spec::Rake::SpecTask.new(parser) do |spec|
|
13
|
+
spec.libs << 'lib' << 'spec' << 'examples'
|
14
|
+
spec.spec_opts = ['--options=spec/spec.opts']
|
15
|
+
spec.spec_files = ["spec/support/#{parser}.rb"] + FileList['spec/**/*_spec.rb']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run specs with rcov"
|
21
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
24
|
+
spec.rcov = true
|
25
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
Rake::TestTask.new(:bugs) do |test|
|
3
|
+
test.libs << 'lib' << 'test'
|
4
|
+
test.pattern = 'test/bugs/*_bugs.rb'
|
5
|
+
test.verbose = true
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Test ROXML using the default parser selection behavior"
|
9
|
+
task :test do
|
10
|
+
require 'rake/runtest'
|
11
|
+
Rake.run_tests 'test/unit/*_test.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :test do
|
15
|
+
desc "Test ROXML under the Nokogiri parser"
|
16
|
+
task :nokogiri do
|
17
|
+
module ROXML
|
18
|
+
XML_PARSER = 'nokogiri'
|
19
|
+
end
|
20
|
+
Rake::Task["test"].invoke
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Test ROXML under the LibXML parser"
|
24
|
+
task :libxml do
|
25
|
+
module ROXML
|
26
|
+
XML_PARSER = 'libxml'
|
27
|
+
end
|
28
|
+
Rake::Task["test"].invoke
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Runs tests under RCOV"
|
32
|
+
task :rcov do
|
33
|
+
system "rcov -T --no-html -x '^/' #{FileList['test/unit/*_test.rb']}"
|
34
|
+
end
|
35
|
+
end
|