roxml 2.5.3 → 3.1.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 +7 -0
- data/.gitmodules +3 -0
- data/History.txt +38 -1
- data/README.rdoc +8 -5
- data/Rakefile +35 -36
- data/TODO +12 -35
- data/VERSION +1 -0
- data/examples/amazon.rb +8 -6
- data/examples/posts.rb +1 -1
- data/examples/{active_record.rb → rails.rb} +2 -2
- data/examples/twitter.rb +1 -1
- data/lib/roxml.rb +86 -151
- data/lib/roxml/definition.rb +64 -152
- data/lib/roxml/hash_definition.rb +5 -40
- data/lib/roxml/xml.rb +12 -9
- data/lib/roxml/xml/parsers/libxml.rb +22 -17
- data/lib/roxml/xml/parsers/nokogiri.rb +77 -0
- data/lib/roxml/xml/references.rb +66 -57
- data/roxml.gemspec +170 -19
- data/spec/definition_spec.rb +121 -198
- data/spec/examples/active_record_spec.rb +2 -2
- data/spec/examples/amazon_spec.rb +3 -2
- data/spec/examples/current_weather_spec.rb +2 -2
- data/spec/examples/dashed_elements_spec.rb +2 -2
- data/spec/examples/library_spec.rb +11 -6
- data/spec/examples/post_spec.rb +3 -3
- data/spec/examples/twitter_spec.rb +2 -2
- data/spec/roxml_spec.rb +15 -15
- data/spec/shared_specs.rb +1 -1
- data/spec/spec_helper.rb +8 -27
- 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 +9 -30
- data/tasks/rdoc.rake +13 -0
- data/tasks/rspec.rake +21 -17
- data/tasks/test.rake +13 -20
- data/test/mocks/dictionaries.rb +8 -7
- data/test/mocks/mocks.rb +20 -20
- data/test/support/fixtures.rb +11 -0
- data/test/test_helper.rb +3 -14
- data/test/unit/definition_test.rb +21 -95
- data/test/unit/deprecations_test.rb +1 -74
- data/test/unit/to_xml_test.rb +3 -3
- data/test/unit/xml_attribute_test.rb +1 -1
- data/test/unit/xml_block_test.rb +3 -3
- data/test/unit/xml_bool_test.rb +4 -4
- data/test/unit/xml_convention_test.rb +3 -3
- data/test/unit/xml_hash_test.rb +5 -14
- data/test/unit/xml_initialize_test.rb +2 -6
- data/test/unit/xml_name_test.rb +5 -24
- data/test/unit/xml_namespace_test.rb +1 -46
- data/test/unit/xml_object_test.rb +6 -6
- data/test/unit/xml_required_test.rb +3 -2
- data/test/unit/xml_text_test.rb +2 -2
- data/website/index.html +1 -1
- metadata +68 -51
- data/Manifest.txt +0 -106
- data/lib/roxml/extensions.rb +0 -6
- data/lib/roxml/extensions/array.rb +0 -13
- data/lib/roxml/extensions/array/conversions.rb +0 -35
- data/lib/roxml/extensions/deprecation.rb +0 -33
- data/lib/roxml/extensions/string.rb +0 -21
- data/lib/roxml/extensions/string/conversions.rb +0 -43
- data/lib/roxml/extensions/string/iterators.rb +0 -12
- data/lib/roxml/xml/parsers/rexml.rb +0 -84
- data/spec/string_spec.rb +0 -15
- data/test/bugs/rexml_bugs.rb +0 -15
- data/test/release/dependencies_test.rb +0 -32
- data/test/unit/xml_construct_test.rb +0 -77
- data/vendor/override_rake_task/README +0 -30
- data/vendor/override_rake_task/init.rb +0 -1
- data/vendor/override_rake_task/install.rb +0 -46
- data/vendor/override_rake_task/lib/override_rake_task.rb +0 -16
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'examples/amazon'
|
3
3
|
|
4
4
|
describe PITA::ItemSearchResponse do
|
5
5
|
before do
|
@@ -21,6 +21,7 @@ describe PITA::ItemSearchResponse do
|
|
21
21
|
describe "#items" do
|
22
22
|
it "should return a collection of items" do
|
23
23
|
@response.items.should be_an_instance_of(Array)
|
24
|
+
@response.items.size.should > 0
|
24
25
|
@response.items.each {|item| item.should be_an_instance_of(PITA::Item) }
|
25
26
|
end
|
26
27
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'examples/library'
|
3
3
|
|
4
4
|
describe Library do
|
5
5
|
before :all do
|
@@ -17,18 +17,23 @@ describe Library do
|
|
17
17
|
|
18
18
|
describe "#to_xml" do
|
19
19
|
it "should contain the expected information" do
|
20
|
-
@lib.to_xml.should == ROXML::XML::Parser.parse(%{<library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).root
|
20
|
+
@lib.to_xml.to_s.should == ROXML::XML::Parser.parse(%{<library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).root.to_s
|
21
21
|
end
|
22
22
|
|
23
23
|
context "when written to a file" do
|
24
24
|
before :all do
|
25
|
+
@path = "spec/examples/library.xml"
|
25
26
|
@doc = ROXML::XML::Document.new
|
26
27
|
@doc.root = @lib.to_xml
|
27
|
-
@doc.save(
|
28
|
+
@doc.save(@path)
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
after :all do
|
32
|
+
FileUtils.rm @path
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be contain the expected xml" do
|
36
|
+
ROXML::XML::Parser.parse(File.read(@path)).to_s.should == ROXML::XML::Parser.parse(%{<?xml version="1.0"?><library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).to_s
|
32
37
|
end
|
33
38
|
|
34
39
|
it "should be re-parsable via .from_xml" do
|
data/spec/examples/post_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'examples/posts'
|
3
3
|
|
4
4
|
describe Post do
|
5
5
|
before do
|
@@ -19,6 +19,6 @@ describe Post do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should extract time" do
|
22
|
-
@posts.each {|post| post.
|
22
|
+
@posts.each {|post| post.created_at.should be_an_instance_of(DateTime) }
|
23
23
|
end
|
24
24
|
end
|
data/spec/roxml_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe ROXML, "#from_xml" do
|
4
4
|
describe "from_xml call", :shared => true do
|
@@ -53,8 +53,8 @@ describe ROXML, "#xml" do
|
|
53
53
|
xml_name :book
|
54
54
|
xml_reader :isbn, :from => :attr
|
55
55
|
xml_reader :title
|
56
|
-
xml_reader :description, DescriptionReadonly
|
57
|
-
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions"
|
56
|
+
xml_reader :description, :as => DescriptionReadonly
|
57
|
+
xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions"
|
58
58
|
end
|
59
59
|
|
60
60
|
class BookWithContributionsReadonly
|
@@ -63,8 +63,8 @@ describe ROXML, "#xml" do
|
|
63
63
|
xml_name :book
|
64
64
|
xml_reader :isbn, :from => :attr, :frozen => true
|
65
65
|
xml_reader :title, :frozen => true
|
66
|
-
xml_reader :description, DescriptionReadonly, :frozen => true
|
67
|
-
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
|
66
|
+
xml_reader :description, :as => DescriptionReadonly, :frozen => true
|
67
|
+
xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
|
68
68
|
end
|
69
69
|
|
70
70
|
before do
|
@@ -106,7 +106,7 @@ describe ROXML, "#xml" do
|
|
106
106
|
include ROXML
|
107
107
|
|
108
108
|
xml_accessor :pages_with_as, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
|
109
|
-
xml_accessor :pages_with_type, OctalInteger, :required => true
|
109
|
+
xml_accessor :pages_with_type, :as => OctalInteger, :required => true
|
110
110
|
end
|
111
111
|
|
112
112
|
# to_xml_test :book_with_octal_pages
|
@@ -148,7 +148,7 @@ describe ROXML, "#xml" do
|
|
148
148
|
class BookWithOctalPagesType
|
149
149
|
include ROXML
|
150
150
|
|
151
|
-
xml_accessor :pages, OctalInteger, :required => true
|
151
|
+
xml_accessor :pages, :as => OctalInteger, :required => true
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should apply filtering on input" do
|
@@ -216,7 +216,7 @@ describe ROXML, "#xml" do
|
|
216
216
|
xml_reader :isbn, :from => :attr
|
217
217
|
xml_reader :title
|
218
218
|
xml_reader :description
|
219
|
-
xml_reader :contributors, [Contributor]
|
219
|
+
xml_reader :contributors, :as => [Contributor]
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should look for elements :in the plural of name" do
|
@@ -239,7 +239,7 @@ describe ROXML, "#xml" do
|
|
239
239
|
include ROXML
|
240
240
|
|
241
241
|
xml_name :dictionary
|
242
|
-
xml_reader :definitions, {:key => :name,
|
242
|
+
xml_reader :definitions, :as => {:key => :name,
|
243
243
|
:value => :content}, :in => :definitions
|
244
244
|
end
|
245
245
|
|
@@ -247,7 +247,7 @@ describe ROXML, "#xml" do
|
|
247
247
|
include ROXML
|
248
248
|
|
249
249
|
xml_name :dictionary
|
250
|
-
xml_reader :definitions, {:key => :name,
|
250
|
+
xml_reader :definitions, :as => {:key => :name,
|
251
251
|
:value => :content}, :in => :definitions, :frozen => true
|
252
252
|
end
|
253
253
|
|
@@ -274,11 +274,11 @@ describe ROXML, "inheritance" do
|
|
274
274
|
class Book
|
275
275
|
include ROXML
|
276
276
|
|
277
|
-
xml_accessor :isbn, :
|
277
|
+
xml_accessor :isbn, :from => '@ISBN'
|
278
278
|
xml_reader :title
|
279
|
-
xml_reader :description, :
|
279
|
+
xml_reader :description, :cdata => true
|
280
280
|
xml_reader :author
|
281
|
-
xml_accessor :pages, :
|
281
|
+
xml_accessor :pages, :from => 'pagecount', :as => Integer
|
282
282
|
end
|
283
283
|
|
284
284
|
class Measurement
|
@@ -315,7 +315,7 @@ describe ROXML, "inheritance" do
|
|
315
315
|
end
|
316
316
|
|
317
317
|
class InheritedBookWithDepth < Book
|
318
|
-
xml_reader :depth, Measurement
|
318
|
+
xml_reader :depth, :as => Measurement
|
319
319
|
end
|
320
320
|
|
321
321
|
before do
|
@@ -362,7 +362,7 @@ describe ROXML, "inheritance" do
|
|
362
362
|
|
363
363
|
it "should include parent's attributes added after declaration" do
|
364
364
|
Book.class_eval do
|
365
|
-
xml_reader :publisher, :
|
365
|
+
xml_reader :publisher, :required => true
|
366
366
|
end
|
367
367
|
|
368
368
|
book = InheritedBookWithDepth.from_xml(@book_xml)
|
data/spec/shared_specs.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,33 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'pathname'
|
3
|
+
require 'test/support/fixtures'
|
4
|
+
require 'lib/roxml'
|
2
5
|
|
3
|
-
|
4
|
-
SILENCE_XML_NAME_WARNING = true
|
5
|
-
end
|
6
|
-
|
7
|
-
DIR = Pathname.new(__FILE__ + '../..').expand_path.dirname
|
8
|
-
LOAD_PATH = DIR.join('lib').to_s
|
9
|
-
$LOAD_PATH.unshift(LOAD_PATH) unless
|
10
|
-
$LOAD_PATH.include?(LOAD_PATH) || $LOAD_PATH.include?(File.expand_path(LOAD_PATH))
|
11
|
-
require 'roxml'
|
12
|
-
|
13
|
-
require File.join(File.dirname(__FILE__), 'shared_specs')
|
14
|
-
|
15
|
-
def example(name)
|
16
|
-
DIR.join("examples/#{name}.rb")
|
17
|
-
end
|
6
|
+
require 'spec/shared_specs' if defined?(Spec)
|
18
7
|
|
19
|
-
def
|
20
|
-
File.
|
21
|
-
end
|
22
|
-
|
23
|
-
def xml_fixture(name)
|
24
|
-
ROXML::XML::Parser.parse_file(fixture_path(name)).root
|
8
|
+
def xml_for(name)
|
9
|
+
Pathname.new(File.dirname(__FILE__)).expand_path.dirname.join("examples/xml/#{name}.xml")
|
25
10
|
end
|
26
11
|
|
27
|
-
|
28
|
-
|
12
|
+
class RoxmlObject
|
13
|
+
include ROXML
|
29
14
|
end
|
30
|
-
|
31
|
-
def xml_for(name)
|
32
|
-
DIR.join("examples/xml/#{name}.xml")
|
33
|
-
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
|