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
@@ -8,30 +8,30 @@ describe ROXML, "under ActiveRecord" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should be parsed" do
|
11
|
-
@route.
|
12
|
-
@route.
|
11
|
+
expect(@route).to_not eq(nil)
|
12
|
+
expect(@route).to be_an_instance_of(Route)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "xml attributes" do
|
16
16
|
it "should extract xml attributes" do
|
17
|
-
@route.totalHg.
|
18
|
-
@route.lonlatx.
|
19
|
-
@route.lonlaty.
|
20
|
-
@route.grcenter.
|
21
|
-
@route.totalMins.
|
22
|
-
@route.totalDist.
|
17
|
+
expect(@route.totalHg).to eq("640")
|
18
|
+
expect(@route.lonlatx).to eq("357865")
|
19
|
+
expect(@route.lonlaty).to eq("271635")
|
20
|
+
expect(@route.grcenter).to eq("SH 71635 57865")
|
21
|
+
expect(@route.totalMins).to eq("235.75000000000003")
|
22
|
+
expect(@route.totalDist).to eq("11185.321521477119")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "xml sub-objects" do
|
27
27
|
it "should extract xml sub-objects" do
|
28
|
-
@route.
|
29
|
-
@route.waypoints.each {|waypoint| waypoint.
|
28
|
+
expect(@route.waypoints.size).to eq(6)
|
29
|
+
@route.waypoints.each {|waypoint| expect(waypoint).to be_an_instance_of(Waypoint)}
|
30
30
|
end
|
31
31
|
it "should be usable as a ActiveRecord object" do
|
32
|
-
Waypoint.count.
|
32
|
+
expect(Waypoint.count).to eq(0)
|
33
33
|
@route.save!
|
34
|
-
Waypoint.count.
|
34
|
+
expect(Waypoint.count).to eq(6)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -8,26 +8,26 @@ describe PITA::ItemSearchResponse do
|
|
8
8
|
|
9
9
|
describe "#total_results" do
|
10
10
|
it "should be parsed as a number" do
|
11
|
-
@response.total_results.
|
11
|
+
expect(@response.total_results).to be > 0
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#total_pages" do
|
16
16
|
it "should be parsed as a number" do
|
17
|
-
@response.total_pages.
|
17
|
+
expect(@response.total_pages).to be > 0
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#items" do
|
22
22
|
it "should return a collection of items" do
|
23
|
-
@response.items.
|
24
|
-
@response.items.size.
|
25
|
-
@response.items.each {|item| item.
|
23
|
+
expect(@response.items).to be_an_instance_of(Array)
|
24
|
+
expect(@response.items.size).to be > 0
|
25
|
+
@response.items.each {|item| expect(item).to be_an_instance_of(PITA::Item) }
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should have the some number less than or equal to #total_results" do
|
29
|
-
@response.items.size.
|
30
|
-
@response.items.size.
|
29
|
+
expect(@response.items.size).to be > 0
|
30
|
+
expect(@response.items.size).to be <= @response.total_results
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -38,17 +38,17 @@ describe PITA::Item do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should extract asin" do
|
41
|
-
@items.each {|item| item.asin.
|
42
|
-
@items.each {|item| item.asin.
|
41
|
+
@items.each {|item| expect(item.asin).to be_an_instance_of(String) }
|
42
|
+
@items.each {|item| expect(item.asin).to_not be_empty }
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should extract detail_page_url" do
|
46
|
-
@items.each {|item| item.detail_page_url.
|
47
|
-
@items.each {|item| item.detail_page_url.
|
46
|
+
@items.each {|item| expect(item.detail_page_url).to be_an_instance_of(String) }
|
47
|
+
@items.each {|item| expect(item.detail_page_url).to_not be_empty }
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should extract manufacturer" do
|
51
|
-
@items.each {|item| item.manufacturer.
|
52
|
-
@items.each {|item| item.manufacturer.
|
51
|
+
@items.each {|item| expect(item.manufacturer).to be_an_instance_of(String) }
|
52
|
+
@items.each {|item| expect(item.manufacturer).to_not be_empty }
|
53
53
|
end
|
54
54
|
end
|
@@ -7,7 +7,7 @@ describe Weather do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should extract observations" do
|
10
|
-
@weather.observation.
|
10
|
+
expect(@weather.observation).to be_an_instance_of(WeatherObservation)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -17,21 +17,21 @@ describe WeatherObservation do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should extract temperature" do
|
20
|
-
@observation.temperature.
|
20
|
+
expect(@observation.temperature).to be > 0
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should extract feels_like" do
|
24
|
-
@observation.feels_like.
|
24
|
+
expect(@observation.feels_like).to be > 0
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#current_condition" do
|
28
28
|
it "should extract current_condition" do
|
29
|
-
@observation.current_condition.
|
29
|
+
expect(@observation.current_condition).to_not be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should extract icon attribute" do
|
33
|
-
|
34
|
-
@observation.current_condition.icon.
|
33
|
+
skip "need to think options through for HappyMapper-style :attributes extensions"
|
34
|
+
expect(@observation.current_condition.icon).to_not be_empty
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -7,14 +7,14 @@ describe GitHub::Commit do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should extract committed date" do
|
10
|
-
@commit.committed_date.
|
10
|
+
expect(@commit.committed_date).to be_an_instance_of(Date)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should extract url" do
|
14
|
-
@commit.url.
|
14
|
+
expect(@commit.url).to_not be_empty
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should extract id" do
|
18
|
-
@commit.id.
|
18
|
+
expect(@commit.id).to_not be_empty
|
19
19
|
end
|
20
20
|
end
|
@@ -17,7 +17,7 @@ describe Library do
|
|
17
17
|
|
18
18
|
describe "#to_xml" do
|
19
19
|
it "should contain the expected information" do
|
20
|
-
@lib.to_xml.to_s.
|
20
|
+
expect(@lib.to_xml.to_s).to eq(ROXML::XML.parse_string(%{<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
|
@@ -33,12 +33,12 @@ describe Library do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should be contain the expected xml" do
|
36
|
-
ROXML::XML.parse_string(File.read(@path)).to_s.
|
36
|
+
expect(ROXML::XML.parse_string(File.read(@path)).to_s).to eq(ROXML::XML.parse_string(%{<?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)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should be re-parsable via .from_xml" do
|
40
40
|
File.open("spec/examples/library.xml") do |file|
|
41
|
-
Library.from_xml(file).
|
41
|
+
expect(Library.from_xml(file)).to eq(@lib)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -7,10 +7,10 @@ describe LibraryWithFines do
|
|
7
7
|
let(:library) { LibraryWithFines.from_xml(xml) }
|
8
8
|
|
9
9
|
it "should read nested elements" do
|
10
|
-
library.fines.
|
10
|
+
expect(library.fines).to be_a(Hash)
|
11
11
|
library.fines.size == 3
|
12
|
-
library.fines.
|
13
|
-
library.fines['talking'].
|
12
|
+
expect(library.fines).to have_key('talking')
|
13
|
+
expect(library.fines['talking']).to match(/Stop asking/)
|
14
14
|
end
|
15
15
|
|
16
16
|
class String
|
@@ -21,17 +21,17 @@ describe LibraryWithFines do
|
|
21
21
|
|
22
22
|
it "should write deeply nested elements" do
|
23
23
|
xml_out = library.to_xml.to_s
|
24
|
-
xml_out.remove_whitespace.
|
24
|
+
expect(xml_out.remove_whitespace).to eq(xml.remove_whitespace)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should write two children of library: name and policy" do
|
28
|
-
library.to_xml.children.map{|e| e.name }.
|
28
|
+
expect(library.to_xml.children.map{|e| e.name }).to eq(['name', 'policy'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be re-parsable via .from_xml" do
|
32
32
|
lib_reparsed = LibraryWithFines.from_xml(library.to_xml.to_s)
|
33
|
-
lib_reparsed.name.
|
34
|
-
lib_reparsed.fines.
|
33
|
+
expect(lib_reparsed.name).to eq(library.name)
|
34
|
+
expect(lib_reparsed.fines).to eq(library.fines)
|
35
35
|
end
|
36
36
|
|
37
37
|
|
@@ -2,36 +2,36 @@ require 'spec_helper'
|
|
2
2
|
require_relative './../../examples/person'
|
3
3
|
|
4
4
|
describe Person do
|
5
|
-
|
6
|
-
before do
|
7
|
-
@person = Person.new
|
8
|
-
@person.name = 'John Doe'
|
9
|
-
@person.lat = '40.715224'
|
10
|
-
@person.long = '-74.005966'
|
11
|
-
@person.street = 'Evergreen Terrace'
|
12
|
-
@person.city = 'Springfield'
|
13
|
-
@person.zip = '2342'
|
14
|
-
end
|
15
5
|
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
before do
|
7
|
+
@person = Person.new
|
8
|
+
@person.name = 'John Doe'
|
9
|
+
@person.lat = '40.715224'
|
10
|
+
@person.long = '-74.005966'
|
11
|
+
@person.street = 'Evergreen Terrace'
|
12
|
+
@person.city = 'Springfield'
|
13
|
+
@person.zip = '2342'
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
16
|
+
it 'should only contain one location element' do
|
17
|
+
expect(ROXML::XML.search(@person.to_xml, 'location').count).to eq(1)
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
describe '#to_xml' do
|
21
|
+
before do
|
22
|
+
@xml_generated = @person.to_xml.to_s.gsub("\n",'').squeeze(' ')
|
23
|
+
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
it 'should generate the expected xml' do
|
26
|
+
xml_file = File.read(xml_for('person')).gsub("\n",'').squeeze(' ')
|
27
|
+
expect(xml_file).to eq(@xml_generated)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should generate identical xml after a full roundtrip' do
|
31
|
+
p = Person.from_xml(@xml_generated)
|
32
|
+
xml_roundtrip = p.to_xml.to_s.gsub("\n",'').squeeze(' ')
|
33
|
+
expect(xml_roundtrip).to eq(@xml_generated)
|
34
|
+
end
|
35
|
+
end
|
36
36
|
|
37
37
|
end
|
data/spec/examples/post_spec.rb
CHANGED
@@ -7,18 +7,18 @@ describe Post do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should extract description" do
|
10
|
-
@posts.each {|post| post.description.
|
10
|
+
@posts.each {|post| expect(post.description).to_not be_empty }
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should extract href" do
|
14
|
-
@posts.each {|post| post.href.
|
14
|
+
@posts.each {|post| expect(post.href).to_not be_empty }
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should extract extended" do
|
18
|
-
@posts.each {|post| post.extended.
|
18
|
+
@posts.each {|post| expect(post.extended).to_not be_empty }
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should extract time" do
|
22
|
-
@posts.each {|post| post.created_at.
|
22
|
+
@posts.each {|post| expect(post.created_at).to be_an_instance_of(DateTime) }
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative './../../examples/search_query'
|
3
|
+
|
4
|
+
describe SearchQuery do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@search = SearchQuery.new
|
8
|
+
@search.query = 'This is a random search query.'
|
9
|
+
|
10
|
+
@saved_search = SearchQuery.from_xml("<searchquery><query>Search for something</query></searchquery>")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return the default value for all attributes where no value is set' do
|
14
|
+
expect(@search.language).to eq('EN')
|
15
|
+
@search.max_results == 20
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return the same object for the default value' do
|
19
|
+
expect(@search.language.object_id).to eq(@search.language.object_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should respect the defaults when loading from xml' do
|
23
|
+
expect(@saved_search.language).to eq('EN')
|
24
|
+
@saved_search.max_results == 20
|
25
|
+
end
|
26
|
+
end
|
@@ -8,11 +8,11 @@ describe Statuses do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should extract text" do
|
11
|
-
@statuses.each {|status| status.text.
|
11
|
+
@statuses.each {|status| expect(status.text).to_not be_empty }
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should extract source" do
|
15
|
-
@statuses.each {|status| status.source.
|
15
|
+
@statuses.each {|status| expect(status.source).to_not be_empty }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe User do
|
@@ -21,11 +21,11 @@ describe Statuses do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should extract name" do
|
24
|
-
@users.each {|user| user.name.
|
24
|
+
@users.each {|user| expect(user.name).to eq("John Nunemaker") }
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should extract screen_name" do
|
28
|
-
@users.each {|user| user.screen_name.
|
28
|
+
@users.each {|user| expect(user.screen_name).to eq("jnunemaker") }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/spec/reference_spec.rb
CHANGED
@@ -23,12 +23,12 @@ describe ROXML::XMLRef do
|
|
23
23
|
|
24
24
|
it "should properly reconstruct wrappers with multiple elements" do
|
25
25
|
|
26
|
-
reference.
|
26
|
+
expect(reference).to be_a(ROXML::XMLHashRef)
|
27
27
|
|
28
28
|
xml = ROXML::XML.new_node('org').tap do |root|
|
29
29
|
reference.update_xml(root, org.fines)
|
30
30
|
end
|
31
31
|
|
32
|
-
xml_path( xml ).
|
32
|
+
expect(xml_path( xml )).to eq(%w{org policy fines fine name})
|
33
33
|
end
|
34
34
|
end
|
data/spec/regression_spec.rb
CHANGED
@@ -4,16 +4,21 @@ describe ROXML do
|
|
4
4
|
describe 'frozen nils' do
|
5
5
|
subject { nil }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
lib = Library.from_xml(fixture(:library))
|
7
|
+
# Prior to ruby-2.2, nil was not frozen. This test watches for
|
8
|
+
# a regression in previous versions of roxml that caused nil to
|
9
|
+
# become frozen. FIXME: remove after ruby-2.1 support is removed.
|
10
|
+
if RUBY_VERSION < "2.2"
|
11
|
+
context 'before unmarshalling an XML document' do
|
12
|
+
it { is_expected.to_not be_frozen }
|
14
13
|
end
|
15
14
|
|
16
|
-
|
15
|
+
context 'after unmarshalling an XML document' do
|
16
|
+
before do
|
17
|
+
lib = Library.from_xml(fixture(:library))
|
18
|
+
end
|
19
|
+
|
20
|
+
it { is_expected.to_not be_frozen }
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
data/spec/roxml_spec.rb
CHANGED
@@ -1,34 +1,42 @@
|
|
1
1
|
require_relative './spec_helper'
|
2
2
|
|
3
|
-
describe ROXML
|
4
|
-
|
5
|
-
it "should
|
6
|
-
|
7
|
-
book.title.should == "Programming Ruby - 2nd Edition"
|
8
|
-
book.contributors.map(&:name).should == ["David Thomas","Andrew Hunt","Chad Fowler"]
|
3
|
+
describe ROXML do
|
4
|
+
describe "::VERSION" do
|
5
|
+
it "should be equal to the VERSION file contents" do
|
6
|
+
expect(ROXML::VERSION).to eq(File.read('VERSION'))
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
describe "#from_xml" do
|
11
|
+
shared_examples_for "from_xml call" do
|
12
|
+
it "should fetch values" do
|
13
|
+
book = BookWithContributors.from_xml(@path)
|
14
|
+
expect(book.title).to eq("Programming Ruby - 2nd Edition")
|
15
|
+
expect(book.contributors.map(&:name)).to eq(["David Thomas","Andrew Hunt","Chad Fowler"])
|
16
|
+
end
|
15
17
|
end
|
16
|
-
it_should_behave_like "from_xml call"
|
17
|
-
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
context "called with PathName" do
|
20
|
+
before do
|
21
|
+
@path = Pathname.new(fixture_path(:book_with_contributors))
|
22
|
+
end
|
23
|
+
it_should_behave_like "from_xml call"
|
22
24
|
end
|
23
|
-
it_should_behave_like "from_xml call"
|
24
|
-
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
context "called with File" do
|
27
|
+
before do
|
28
|
+
@path = File.new(fixture_path(:book_with_contributors))
|
29
|
+
end
|
30
|
+
it_should_behave_like "from_xml call"
|
31
|
+
end
|
32
|
+
|
33
|
+
context "called with URI" do
|
34
|
+
before do
|
35
|
+
require 'uri'
|
36
|
+
@path = URI.parse("file://#{File.expand_path(File.expand_path(fixture_path(:book_with_contributors)))}")
|
37
|
+
end
|
38
|
+
it_should_behave_like "from_xml call"
|
30
39
|
end
|
31
|
-
it_should_behave_like "from_xml call"
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
@@ -73,14 +81,14 @@ describe ROXML, "#xml" do
|
|
73
81
|
end
|
74
82
|
|
75
83
|
it "should raise on duplicate accessor name" do
|
76
|
-
|
84
|
+
expect do
|
77
85
|
Class.new do
|
78
86
|
include ROXML
|
79
87
|
|
80
88
|
xml_reader :id
|
81
89
|
xml_accessor :id
|
82
90
|
end
|
83
|
-
end.
|
91
|
+
end.to raise_error(RuntimeError)
|
84
92
|
end
|
85
93
|
|
86
94
|
class OctalInteger
|
@@ -131,19 +139,6 @@ describe ROXML, "#xml" do
|
|
131
139
|
@expected_pages = 239
|
132
140
|
end
|
133
141
|
|
134
|
-
describe "with :as block shorthand" do
|
135
|
-
class BookWithOctalPagesBlockShorthand
|
136
|
-
include ROXML
|
137
|
-
|
138
|
-
xml_accessor :pages, :as => Integer, :required => true
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should apply filtering on input" do
|
142
|
-
book = BookWithOctalPagesBlockShorthand.from_xml(@book_with_octal_pages_xml)
|
143
|
-
book.pages.should == @expected_pages
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
142
|
describe "with #from_xml defined on the object" do
|
148
143
|
class BookWithOctalPagesType
|
149
144
|
include ROXML
|
@@ -153,7 +148,7 @@ describe ROXML, "#xml" do
|
|
153
148
|
|
154
149
|
it "should apply filtering on input" do
|
155
150
|
book = BookWithOctalPagesType.from_xml(@book_with_octal_pages_xml)
|
156
|
-
book.pages.
|
151
|
+
expect(book.pages).to eq(@expected_pages)
|
157
152
|
end
|
158
153
|
end
|
159
154
|
end
|
@@ -186,11 +181,11 @@ describe ROXML, "#xml" do
|
|
186
181
|
|
187
182
|
describe "indirect reference via an object" do
|
188
183
|
it "does not inherit the frozen status from its parent" do
|
189
|
-
@frozen.writable.frozen
|
190
|
-
@frozen.readonly.frozen
|
184
|
+
expect(@frozen.writable.frozen?).to be_falsey
|
185
|
+
expect(@frozen.readonly.frozen?).to be_truthy
|
191
186
|
|
192
|
-
@unfrozen.writable.frozen
|
193
|
-
@unfrozen.readonly.frozen
|
187
|
+
expect(@unfrozen.writable.frozen?).to be_falsey
|
188
|
+
expect(@unfrozen.readonly.frozen?).to be_truthy
|
194
189
|
end
|
195
190
|
end
|
196
191
|
end
|
@@ -204,8 +199,8 @@ describe ROXML, "#xml" do
|
|
204
199
|
it_should_behave_like "freezable xml reference"
|
205
200
|
|
206
201
|
it "should apply :frozen to the constituent elements" do
|
207
|
-
@frozen.all?(&:frozen?).
|
208
|
-
@unfrozen.any?(&:frozen?).
|
202
|
+
expect(@frozen.all?(&:frozen?)).to be_truthy
|
203
|
+
expect(@unfrozen.any?(&:frozen?)).to be_falsey
|
209
204
|
end
|
210
205
|
|
211
206
|
context "no elements are present in root, no :in is specified" do
|
@@ -229,7 +224,7 @@ describe ROXML, "#xml" do
|
|
229
224
|
</contributors>
|
230
225
|
</book>
|
231
226
|
})
|
232
|
-
book.contributors.map(&:name).sort.
|
227
|
+
expect(book.contributors.map(&:name).sort).to eq(["David Thomas","Andrew Hunt","Chad Fowler"].sort)
|
233
228
|
end
|
234
229
|
end
|
235
230
|
end
|
@@ -259,13 +254,13 @@ describe ROXML, "#xml" do
|
|
259
254
|
it_should_behave_like "freezable xml reference"
|
260
255
|
|
261
256
|
it "should have frozen keys, as with all hashes" do
|
262
|
-
@frozen.keys.all?(&:frozen?).
|
263
|
-
@unfrozen.keys.all?(&:frozen?).
|
257
|
+
expect(@frozen.keys.all?(&:frozen?)).to be_truthy
|
258
|
+
expect(@unfrozen.keys.all?(&:frozen?)).to be_truthy
|
264
259
|
end
|
265
260
|
|
266
261
|
it "should apply :frozen to the constituent values" do
|
267
|
-
@frozen.values.all?(&:frozen?).
|
268
|
-
@unfrozen.values.any?(&:frozen?).
|
262
|
+
expect(@frozen.values.all?(&:frozen?)).to be_truthy
|
263
|
+
expect(@unfrozen.values.any?(&:frozen?)).to be_falsey
|
269
264
|
end
|
270
265
|
end
|
271
266
|
end
|
@@ -335,29 +330,29 @@ describe ROXML, "inheritance" do
|
|
335
330
|
|
336
331
|
describe "parent" do
|
337
332
|
it "should include its attributes" do
|
338
|
-
@child.isbn.
|
339
|
-
@child.title.
|
340
|
-
@child.description.
|
341
|
-
@child.author.
|
342
|
-
@child.pages.
|
333
|
+
expect(@child.isbn).to eq("0201710897")
|
334
|
+
expect(@child.title).to eq("The PickAxe")
|
335
|
+
expect(@child.description).to eq("Probably the best Ruby book out there")
|
336
|
+
expect(@child.author).to eq('David Thomas, Andrew Hunt, Dave Thomas')
|
337
|
+
expect(@child.pages).to eq(nil)
|
343
338
|
end
|
344
339
|
|
345
340
|
it "should not include its child's attributes" do
|
346
|
-
@parent.
|
341
|
+
expect(@parent).to_not respond_to(:depth)
|
347
342
|
end
|
348
343
|
end
|
349
344
|
|
350
345
|
describe "child" do
|
351
346
|
it "should include its parent's attributes" do
|
352
|
-
@child.isbn.
|
353
|
-
@child.title.
|
354
|
-
@child.description.
|
355
|
-
@child.author.
|
356
|
-
@child.pages.
|
347
|
+
expect(@child.isbn).to eq(@parent.isbn)
|
348
|
+
expect(@child.title).to eq(@parent.title)
|
349
|
+
expect(@child.description).to eq(@parent.description)
|
350
|
+
expect(@child.author).to eq(@parent.author)
|
351
|
+
expect(@child.pages).to eq(@parent.pages)
|
357
352
|
end
|
358
353
|
|
359
354
|
it "should include its attributes" do
|
360
|
-
@child.depth.to_s.
|
355
|
+
expect(@child.depth.to_s).to eq('11.3 meters')
|
361
356
|
end
|
362
357
|
|
363
358
|
it "should include parent's attributes added after declaration" do
|
@@ -366,7 +361,7 @@ describe ROXML, "inheritance" do
|
|
366
361
|
end
|
367
362
|
|
368
363
|
book = InheritedBookWithDepth.from_xml(@book_xml)
|
369
|
-
book.publisher.
|
364
|
+
expect(book.publisher).to eq("Pragmattic Programmers")
|
370
365
|
end
|
371
366
|
end
|
372
367
|
end
|