multi_xml 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +3 -3
- data/CONTRIBUTING.md +49 -0
- data/README.md +15 -64
- data/Rakefile +1 -1
- data/lib/multi_xml.rb +23 -6
- data/lib/multi_xml/version.rb +1 -1
- data/multi_xml.gemspec +18 -17
- data/spec/helper.rb +8 -0
- data/spec/multi_xml_spec.rb +12 -12
- data/spec/parser_shared_example.rb +194 -166
- metadata +34 -33
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
## Contributing
|
2
|
+
In the spirit of [free software][free-sw] , **everyone** is encouraged to help
|
3
|
+
improve this project.
|
4
|
+
|
5
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
6
|
+
|
7
|
+
Here are some ways *you* can contribute:
|
8
|
+
|
9
|
+
* by using alpha, beta, and prerelease versions
|
10
|
+
* by reporting bugs
|
11
|
+
* by suggesting new features
|
12
|
+
* by writing or editing documentation
|
13
|
+
* by writing specifications
|
14
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
15
|
+
inconsistent whitespace)
|
16
|
+
* by refactoring code
|
17
|
+
* by resolving [issues][]
|
18
|
+
* by reviewing patches
|
19
|
+
|
20
|
+
[issues]: https://github.com/sferik/multi_xml/issues
|
21
|
+
|
22
|
+
## Submitting an Issue
|
23
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
24
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
25
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
26
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
27
|
+
the bug, including your gem version, Ruby version, and operating system.
|
28
|
+
Ideally, a bug report should include a pull request with failing specs.
|
29
|
+
|
30
|
+
[gist]: https://gist.github.com/
|
31
|
+
|
32
|
+
## Submitting a Pull Request
|
33
|
+
1. [Fork the repository.][fork]
|
34
|
+
2. [Create a topic branch.][branch]
|
35
|
+
3. Add specs for your unimplemented feature or bug fix.
|
36
|
+
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
37
|
+
5. Implement your feature or bug fix.
|
38
|
+
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
39
|
+
7. Run `open coverage/index.html`. If your changes are not completely covered
|
40
|
+
by your tests, return to step 3.
|
41
|
+
8. Add documentation for your feature or bug fix.
|
42
|
+
9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
|
43
|
+
back to step 8.
|
44
|
+
10. Add, commit, and push your changes.
|
45
|
+
11. [Submit a pull request.][pr]
|
46
|
+
|
47
|
+
[fork]: http://help.github.com/fork-a-repo/
|
48
|
+
[branch]: http://learn.github.com/p/branching.html
|
49
|
+
[pr]: http://help.github.com/send-pull-requests/
|
data/README.md
CHANGED
@@ -17,24 +17,25 @@ Lots of Ruby libraries utilize XML parsing in some form, and everyone has their
|
|
17
17
|
favorite XML library. In order to best support multiple XML parsers and
|
18
18
|
libraries, `multi_xml` is a general-purpose swappable XML backend library. You
|
19
19
|
use it like so:
|
20
|
+
```ruby
|
21
|
+
require 'multi_xml'
|
20
22
|
|
21
|
-
|
23
|
+
MultiXml.parser = :ox
|
24
|
+
MultiXml.parser = MultiXml::Parsers::Ox # Same as above
|
25
|
+
MultiXml.parse('<tag>This is the contents</tag>') # Parsed using Ox
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
MultiXml.parser = :libxml
|
28
|
+
MultiXml.parser = MultiXml::Parsers::Libxml # Same as above
|
29
|
+
MultiXml.parse('<tag>This is the contents</tag>') # Parsed using LibXML
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
MultiXml.parser = :nokogiri MultiXml.parser = MultiXml::Parsers::Nokogiri #
|
31
|
-
Same as above MultiXml.parse('<tag>This is the contents</tag>') # Parsed
|
32
|
-
using Nokogiri
|
33
|
-
|
34
|
-
MultiXml.parser = :rexml MultiXml.parser = MultiXml::Parsers::Rexml # Same
|
35
|
-
as above MultiXml.parse('<tag>This is the contents</tag>') # Parsed using
|
36
|
-
REXML
|
31
|
+
MultiXml.parser = :nokogiri
|
32
|
+
MultiXml.parser = MultiXml::Parsers::Nokogiri # Same as above
|
33
|
+
MultiXml.parse('<tag>This is the contents</tag>') # Parsed using Nokogiri
|
37
34
|
|
35
|
+
MultiXml.parser = :rexml
|
36
|
+
MultiXml.parser = MultiXml::Parsers::Rexml # Same as above
|
37
|
+
MultiXml.parse('<tag>This is the contents</tag>') # Parsed using REXML
|
38
|
+
```
|
38
39
|
The `parser` setter takes either a symbol or a class (to allow for custom XML
|
39
40
|
parsers) that responds to `.parse` at the class level.
|
40
41
|
|
@@ -43,56 +44,6 @@ supported parsers already loaded, it will utilize them before attempting to
|
|
43
44
|
load any. When loading, libraries are ordered by speed: first Ox, then LibXML,
|
44
45
|
then Nokogiri, and finally REXML.
|
45
46
|
|
46
|
-
## Contributing
|
47
|
-
In the spirit of [free software][free-sw] , **everyone** is encouraged to help
|
48
|
-
improve this project.
|
49
|
-
|
50
|
-
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
51
|
-
|
52
|
-
Here are some ways *you* can contribute:
|
53
|
-
|
54
|
-
* by using alpha, beta, and prerelease versions
|
55
|
-
* by reporting bugs
|
56
|
-
* by suggesting new features
|
57
|
-
* by writing or editing documentation
|
58
|
-
* by writing specifications
|
59
|
-
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
60
|
-
inconsistent whitespace)
|
61
|
-
* by refactoring code
|
62
|
-
* by resolving [issues][]
|
63
|
-
* by reviewing patches
|
64
|
-
|
65
|
-
[issues]: https://github.com/sferik/multi_xml/issues
|
66
|
-
|
67
|
-
## Submitting an Issue
|
68
|
-
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
69
|
-
submitting a bug report or feature request, check to make sure it hasn't
|
70
|
-
already been submitted. When submitting a bug report, please include a [Gist][]
|
71
|
-
that includes a stack trace and any details that may be necessary to reproduce
|
72
|
-
the bug, including your gem version, Ruby version, and operating system.
|
73
|
-
Ideally, a bug report should include a pull request with failing specs.
|
74
|
-
|
75
|
-
[gist]: https://gist.github.com/
|
76
|
-
|
77
|
-
## Submitting a Pull Request
|
78
|
-
1. [Fork the repository.][fork]
|
79
|
-
2. [Create a topic branch.][branch]
|
80
|
-
3. Add specs for your unimplemented feature or bug fix.
|
81
|
-
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
82
|
-
5. Implement your feature or bug fix.
|
83
|
-
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
84
|
-
7. Run `open coverage/index.html`. If your changes are not completely covered
|
85
|
-
by your tests, return to step 3.
|
86
|
-
8. Add documentation for your feature or bug fix.
|
87
|
-
9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
|
88
|
-
back to step 8.
|
89
|
-
10. Add, commit, and push your changes.
|
90
|
-
11. [Submit a pull request.][pr]
|
91
|
-
|
92
|
-
[fork]: http://help.github.com/fork-a-repo/
|
93
|
-
[branch]: http://learn.github.com/p/branching.html
|
94
|
-
[pr]: http://help.github.com/send-pull-requests/
|
95
|
-
|
96
47
|
## Supported Ruby Versions
|
97
48
|
This library aims to support and is [tested against][travis] the following Ruby
|
98
49
|
implementations:
|
data/Rakefile
CHANGED
data/lib/multi_xml.rb
CHANGED
@@ -7,6 +7,11 @@ require 'yaml'
|
|
7
7
|
|
8
8
|
module MultiXml
|
9
9
|
class ParseError < StandardError; end
|
10
|
+
class DisallowedTypeError < StandardError
|
11
|
+
def initialize(type)
|
12
|
+
super "Disallowed type attribute: #{type.inspect}"
|
13
|
+
end
|
14
|
+
end
|
10
15
|
|
11
16
|
REQUIREMENT_MAP = [
|
12
17
|
['ox', :ox],
|
@@ -54,6 +59,8 @@ module MultiXml
|
|
54
59
|
'Hash' => 'hash'
|
55
60
|
} unless defined?(TYPE_NAMES)
|
56
61
|
|
62
|
+
DISALLOWED_XML_TYPES = %w(symbol yaml)
|
63
|
+
|
57
64
|
class << self
|
58
65
|
# Get the current parser class.
|
59
66
|
def parser
|
@@ -105,6 +112,8 @@ module MultiXml
|
|
105
112
|
# <b>Options</b>
|
106
113
|
#
|
107
114
|
# <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.
|
115
|
+
#
|
116
|
+
# <tt>:disallowed_types</tt> :: Types to disallow from being typecasted. Defaults to `['yaml', 'symbol']`. Use `[]` to allow all types.
|
108
117
|
def parse(xml, options={})
|
109
118
|
xml ||= ''
|
110
119
|
|
@@ -116,7 +125,9 @@ module MultiXml
|
|
116
125
|
return {} if char.nil?
|
117
126
|
xml.ungetc(char)
|
118
127
|
|
119
|
-
hash = typecast_xml_value(undasherize_keys(parser.parse(xml))) || {}
|
128
|
+
hash = typecast_xml_value(undasherize_keys(parser.parse(xml)), options[:disallowed_types]) || {}
|
129
|
+
rescue DisallowedTypeError
|
130
|
+
raise
|
120
131
|
rescue parser.parse_error => error
|
121
132
|
raise ParseError, error.to_s, error.backtrace
|
122
133
|
end
|
@@ -191,9 +202,15 @@ module MultiXml
|
|
191
202
|
end
|
192
203
|
end
|
193
204
|
|
194
|
-
def typecast_xml_value(value)
|
205
|
+
def typecast_xml_value(value, disallowed_types=nil)
|
206
|
+
disallowed_types ||= DISALLOWED_XML_TYPES
|
207
|
+
|
195
208
|
case value
|
196
209
|
when Hash
|
210
|
+
if value.include?('type') && !value['type'].is_a?(Hash) && disallowed_types.include?(value['type'])
|
211
|
+
raise DisallowedTypeError, value['type']
|
212
|
+
end
|
213
|
+
|
197
214
|
if value['type'] == 'array'
|
198
215
|
|
199
216
|
# this commented-out suggestion helps to avoid the multiple attribute
|
@@ -216,9 +233,9 @@ module MultiXml
|
|
216
233
|
else
|
217
234
|
case entries
|
218
235
|
when Array
|
219
|
-
entries.map {|entry| typecast_xml_value(entry)}
|
236
|
+
entries.map {|entry| typecast_xml_value(entry, disallowed_types)}
|
220
237
|
when Hash
|
221
|
-
[typecast_xml_value(entries)]
|
238
|
+
[typecast_xml_value(entries, disallowed_types)]
|
222
239
|
else
|
223
240
|
raise "can't typecast #{entries.class.name}: #{entries.inspect}"
|
224
241
|
end
|
@@ -252,7 +269,7 @@ module MultiXml
|
|
252
269
|
nil
|
253
270
|
else
|
254
271
|
xml_value = value.inject({}) do |hash, (k, v)|
|
255
|
-
hash[k] = typecast_xml_value(v)
|
272
|
+
hash[k] = typecast_xml_value(v, disallowed_types)
|
256
273
|
hash
|
257
274
|
end
|
258
275
|
|
@@ -261,7 +278,7 @@ module MultiXml
|
|
261
278
|
xml_value['file'].is_a?(StringIO) ? xml_value['file'] : xml_value
|
262
279
|
end
|
263
280
|
when Array
|
264
|
-
value.map!{|i| typecast_xml_value(i)}
|
281
|
+
value.map!{|i| typecast_xml_value(i, disallowed_types)}
|
265
282
|
value.length > 1 ? value : value.first
|
266
283
|
when String
|
267
284
|
value
|
data/lib/multi_xml/version.rb
CHANGED
data/multi_xml.gemspec
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path('../lib/multi_xml/version', __FILE__)
|
3
3
|
|
4
|
-
Gem::Specification.new do |
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.add_development_dependency 'kramdown'
|
6
|
+
spec.add_development_dependency 'rake'
|
7
|
+
spec.add_development_dependency 'rspec'
|
8
|
+
spec.add_development_dependency 'simplecov'
|
9
|
+
spec.add_development_dependency 'yard'
|
10
|
+
spec.author = "Erik Michaels-Ober"
|
11
|
+
spec.description = %q{Provides swappable XML backends utilizing LibXML, Nokogiri, Ox, or REXML.}
|
12
|
+
spec.email = 'sferik@gmail.com'
|
13
|
+
spec.files = `git ls-files`.split("\n")
|
14
|
+
spec.homepage = 'https://github.com/sferik/multi_xml'
|
15
|
+
spec.licenses = ['MIT']
|
16
|
+
spec.name = 'multi_xml'
|
17
|
+
spec.platform = Gem::Platform::RUBY
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.summary = %q{A generic swappable back-end for XML parsing}
|
20
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
spec.version = MultiXml::VERSION
|
21
22
|
end
|
data/spec/helper.rb
CHANGED
data/spec/multi_xml_spec.rb
CHANGED
@@ -5,28 +5,28 @@ class MockDecoder; end
|
|
5
5
|
|
6
6
|
describe "MultiXml" do
|
7
7
|
context "Parsers" do
|
8
|
-
it "
|
9
|
-
MultiXml.parser.
|
10
|
-
MultiXml.parser.
|
8
|
+
it "picks a default parser" do
|
9
|
+
expect(MultiXml.parser).to be_kind_of(Module)
|
10
|
+
expect(MultiXml.parser).to respond_to(:parse)
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "defaults to the best available gem" do
|
14
14
|
pending
|
15
|
-
MultiXml.parser.name.
|
15
|
+
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Rexml')
|
16
16
|
require 'nokogiri'
|
17
|
-
MultiXml.parser.name.
|
17
|
+
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Nokogiri')
|
18
18
|
require 'libxml'
|
19
|
-
MultiXml.parser.name.
|
19
|
+
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Libxml')
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "is settable via a symbol" do
|
23
23
|
MultiXml.parser = :nokogiri
|
24
|
-
MultiXml.parser.name.
|
24
|
+
expect(MultiXml.parser.name).to eq('MultiXml::Parsers::Nokogiri')
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "is settable via a class" do
|
28
28
|
MultiXml.parser = MockDecoder
|
29
|
-
MultiXml.parser.name.
|
29
|
+
expect(MultiXml.parser.name).to eq('MockDecoder')
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -37,7 +37,7 @@ describe "MultiXml" do
|
|
37
37
|
begin
|
38
38
|
require parser.last
|
39
39
|
context "#{parser.first} parser" do
|
40
|
-
|
40
|
+
it_behaves_like "a parser", parser.first
|
41
41
|
end
|
42
42
|
rescue LoadError => e
|
43
43
|
puts "Tests not run for #{parser.first} due to a LoadError"
|
@@ -14,8 +14,8 @@ shared_examples_for "a parser" do |parser|
|
|
14
14
|
@xml = ''
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
MultiXml.parse(@xml).
|
17
|
+
it "returns an empty Hash" do
|
18
|
+
expect(MultiXml.parse(@xml)).to eq({})
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,8 +24,8 @@ shared_examples_for "a parser" do |parser|
|
|
24
24
|
@xml = ' '
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
28
|
-
MultiXml.parse(@xml).
|
27
|
+
it "returns an empty Hash" do
|
28
|
+
expect(MultiXml.parse(@xml)).to eq({})
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,10 +34,8 @@ shared_examples_for "a parser" do |parser|
|
|
34
34
|
@xml = '<open></close>'
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
38
|
-
|
39
|
-
MultiXml.parse(@xml)
|
40
|
-
end.should raise_error(MultiXml::ParseError)
|
37
|
+
it "raises MultiXml::ParseError" do
|
38
|
+
expect{MultiXml.parse(@xml)}.to raise_error(MultiXml::ParseError)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
@@ -46,8 +44,8 @@ shared_examples_for "a parser" do |parser|
|
|
46
44
|
@xml = '<user/>'
|
47
45
|
end
|
48
46
|
|
49
|
-
it "
|
50
|
-
MultiXml.parse(@xml).
|
47
|
+
it "parses correctly" do
|
48
|
+
expect(MultiXml.parse(@xml)).to eq({'user' => nil})
|
51
49
|
end
|
52
50
|
|
53
51
|
context "with CDATA" do
|
@@ -55,8 +53,8 @@ shared_examples_for "a parser" do |parser|
|
|
55
53
|
@xml = '<user><![CDATA[Erik Michaels-Ober]]></user>'
|
56
54
|
end
|
57
55
|
|
58
|
-
it "
|
59
|
-
MultiXml.parse(@xml)['user'].
|
56
|
+
it "returns the correct CDATA" do
|
57
|
+
expect(MultiXml.parse(@xml)['user']).to eq("Erik Michaels-Ober")
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -65,8 +63,8 @@ shared_examples_for "a parser" do |parser|
|
|
65
63
|
@xml = '<user>Erik Michaels-Ober</user>'
|
66
64
|
end
|
67
65
|
|
68
|
-
it "
|
69
|
-
MultiXml.parse(@xml)['user'].
|
66
|
+
it "returns the correct content" do
|
67
|
+
expect(MultiXml.parse(@xml)['user']).to eq("Erik Michaels-Ober")
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
@@ -75,8 +73,8 @@ shared_examples_for "a parser" do |parser|
|
|
75
73
|
@xml = '<user name="Erik Michaels-Ober"/>'
|
76
74
|
end
|
77
75
|
|
78
|
-
it "
|
79
|
-
MultiXml.parse(@xml)['user']['name'].
|
76
|
+
it "returns the correct attribute" do
|
77
|
+
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
@@ -85,9 +83,9 @@ shared_examples_for "a parser" do |parser|
|
|
85
83
|
@xml = '<user name="Erik Michaels-Ober" screen_name="sferik"/>'
|
86
84
|
end
|
87
85
|
|
88
|
-
it "
|
89
|
-
MultiXml.parse(@xml)['user']['name'].
|
90
|
-
MultiXml.parse(@xml)['user']['screen_name'].
|
86
|
+
it "returns the correct attributes" do
|
87
|
+
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
|
88
|
+
expect(MultiXml.parse(@xml)['user']['screen_name']).to eq("sferik")
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
@@ -96,8 +94,8 @@ shared_examples_for "a parser" do |parser|
|
|
96
94
|
@xml = '<user><name>Erik Michaels-Ober</name></user>'
|
97
95
|
end
|
98
96
|
|
99
|
-
it "
|
100
|
-
MultiXml.parse(@xml, :symbolize_keys => true).
|
97
|
+
it "symbolizes keys" do
|
98
|
+
expect(MultiXml.parse(@xml, :symbolize_keys => true)).to eq({:user => {:name => "Erik Michaels-Ober"}})
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
@@ -107,8 +105,8 @@ shared_examples_for "a parser" do |parser|
|
|
107
105
|
@xml = '<tag>true</tag>'
|
108
106
|
end
|
109
107
|
|
110
|
-
it "
|
111
|
-
MultiXml.parse(@xml)['tag'].
|
108
|
+
it "returns true" do
|
109
|
+
expect(MultiXml.parse(@xml)['tag']).to be_true
|
112
110
|
end
|
113
111
|
end
|
114
112
|
|
@@ -118,8 +116,8 @@ shared_examples_for "a parser" do |parser|
|
|
118
116
|
@xml = '<tag>false</tag>'
|
119
117
|
end
|
120
118
|
|
121
|
-
it "
|
122
|
-
MultiXml.parse(@xml)['tag'].
|
119
|
+
it "returns false" do
|
120
|
+
expect(MultiXml.parse(@xml)['tag']).to be_false
|
123
121
|
end
|
124
122
|
end
|
125
123
|
|
@@ -129,12 +127,12 @@ shared_examples_for "a parser" do |parser|
|
|
129
127
|
@xml = '<id>1</id>'
|
130
128
|
end
|
131
129
|
|
132
|
-
it "
|
133
|
-
MultiXml.parse(@xml)['id'].
|
130
|
+
it "returns a Fixnum" do
|
131
|
+
expect(MultiXml.parse(@xml)['id']).to be_a(Fixnum)
|
134
132
|
end
|
135
133
|
|
136
|
-
it "
|
137
|
-
MultiXml.parse(@xml)['id'].
|
134
|
+
it "returns the correct number" do
|
135
|
+
expect(MultiXml.parse(@xml)['id']).to eq(1)
|
138
136
|
end
|
139
137
|
end
|
140
138
|
|
@@ -144,21 +142,21 @@ shared_examples_for "a parser" do |parser|
|
|
144
142
|
@xml = '<tag_id>1</tag_id>'
|
145
143
|
end
|
146
144
|
|
147
|
-
it "
|
148
|
-
MultiXml.parse(@xml)['tag_id'].
|
145
|
+
it "returns a Fixnum" do
|
146
|
+
expect(MultiXml.parse(@xml)['tag_id']).to be_a(Fixnum)
|
149
147
|
end
|
150
148
|
|
151
|
-
it "
|
152
|
-
MultiXml.parse(@xml)['tag_id'].
|
149
|
+
it "returns the correct number" do
|
150
|
+
expect(MultiXml.parse(@xml)['tag_id']).to eq(1)
|
153
151
|
end
|
154
152
|
end
|
155
153
|
|
156
154
|
context "with an attribute type=\"boolean\"" do
|
157
155
|
%w(true false).each do |boolean|
|
158
156
|
context "when #{boolean}" do
|
159
|
-
it "
|
157
|
+
it "returns #{boolean}" do
|
160
158
|
xml = "<tag type=\"boolean\">#{boolean}</tag>"
|
161
|
-
MultiXml.parse(xml)['tag'].
|
159
|
+
expect(MultiXml.parse(xml)['tag']).to instance_eval("be_#{boolean}")
|
162
160
|
end
|
163
161
|
end
|
164
162
|
end
|
@@ -168,8 +166,8 @@ shared_examples_for "a parser" do |parser|
|
|
168
166
|
@xml = '<tag type="boolean">1</tag>'
|
169
167
|
end
|
170
168
|
|
171
|
-
it "
|
172
|
-
MultiXml.parse(@xml)['tag'].
|
169
|
+
it "returns true" do
|
170
|
+
expect(MultiXml.parse(@xml)['tag']).to be_true
|
173
171
|
end
|
174
172
|
end
|
175
173
|
|
@@ -178,8 +176,8 @@ shared_examples_for "a parser" do |parser|
|
|
178
176
|
@xml = '<tag type="boolean">0</tag>'
|
179
177
|
end
|
180
178
|
|
181
|
-
it "
|
182
|
-
MultiXml.parse(@xml)['tag'].
|
179
|
+
it "returns false" do
|
180
|
+
expect(MultiXml.parse(@xml)['tag']).to be_false
|
183
181
|
end
|
184
182
|
end
|
185
183
|
end
|
@@ -190,16 +188,16 @@ shared_examples_for "a parser" do |parser|
|
|
190
188
|
@xml = '<tag type="integer">1</tag>'
|
191
189
|
end
|
192
190
|
|
193
|
-
it "
|
194
|
-
MultiXml.parse(@xml)['tag'].
|
191
|
+
it "returns a Fixnum" do
|
192
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Fixnum)
|
195
193
|
end
|
196
194
|
|
197
|
-
it "
|
198
|
-
MultiXml.parse(@xml)['tag'].
|
195
|
+
it "returns a positive number" do
|
196
|
+
expect(MultiXml.parse(@xml)['tag']).to be > 0
|
199
197
|
end
|
200
198
|
|
201
|
-
it "
|
202
|
-
MultiXml.parse(@xml)['tag'].
|
199
|
+
it "returns the correct number" do
|
200
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(1)
|
203
201
|
end
|
204
202
|
end
|
205
203
|
|
@@ -208,16 +206,16 @@ shared_examples_for "a parser" do |parser|
|
|
208
206
|
@xml = '<tag type="integer">-1</tag>'
|
209
207
|
end
|
210
208
|
|
211
|
-
it "
|
212
|
-
MultiXml.parse(@xml)['tag'].
|
209
|
+
it "returns a Fixnum" do
|
210
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Fixnum)
|
213
211
|
end
|
214
212
|
|
215
|
-
it "
|
216
|
-
MultiXml.parse(@xml)['tag'].
|
213
|
+
it "returns a negative number" do
|
214
|
+
expect(MultiXml.parse(@xml)['tag']).to be < 0
|
217
215
|
end
|
218
216
|
|
219
|
-
it "
|
220
|
-
MultiXml.parse(@xml)['tag'].
|
217
|
+
it "returns the correct number" do
|
218
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(-1)
|
221
219
|
end
|
222
220
|
end
|
223
221
|
end
|
@@ -227,12 +225,12 @@ shared_examples_for "a parser" do |parser|
|
|
227
225
|
@xml = '<tag type="string"></tag>'
|
228
226
|
end
|
229
227
|
|
230
|
-
it "
|
231
|
-
MultiXml.parse(@xml)['tag'].
|
228
|
+
it "returns a String" do
|
229
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(String)
|
232
230
|
end
|
233
231
|
|
234
|
-
it "
|
235
|
-
MultiXml.parse(@xml)['tag'].
|
232
|
+
it "returns the correct string" do
|
233
|
+
expect(MultiXml.parse(@xml)['tag']).to eq("")
|
236
234
|
end
|
237
235
|
end
|
238
236
|
|
@@ -241,12 +239,12 @@ shared_examples_for "a parser" do |parser|
|
|
241
239
|
@xml = '<tag type="date">1970-01-01</tag>'
|
242
240
|
end
|
243
241
|
|
244
|
-
it "
|
245
|
-
MultiXml.parse(@xml)['tag'].
|
242
|
+
it "returns a Date" do
|
243
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Date)
|
246
244
|
end
|
247
245
|
|
248
|
-
it "
|
249
|
-
MultiXml.parse(@xml)['tag'].
|
246
|
+
it "returns the correct date" do
|
247
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(Date.parse('1970-01-01'))
|
250
248
|
end
|
251
249
|
end
|
252
250
|
|
@@ -255,12 +253,12 @@ shared_examples_for "a parser" do |parser|
|
|
255
253
|
@xml = '<tag type="datetime">1970-01-01 00:00</tag>'
|
256
254
|
end
|
257
255
|
|
258
|
-
it "
|
259
|
-
MultiXml.parse(@xml)['tag'].
|
256
|
+
it "returns a Time" do
|
257
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Time)
|
260
258
|
end
|
261
259
|
|
262
|
-
it "
|
263
|
-
MultiXml.parse(@xml)['tag'].
|
260
|
+
it "returns the correct time" do
|
261
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(Time.parse('1970-01-01 00:00'))
|
264
262
|
end
|
265
263
|
end
|
266
264
|
|
@@ -269,12 +267,12 @@ shared_examples_for "a parser" do |parser|
|
|
269
267
|
@xml = '<tag type="datetime">1970-01-01 00:00</tag>'
|
270
268
|
end
|
271
269
|
|
272
|
-
it "
|
273
|
-
MultiXml.parse(@xml)['tag'].
|
270
|
+
it "returns a Time" do
|
271
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Time)
|
274
272
|
end
|
275
273
|
|
276
|
-
it "
|
277
|
-
MultiXml.parse(@xml)['tag'].
|
274
|
+
it "returns the correct time" do
|
275
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(Time.parse('1970-01-01 00:00'))
|
278
276
|
end
|
279
277
|
end
|
280
278
|
|
@@ -283,12 +281,12 @@ shared_examples_for "a parser" do |parser|
|
|
283
281
|
@xml = '<tag type="double">3.14159265358979</tag>'
|
284
282
|
end
|
285
283
|
|
286
|
-
it "
|
287
|
-
MultiXml.parse(@xml)['tag'].
|
284
|
+
it "returns a Float" do
|
285
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(Float)
|
288
286
|
end
|
289
287
|
|
290
|
-
it "
|
291
|
-
MultiXml.parse(@xml)['tag'].
|
288
|
+
it "returns the correct number" do
|
289
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(3.14159265358979)
|
292
290
|
end
|
293
291
|
end
|
294
292
|
|
@@ -297,12 +295,12 @@ shared_examples_for "a parser" do |parser|
|
|
297
295
|
@xml = '<tag type="decimal">3.14159265358979</tag>'
|
298
296
|
end
|
299
297
|
|
300
|
-
it "
|
301
|
-
MultiXml.parse(@xml)['tag'].
|
298
|
+
it "returns a BigDecimal" do
|
299
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(BigDecimal)
|
302
300
|
end
|
303
301
|
|
304
|
-
it "
|
305
|
-
MultiXml.parse(@xml)['tag'].
|
302
|
+
it "returns the correct number" do
|
303
|
+
expect(MultiXml.parse(@xml)['tag']).to eq(3.14159265358979)
|
306
304
|
end
|
307
305
|
end
|
308
306
|
|
@@ -311,26 +309,40 @@ shared_examples_for "a parser" do |parser|
|
|
311
309
|
@xml = '<tag type="base64Binary">aW1hZ2UucG5n</tag>'
|
312
310
|
end
|
313
311
|
|
314
|
-
it "
|
315
|
-
MultiXml.parse(@xml)['tag'].
|
312
|
+
it "returns a String" do
|
313
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(String)
|
316
314
|
end
|
317
315
|
|
318
|
-
it "
|
319
|
-
MultiXml.parse(@xml)['tag'].
|
316
|
+
it "returns the correct string" do
|
317
|
+
expect(MultiXml.parse(@xml)['tag']).to eq("image.png")
|
320
318
|
end
|
321
319
|
end
|
322
320
|
|
323
321
|
context "with an attribute type=\"yaml\"" do
|
324
322
|
before do
|
325
|
-
@xml = "<tag type=\"yaml\">--- \n1:
|
323
|
+
@xml = "<tag type=\"yaml\">--- \n1: returns an integer\n:message: Have a nice day\narray: \n- has-dashes: true\n has_underscores: true\n</tag>"
|
326
324
|
end
|
327
325
|
|
328
|
-
it "
|
329
|
-
MultiXml.parse(@xml)['tag'].
|
326
|
+
it "raises MultiXML::DisallowedTypeError by default" do
|
327
|
+
expect{ MultiXml.parse(@xml)['tag'] }.to raise_error(MultiXml::DisallowedTypeError)
|
330
328
|
end
|
331
329
|
|
332
|
-
it "
|
333
|
-
MultiXml.parse(@xml)['tag'].
|
330
|
+
it "returns the correctly parsed YAML when the type is allowed" do
|
331
|
+
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to eq({:message => "Have a nice day", 1 => "returns an integer", "array" => [{"has-dashes" => true, "has_underscores" => true}]})
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context "with an attribute type=\"symbol\"" do
|
336
|
+
before do
|
337
|
+
@xml = "<tag type=\"symbol\">my_symbol</tag>"
|
338
|
+
end
|
339
|
+
|
340
|
+
it "raises MultiXML::DisallowedTypeError" do
|
341
|
+
expect{ MultiXml.parse(@xml)['tag'] }.to raise_error(MultiXml::DisallowedTypeError)
|
342
|
+
end
|
343
|
+
|
344
|
+
it "returns the correctly parsed Symbol when the type is allowed" do
|
345
|
+
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to eq(:my_symbol)
|
334
346
|
end
|
335
347
|
end
|
336
348
|
|
@@ -339,20 +351,20 @@ shared_examples_for "a parser" do |parser|
|
|
339
351
|
@xml = '<tag type="file" name="data.txt" content_type="text/plain">ZGF0YQ==</tag>'
|
340
352
|
end
|
341
353
|
|
342
|
-
it "
|
343
|
-
MultiXml.parse(@xml)['tag'].
|
354
|
+
it "returns a StringIO" do
|
355
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(StringIO)
|
344
356
|
end
|
345
357
|
|
346
|
-
it "
|
347
|
-
MultiXml.parse(@xml)['tag'].string.
|
358
|
+
it "is decoded correctly" do
|
359
|
+
expect(MultiXml.parse(@xml)['tag'].string).to eq('data')
|
348
360
|
end
|
349
361
|
|
350
|
-
it "
|
351
|
-
MultiXml.parse(@xml)['tag'].original_filename.
|
362
|
+
it "has the correct file name" do
|
363
|
+
expect(MultiXml.parse(@xml)['tag'].original_filename).to eq('data.txt')
|
352
364
|
end
|
353
365
|
|
354
|
-
it "
|
355
|
-
MultiXml.parse(@xml)['tag'].content_type.
|
366
|
+
it "has the correct content type" do
|
367
|
+
expect(MultiXml.parse(@xml)['tag'].content_type).to eq('text/plain')
|
356
368
|
end
|
357
369
|
|
358
370
|
context "with missing name and content type" do
|
@@ -360,20 +372,20 @@ shared_examples_for "a parser" do |parser|
|
|
360
372
|
@xml = '<tag type="file">ZGF0YQ==</tag>'
|
361
373
|
end
|
362
374
|
|
363
|
-
it "
|
364
|
-
MultiXml.parse(@xml)['tag'].
|
375
|
+
it "returns a StringIO" do
|
376
|
+
expect(MultiXml.parse(@xml)['tag']).to be_a(StringIO)
|
365
377
|
end
|
366
378
|
|
367
|
-
it "
|
368
|
-
MultiXml.parse(@xml)['tag'].string.
|
379
|
+
it "is decoded correctly" do
|
380
|
+
expect(MultiXml.parse(@xml)['tag'].string).to eq('data')
|
369
381
|
end
|
370
382
|
|
371
|
-
it "
|
372
|
-
MultiXml.parse(@xml)['tag'].original_filename.
|
383
|
+
it "has the default file name" do
|
384
|
+
expect(MultiXml.parse(@xml)['tag'].original_filename).to eq('untitled')
|
373
385
|
end
|
374
386
|
|
375
|
-
it "
|
376
|
-
MultiXml.parse(@xml)['tag'].content_type.
|
387
|
+
it "has the default content type" do
|
388
|
+
expect(MultiXml.parse(@xml)['tag'].content_type).to eq('application/octet-stream')
|
377
389
|
end
|
378
390
|
end
|
379
391
|
end
|
@@ -383,12 +395,12 @@ shared_examples_for "a parser" do |parser|
|
|
383
395
|
@xml = '<users type="array"><user>Erik Michaels-Ober</user><user>Wynn Netherland</user></users>'
|
384
396
|
end
|
385
397
|
|
386
|
-
it "
|
387
|
-
MultiXml.parse(@xml)['users'].
|
398
|
+
it "returns an Array" do
|
399
|
+
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
|
388
400
|
end
|
389
401
|
|
390
|
-
it "
|
391
|
-
MultiXml.parse(@xml)['users'].
|
402
|
+
it "returns the correct array" do
|
403
|
+
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober", "Wynn Netherland"])
|
392
404
|
end
|
393
405
|
end
|
394
406
|
|
@@ -397,12 +409,12 @@ shared_examples_for "a parser" do |parser|
|
|
397
409
|
@xml = '<users type="array" foo="bar"><user>Erik Michaels-Ober</user><user>Wynn Netherland</user></users>'
|
398
410
|
end
|
399
411
|
|
400
|
-
it "
|
401
|
-
MultiXml.parse(@xml)['users'].
|
412
|
+
it "returns an Array" do
|
413
|
+
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
|
402
414
|
end
|
403
415
|
|
404
|
-
it "
|
405
|
-
MultiXml.parse(@xml)['users'].
|
416
|
+
it "returns the correct array" do
|
417
|
+
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober", "Wynn Netherland"])
|
406
418
|
end
|
407
419
|
end
|
408
420
|
|
@@ -411,23 +423,39 @@ shared_examples_for "a parser" do |parser|
|
|
411
423
|
@xml = '<users type="array"><user>Erik Michaels-Ober</user></users>'
|
412
424
|
end
|
413
425
|
|
414
|
-
it "
|
415
|
-
MultiXml.parse(@xml)['users'].
|
426
|
+
it "returns an Array" do
|
427
|
+
expect(MultiXml.parse(@xml)['users']).to be_a(Array)
|
416
428
|
end
|
417
429
|
|
418
|
-
it "
|
419
|
-
MultiXml.parse(@xml)['users'].
|
430
|
+
it "returns the correct array" do
|
431
|
+
expect(MultiXml.parse(@xml)['users']).to eq(["Erik Michaels-Ober"])
|
420
432
|
end
|
421
433
|
end
|
422
434
|
|
423
|
-
%w(integer boolean date datetime
|
435
|
+
%w(integer boolean date datetime file).each do |type|
|
424
436
|
context "with an empty attribute type=\"#{type}\"" do
|
425
437
|
before do
|
426
438
|
@xml = "<tag type=\"#{type}\"/>"
|
427
439
|
end
|
428
440
|
|
429
|
-
it "
|
430
|
-
MultiXml.parse(@xml)['tag'].
|
441
|
+
it "returns nil" do
|
442
|
+
expect(MultiXml.parse(@xml)['tag']).to be_nil
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
%w{yaml symbol}.each do |type|
|
448
|
+
context "with an empty attribute type=\"#{type}\"" do
|
449
|
+
before do
|
450
|
+
@xml = "<tag type=\"#{type}\"/>"
|
451
|
+
end
|
452
|
+
|
453
|
+
it "raises MultiXml::DisallowedTypeError by default" do
|
454
|
+
expect{ MultiXml.parse(@xml)['tag']}.to raise_error(MultiXml::DisallowedTypeError)
|
455
|
+
end
|
456
|
+
|
457
|
+
it "returns nil when the type is allowed" do
|
458
|
+
expect(MultiXml.parse(@xml, :disallowed_types => [])['tag']).to be_nil
|
431
459
|
end
|
432
460
|
end
|
433
461
|
end
|
@@ -437,8 +465,8 @@ shared_examples_for "a parser" do |parser|
|
|
437
465
|
@xml = '<tag type="array"/>'
|
438
466
|
end
|
439
467
|
|
440
|
-
it "
|
441
|
-
MultiXml.parse(@xml)['tag'].
|
468
|
+
it "returns an empty Array" do
|
469
|
+
expect(MultiXml.parse(@xml)['tag']).to eq([])
|
442
470
|
end
|
443
471
|
|
444
472
|
context "with whitespace" do
|
@@ -446,8 +474,8 @@ shared_examples_for "a parser" do |parser|
|
|
446
474
|
@xml = '<tag type="array"> </tag>'
|
447
475
|
end
|
448
476
|
|
449
|
-
it "
|
450
|
-
MultiXml.parse(@xml)['tag'].
|
477
|
+
it "returns an empty Array" do
|
478
|
+
expect(MultiXml.parse(@xml)['tag']).to eq([])
|
451
479
|
end
|
452
480
|
end
|
453
481
|
end
|
@@ -464,19 +492,19 @@ shared_examples_for "a parser" do |parser|
|
|
464
492
|
end
|
465
493
|
|
466
494
|
context "in content" do
|
467
|
-
it "
|
495
|
+
it "returns unescaped XML entities" do
|
468
496
|
@xml_entities.each do |key, value|
|
469
497
|
xml = "<tag>#{value}</tag>"
|
470
|
-
MultiXml.parse(xml)['tag'].
|
498
|
+
expect(MultiXml.parse(xml)['tag']).to eq(key)
|
471
499
|
end
|
472
500
|
end
|
473
501
|
end
|
474
502
|
|
475
503
|
context "in attribute" do
|
476
|
-
it "
|
504
|
+
it "returns unescaped XML entities" do
|
477
505
|
@xml_entities.each do |key, value|
|
478
506
|
xml = "<tag attribute=\"#{value}\"/>"
|
479
|
-
MultiXml.parse(xml)['tag']['attribute'].
|
507
|
+
expect(MultiXml.parse(xml)['tag']['attribute']).to eq(key)
|
480
508
|
end
|
481
509
|
end
|
482
510
|
end
|
@@ -488,8 +516,8 @@ shared_examples_for "a parser" do |parser|
|
|
488
516
|
@xml = '<tag-1/>'
|
489
517
|
end
|
490
518
|
|
491
|
-
it "
|
492
|
-
MultiXml.parse(@xml).keys.
|
519
|
+
it "returns undasherize tag" do
|
520
|
+
expect(MultiXml.parse(@xml).keys).to include('tag_1')
|
493
521
|
end
|
494
522
|
end
|
495
523
|
|
@@ -498,8 +526,8 @@ shared_examples_for "a parser" do |parser|
|
|
498
526
|
@xml = '<tag attribute-1="1"></tag>'
|
499
527
|
end
|
500
528
|
|
501
|
-
it "
|
502
|
-
MultiXml.parse(@xml)['tag'].keys.
|
529
|
+
it "returns undasherize attribute" do
|
530
|
+
expect(MultiXml.parse(@xml)['tag'].keys).to include('attribute_1')
|
503
531
|
end
|
504
532
|
end
|
505
533
|
|
@@ -509,8 +537,8 @@ shared_examples_for "a parser" do |parser|
|
|
509
537
|
@xml = '<users><user name="Erik Michaels-Ober"/></users>'
|
510
538
|
end
|
511
539
|
|
512
|
-
it "
|
513
|
-
MultiXml.parse(@xml)['users']['user']['name'].
|
540
|
+
it "returns the correct attributes" do
|
541
|
+
expect(MultiXml.parse(@xml)['users']['user']['name']).to eq("Erik Michaels-Ober")
|
514
542
|
end
|
515
543
|
end
|
516
544
|
|
@@ -519,8 +547,8 @@ shared_examples_for "a parser" do |parser|
|
|
519
547
|
@xml = '<user><name>Erik Michaels-Ober</name></user>'
|
520
548
|
end
|
521
549
|
|
522
|
-
it "
|
523
|
-
MultiXml.parse(@xml)['user']['name'].
|
550
|
+
it "returns the correct text" do
|
551
|
+
expect(MultiXml.parse(@xml)['user']['name']).to eq("Erik Michaels-Ober")
|
524
552
|
end
|
525
553
|
end
|
526
554
|
|
@@ -529,8 +557,8 @@ shared_examples_for "a parser" do |parser|
|
|
529
557
|
@xml = '<user type="admin"><name>Erik Michaels-Ober</name></user>'
|
530
558
|
end
|
531
559
|
|
532
|
-
it "
|
533
|
-
MultiXml.parse(@xml)['user']['type'].
|
560
|
+
it "passes through the type" do
|
561
|
+
expect(MultiXml.parse(@xml)['user']['type']).to eq('admin')
|
534
562
|
end
|
535
563
|
end
|
536
564
|
|
@@ -546,11 +574,11 @@ shared_examples_for "a parser" do |parser|
|
|
546
574
|
@parsed_xml = MultiXml.parse(@xml)
|
547
575
|
end
|
548
576
|
|
549
|
-
it "
|
550
|
-
@parsed_xml['options']['value'][0]['__content__'].
|
551
|
-
@parsed_xml['options']['value'][0]['currency'].
|
552
|
-
@parsed_xml['options']['value'][1]['__content__'].
|
553
|
-
@parsed_xml['options']['value'][1]['number'].
|
577
|
+
it "adds the attributes to the value hash" do
|
578
|
+
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
|
579
|
+
expect(@parsed_xml['options']['value'][0]['currency']).to eq('USD')
|
580
|
+
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
|
581
|
+
expect(@parsed_xml['options']['value'][1]['number']).to eq('percent')
|
554
582
|
end
|
555
583
|
end
|
556
584
|
|
@@ -566,13 +594,13 @@ shared_examples_for "a parser" do |parser|
|
|
566
594
|
@parsed_xml = MultiXml.parse(@xml)
|
567
595
|
end
|
568
596
|
|
569
|
-
it "
|
570
|
-
@parsed_xml['options']['value'][0]['__content__'].
|
571
|
-
@parsed_xml['options']['value'][0]['type'].
|
572
|
-
@parsed_xml['options']['value'][1]['__content__'].
|
573
|
-
@parsed_xml['options']['value'][1]['type'].
|
574
|
-
@parsed_xml['options']['value'][2]['__content__'].
|
575
|
-
@parsed_xml['options']['value'][2]['currency'].
|
597
|
+
it "adds the attributes to the value hash passing through the type" do
|
598
|
+
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
|
599
|
+
expect(@parsed_xml['options']['value'][0]['type']).to eq('USD')
|
600
|
+
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
|
601
|
+
expect(@parsed_xml['options']['value'][1]['type']).to eq('percent')
|
602
|
+
expect(@parsed_xml['options']['value'][2]['__content__']).to eq('123')
|
603
|
+
expect(@parsed_xml['options']['value'][2]['currency']).to eq('USD')
|
576
604
|
end
|
577
605
|
end
|
578
606
|
|
@@ -588,12 +616,12 @@ shared_examples_for "a parser" do |parser|
|
|
588
616
|
@parsed_xml = MultiXml.parse(@xml)
|
589
617
|
end
|
590
618
|
|
591
|
-
it "
|
592
|
-
@parsed_xml['options']['value'][0]['__content__'].
|
593
|
-
@parsed_xml['options']['value'][0]['type'].
|
594
|
-
@parsed_xml['options']['value'][1]['__content__'].
|
595
|
-
@parsed_xml['options']['value'][1]['type'].
|
596
|
-
@parsed_xml['options']['value'][2].
|
619
|
+
it "adds the attributes to the value hash passing through the type" do
|
620
|
+
expect(@parsed_xml['options']['value'][0]['__content__']).to eq('123')
|
621
|
+
expect(@parsed_xml['options']['value'][0]['type']).to eq('USD')
|
622
|
+
expect(@parsed_xml['options']['value'][1]['__content__']).to eq('0.123')
|
623
|
+
expect(@parsed_xml['options']['value'][1]['type']).to eq('percent')
|
624
|
+
expect(@parsed_xml['options']['value'][2]).to eq('123')
|
597
625
|
end
|
598
626
|
end
|
599
627
|
|
@@ -607,9 +635,9 @@ shared_examples_for "a parser" do |parser|
|
|
607
635
|
@parsed_xml = MultiXml.parse(@xml)
|
608
636
|
end
|
609
637
|
|
610
|
-
it "
|
611
|
-
@parsed_xml['options']['value']['__content__'].
|
612
|
-
@parsed_xml['options']['value']['number'].
|
638
|
+
it "adds the the non-type attribute and remove the recognized type attribute and do the typecast" do
|
639
|
+
expect(@parsed_xml['options']['value']['__content__']).to eq(123)
|
640
|
+
expect(@parsed_xml['options']['value']['number']).to eq('USD')
|
613
641
|
end
|
614
642
|
end
|
615
643
|
|
@@ -623,10 +651,10 @@ shared_examples_for "a parser" do |parser|
|
|
623
651
|
@parsed_xml = MultiXml.parse(@xml)
|
624
652
|
end
|
625
653
|
|
626
|
-
it "
|
627
|
-
@parsed_xml['options']['value']['__content__'].
|
628
|
-
@parsed_xml['options']['value']['number'].
|
629
|
-
@parsed_xml['options']['value']['type'].
|
654
|
+
it "adds the the non-type attributes and type attribute to the value hash" do
|
655
|
+
expect(@parsed_xml['options']['value']['__content__']).to eq('123')
|
656
|
+
expect(@parsed_xml['options']['value']['number']).to eq('USD')
|
657
|
+
expect(@parsed_xml['options']['value']['type']).to eq('currency')
|
630
658
|
end
|
631
659
|
end
|
632
660
|
end
|
@@ -640,8 +668,8 @@ shared_examples_for "a parser" do |parser|
|
|
640
668
|
XML
|
641
669
|
end
|
642
670
|
|
643
|
-
it "
|
644
|
-
MultiXml.parse(@xml).
|
671
|
+
it "parses correctly" do
|
672
|
+
expect(MultiXml.parse(@xml)).to eq({"user" => {"name" => "Erik Michaels-Ober"}})
|
645
673
|
end
|
646
674
|
end
|
647
675
|
|
@@ -651,8 +679,8 @@ shared_examples_for "a parser" do |parser|
|
|
651
679
|
@xml = '<users><user name="Erik Michaels-Ober"><status text="Hello"/></user></users>'
|
652
680
|
end
|
653
681
|
|
654
|
-
it "
|
655
|
-
MultiXml.parse(@xml).
|
682
|
+
it "parses correctly" do
|
683
|
+
expect(MultiXml.parse(@xml)).to eq({"users" => {"user" => {"name" => "Erik Michaels-Ober", "status" => {"text" => "Hello"}}}})
|
656
684
|
end
|
657
685
|
end
|
658
686
|
end
|
@@ -662,12 +690,12 @@ shared_examples_for "a parser" do |parser|
|
|
662
690
|
@xml = '<users><user>Erik Michaels-Ober</user><user>Wynn Netherland</user></users>'
|
663
691
|
end
|
664
692
|
|
665
|
-
it "
|
666
|
-
MultiXml.parse(@xml)['users']['user'].
|
693
|
+
it "returns an Array" do
|
694
|
+
expect(MultiXml.parse(@xml)['users']['user']).to be_a(Array)
|
667
695
|
end
|
668
696
|
|
669
|
-
it "
|
670
|
-
MultiXml.parse(@xml).
|
697
|
+
it "parses correctly" do
|
698
|
+
expect(MultiXml.parse(@xml)).to eq({"users" => {"user" => ["Erik Michaels-Ober", "Wynn Netherland"]}})
|
671
699
|
end
|
672
700
|
end
|
673
701
|
|