nokogiri-happymapper 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "Wildcard Root Tag" do
3
+ require 'spec_helper'
4
4
 
5
- generic_class_xml = %{
5
+ describe 'Wildcard Root Tag' do
6
+ generic_class_xml = %(
6
7
  <root>
7
8
  <description>some description</description>
8
9
  <blarg name='blargname1' href='http://blarg.com'/>
@@ -11,7 +12,7 @@ describe "Wildcard Root Tag" do
11
12
  <subelement>
12
13
  <jello name='subjelloname' href='http://ohnojello.com' other='othertext'/>
13
14
  </subelement>
14
- </root>}
15
+ </root>)
15
16
 
16
17
  module GenericBase
17
18
  class Base
@@ -29,28 +30,31 @@ describe "Wildcard Root Tag" do
29
30
  attribute :href, String
30
31
  attribute :other, String
31
32
 
32
- def <=>(compared)
33
- name <=> compared.name && href <=> compared.href && other <=> compared.other
33
+ def <=>(other)
34
+ result = name <=> other.name
35
+ return result unless result == 0
36
+ result = href <=> other.href
37
+ return result unless result == 0
38
+ self.other <=> other.other
34
39
  end
35
40
  end
36
41
  class Sub
37
42
  include HappyMapper
38
43
  tag 'subelement'
39
- has_one :jello, Base, :tag => 'jello'
44
+ has_one :jello, Base, tag: 'jello'
40
45
  end
41
46
  class Root
42
47
  include HappyMapper
43
48
  tag 'root'
44
49
  element :description, String
45
- has_many :blargs, Base, :tag => 'blarg', :xpath => '.'
46
- has_many :jellos, Base, :tag => 'jello', :xpath => '.'
47
- has_many :subjellos, Base, :tag => 'jello', :xpath => 'subelement/.', :read_only => true
50
+ has_many :blargs, Base, tag: 'blarg', xpath: '.'
51
+ has_many :jellos, Base, tag: 'jello', xpath: '.'
52
+ has_many :subjellos, Base, tag: 'jello', xpath: 'subelement/.', read_only: true
48
53
  has_one :sub_element, Sub
49
54
  end
50
55
  end
51
56
 
52
57
  describe "can have generic classes using tag '*'" do
53
-
54
58
  let(:subject) { GenericBase::Root.parse(generic_class_xml) }
55
59
  let(:xml) { Nokogiri::XML(subject.to_xml) }
56
60
 
@@ -65,18 +69,18 @@ describe "Wildcard Root Tag" do
65
69
  expect(subject.subjellos.size).to eq(1)
66
70
  end
67
71
 
68
- def base_with(name,href,other)
69
- GenericBase::Base.new(:name => name,:href => href,:other => other)
72
+ def base_with(name, href, other)
73
+ GenericBase::Base.new(name: name, href: href, other: other)
70
74
  end
71
75
 
72
76
  it 'should parse correct values onto generic class' do
73
- expect(subject.blargs[0]).to eq base_with('blargname1','http://blarg.com',nil)
74
- expect(subject.blargs[1]).to eq base_with('blargname2','http://blarg.com',nil)
75
- expect(subject.jellos[0]).to eq base_with('jelloname','http://jello.com',nil)
76
- expect(subject.subjellos[0]).to eq base_with('subjelloname','http://ohnojello.com','othertext')
77
+ expect(subject.blargs[0]).to eq base_with('blargname1', 'http://blarg.com', nil)
78
+ expect(subject.blargs[1]).to eq base_with('blargname2', 'http://blarg.com', nil)
79
+ expect(subject.jellos[0]).to eq base_with('jelloname', 'http://jello.com', nil)
80
+ expect(subject.subjellos[0]).to eq base_with('subjelloname', 'http://ohnojello.com', 'othertext')
77
81
  end
78
82
 
79
- def validate_xpath(xpath,name,href,other)
83
+ def validate_xpath(xpath, name, href, other)
80
84
  expect(xml.xpath("#{xpath}/@name").text).to eq name
81
85
  expect(xml.xpath("#{xpath}/@href").text).to eq href
82
86
  expect(xml.xpath("#{xpath}/@other").text).to eq other
@@ -84,9 +88,9 @@ describe "Wildcard Root Tag" do
84
88
 
85
89
  it 'should #to_xml using parent element tag name' do
86
90
  expect(xml.xpath('/root/description').text).to eq('some description')
87
- validate_xpath("/root/blarg[1]","blargname1","http://blarg.com","")
88
- validate_xpath("/root/blarg[2]","blargname2","http://blarg.com","")
89
- validate_xpath("/root/jello[1]","jelloname","http://jello.com","")
91
+ validate_xpath('/root/blarg[1]', 'blargname1', 'http://blarg.com', '')
92
+ validate_xpath('/root/blarg[2]', 'blargname2', 'http://blarg.com', '')
93
+ validate_xpath('/root/jello[1]', 'jelloname', 'http://jello.com', '')
90
94
  end
91
95
 
92
96
  it "should properly respect child HappyMapper tags if tag isn't provided on the element defintion" do
@@ -1,13 +1,14 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "wrap which allows you to specify a wrapper element" do
3
+ require 'spec_helper'
4
4
 
5
+ describe 'wrap which allows you to specify a wrapper element' do
5
6
  module Wrap
6
7
  class SubClass
7
8
  include HappyMapper
8
9
  tag 'subclass'
9
10
  attribute :myattr, String
10
- has_many :items, String, :tag => 'item'
11
+ has_many :items, String, tag: 'item'
11
12
  end
12
13
  class Root
13
14
  include HappyMapper
@@ -22,8 +23,8 @@ describe "wrap which allows you to specify a wrapper element" do
22
23
  end
23
24
  end
24
25
 
25
- describe ".parse" do
26
- context "when given valid XML" do
26
+ describe '.parse' do
27
+ context 'when given valid XML' do
27
28
  let(:subject) { Wrap::Root.parse fixture_file('wrapper.xml') }
28
29
 
29
30
  it 'sets the values correctly' do
@@ -38,16 +39,16 @@ describe "wrap which allows you to specify a wrapper element" do
38
39
  end
39
40
  end
40
41
 
41
- context "when initialized without XML" do
42
+ context 'when initialized without XML' do
42
43
  let(:subject) { Wrap::Root.new }
43
44
 
44
- it "anonymous classes are created so nil class values does not occur" do
45
+ it 'anonymous classes are created so nil class values does not occur' do
45
46
  expect { subject.description = 'anything' }.to_not raise_error
46
47
  end
47
48
  end
48
49
  end
49
50
 
50
- describe ".to_xml" do
51
+ describe '.to_xml' do
51
52
  let(:subject) do
52
53
  root = Wrap::Root.new
53
54
  root.attr1 = 'somevalue'
@@ -66,7 +67,7 @@ describe "wrap which allows you to specify a wrapper element" do
66
67
  root
67
68
  end
68
69
 
69
- it "generates the correct xml" do
70
+ it 'generates the correct xml' do
70
71
  xml = Nokogiri::XML(subject.to_xml)
71
72
  expect(xml.xpath('/root/@attr1').text).to eq 'somevalue'
72
73
  expect(xml.xpath('/root/name').text).to eq 'myname'
@@ -77,6 +78,5 @@ describe "wrap which allows you to specify a wrapper element" do
77
78
  expect(xml.xpath('/root/mywraptag/subclass/item[2]').text).to eq 'item2'
78
79
  expect(xml.xpath('/root/number').text).to eq '12345'
79
80
  end
80
-
81
81
  end
82
- end
82
+ end
@@ -1,7 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe "Specifying elements and attributes with an xpath" do
3
+ require 'spec_helper'
4
4
 
5
+ describe 'Specifying elements and attributes with an xpath' do
5
6
  class Item
6
7
  include HappyMapper
7
8
 
@@ -9,15 +10,15 @@ describe "Specifying elements and attributes with an xpath" do
9
10
  namespace 'amazing'
10
11
 
11
12
  element :title, String
12
- attribute :link, String, :xpath => 'amazing:link/@href'
13
- has_one :different_link, String, :xpath => 'different:link/@href'
14
- element :detail, String, :xpath => 'amazing:subitem/amazing:detail'
15
- has_many :more_details_text, String, :xpath => 'amazing:subitem/amazing:more'
16
- has_many :more_details, String, :xpath => 'amazing:subitem/amazing:more/@first|amazing:subitem/amazing:more/@alternative'
17
- has_many :more_details_alternative, String, :xpath => 'amazing:subitem/amazing:more/@*'
18
-
19
- has_one :baby, 'Baby', :name => 'baby', :namespace => 'amazing'
20
-
13
+ attribute :link, String, xpath: 'amazing:link/@href'
14
+ has_one :different_link, String, xpath: 'different:link/@href'
15
+ element :detail, String, xpath: 'amazing:subitem/amazing:detail'
16
+ has_many :more_details_text, String, xpath: 'amazing:subitem/amazing:more'
17
+ has_many :more_details, String,
18
+ xpath: 'amazing:subitem/amazing:more/@first|amazing:subitem/amazing:more/@alternative'
19
+ has_many :more_details_alternative, String, xpath: 'amazing:subitem/amazing:more/@*'
20
+
21
+ has_one :baby, 'Baby', name: 'baby', namespace: 'amazing'
21
22
  end
22
23
 
23
24
  class Baby
@@ -26,12 +27,13 @@ describe "Specifying elements and attributes with an xpath" do
26
27
  has_one :name, String
27
28
  end
28
29
 
29
- let(:subject) { Item.parse(xml_string,:single => true) }
30
+ let(:subject) { Item.parse(xml_string, single: true) }
30
31
 
31
32
  let(:xml_string) do
32
- %{
33
+ %(
33
34
  <rss>
34
- <amazing:item xmlns:amazing="http://www.amazing.com/amazing" xmlns:different="http://www.different.com/different">
35
+ <amazing:item xmlns:amazing="http://www.amazing.com/amazing"
36
+ xmlns:different="http://www.different.com/different">
35
37
  <amazing:title>Test XML</amazing:title>
36
38
  <different:link href="different_link" />
37
39
  <amazing:link href="link_to_resources" />
@@ -45,45 +47,44 @@ describe "Specifying elements and attributes with an xpath" do
45
47
  </amazing:baby>
46
48
  </amazing:item>
47
49
  </rss>
48
- }
50
+ )
49
51
  end
50
52
 
51
- it "should have a title" do
52
- expect(subject.title).to eq "Test XML"
53
+ it 'should have a title' do
54
+ expect(subject.title).to eq 'Test XML'
53
55
  end
54
56
 
55
- it "should find the link href value" do
57
+ it 'should find the link href value' do
56
58
  expect(subject.link).to eq 'link_to_resources'
57
59
  end
58
60
 
59
- it "should find the link href value" do
61
+ it 'should find the link href value' do
60
62
  expect(subject.different_link).to eq 'different_link'
61
63
  end
62
64
 
63
- it "should find this subitem based on the xpath" do
65
+ it 'should find this subitem based on the xpath' do
64
66
  expect(subject.detail).to eq 'I want to parse this'
65
67
  end
66
68
 
67
- it "should find the subitems based on the xpath" do
69
+ it 'should find the subitems based on the xpath' do
68
70
  expect(subject.more_details_text.size).to eq(2)
69
- expect(subject.more_details_text.first).to eq "more 1"
70
- expect(subject.more_details_text.last).to eq "more 2"
71
+ expect(subject.more_details_text.first).to eq 'more 1'
72
+ expect(subject.more_details_text.last).to eq 'more 2'
71
73
  end
72
74
 
73
- it "should find the subitems based on the xpath" do
75
+ it 'should find the subitems based on the xpath' do
74
76
  expect(subject.more_details.size).to eq(2)
75
- expect(subject.more_details.first).to eq "this one"
76
- expect(subject.more_details.last).to eq "another one"
77
+ expect(subject.more_details.first).to eq 'this one'
78
+ expect(subject.more_details.last).to eq 'another one'
77
79
  end
78
80
 
79
- it "should find the subitems based on the xpath" do
81
+ it 'should find the subitems based on the xpath' do
80
82
  expect(subject.more_details_alternative.size).to eq(2)
81
- expect(subject.more_details_alternative.first).to eq "this one"
82
- expect(subject.more_details_alternative.last).to eq "another one"
83
+ expect(subject.more_details_alternative.first).to eq 'this one'
84
+ expect(subject.more_details_alternative.last).to eq 'another one'
83
85
  end
84
86
 
85
- it "should have a baby name" do
86
- expect(subject.baby.name).to eq "Jumbo"
87
+ it 'should have a baby name' do
88
+ expect(subject.baby.name).to eq 'Jumbo'
87
89
  end
88
-
89
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-happymapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2017-09-17 00:00:00.000000000 Z
17
+ date: 2018-08-27 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: nokogiri
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '1.5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '12.0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rspec
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +58,20 @@ dependencies:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
60
  version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: simplecov
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.16.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.16.1
47
75
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
48
76
  Happymapper)
49
77
  email: matijs@matijs.net
@@ -124,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
152
  requirements:
125
153
  - - ">="
126
154
  - !ruby/object:Gem::Version
127
- version: 1.9.3
155
+ version: 2.3.0
128
156
  required_rubygems_version: !ruby/object:Gem::Requirement
129
157
  requirements:
130
158
  - - ">="
@@ -132,9 +160,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
160
  version: '0'
133
161
  requirements: []
134
162
  rubyforge_project:
135
- rubygems_version: 2.6.11
163
+ rubygems_version: 2.7.6
136
164
  signing_key:
137
- specification_version: 3
165
+ specification_version: 4
138
166
  summary: Provides a simple way to map XML to Ruby Objects and back again.
139
167
  test_files:
140
168
  - spec/attribute_default_value_spec.rb