nokogiri-happymapper 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,10 +34,10 @@ describe "emptyness" do
34
34
  end
35
35
 
36
36
  it "returns an empty array" do
37
- navigator.items_with_a_different_name.should be_empty
37
+ expect(navigator.items_with_a_different_name).to be_empty
38
38
  end
39
39
 
40
40
  it "returns an empty array" do
41
- navigator.items.should be_empty
41
+ expect(navigator.items).to be_empty
42
42
  end
43
43
  end
@@ -43,40 +43,40 @@ end
43
43
  describe HappyMapper do
44
44
 
45
45
  it "should not be nil" do
46
- catalog_tree.should_not be_nil
46
+ expect(catalog_tree).not_to be_nil
47
47
  end
48
48
 
49
49
  it "should have the attribute code" do
50
- catalog_tree.code.should == "NLD"
50
+ expect(catalog_tree.code).to eq("NLD")
51
51
  end
52
52
 
53
53
  it "should have many nodes" do
54
- catalog_tree.nodes.should_not be_empty
55
- catalog_tree.nodes.length.should == 2
54
+ expect(catalog_tree.nodes).not_to be_empty
55
+ expect(catalog_tree.nodes.length).to eq(2)
56
56
  end
57
57
 
58
58
  context "first node" do
59
59
 
60
60
  it "should have a name" do
61
- first_node.name.should == "Parent 1"
61
+ expect(first_node.name).to eq("Parent 1")
62
62
  end
63
63
 
64
64
  it "should have translations" do
65
- first_node.translations.length.should == 2
65
+ expect(first_node.translations.length).to eq(2)
66
66
 
67
- first_node.translations.first.language.should == "en-GB"
67
+ expect(first_node.translations.first.language).to eq("en-GB")
68
68
 
69
- first_node.translations.last.name.should == "Parent 1 de"
69
+ expect(first_node.translations.last.name).to eq("Parent 1 de")
70
70
  end
71
71
 
72
72
  it "should have subnodes" do
73
- first_node.nodes.should be_kind_of(Enumerable)
74
- first_node.nodes.should_not be_empty
75
- first_node.nodes.length.should == 1
73
+ expect(first_node.nodes).to be_kind_of(Enumerable)
74
+ expect(first_node.nodes).not_to be_empty
75
+ expect(first_node.nodes.length).to eq(1)
76
76
  end
77
77
 
78
78
  it "first node - first node name" do
79
- first_node.nodes.first.name.should == "First"
79
+ expect(first_node.nodes.first.name).to eq("First")
80
80
  end
81
81
 
82
82
  def first_node
@@ -76,7 +76,7 @@ describe "Using inheritance to share elements and attributes" do
76
76
  expect(subject.love).to eq 99
77
77
  expect(subject.genetics.dna).to eq "ABBA"
78
78
  expect(subject.naivety).to eq "trusting"
79
- expect(subject.immunities).to have(1).item
79
+ expect(subject.immunities.size).to eq(1)
80
80
  end
81
81
  end
82
82
 
@@ -99,7 +99,7 @@ describe "Using inheritance to share elements and attributes" do
99
99
 
100
100
  it "saves both the Child and Parent elements" do
101
101
  expect(subject.xpath("genetics").text).to eq "GATTACA"
102
- expect(subject.xpath("immunities")).to have(3).items
102
+ expect(subject.xpath("immunities").size).to eq(3)
103
103
  end
104
104
  end
105
105
 
@@ -82,7 +82,7 @@ describe "Updating existing objects with .parse and #parse" do
82
82
  end
83
83
 
84
84
  it 'initial values are correct' do
85
- subject.attr1.should == 'initial'
85
+ expect(subject.attr1).to eq('initial')
86
86
  item_is_correctly_defined( subject.items[0] )
87
87
  item_is_correctly_defined( subject.items[1] )
88
88
  end
@@ -22,6 +22,7 @@ describe "Saving #to_xml" do
22
22
  # to_xml will default to the attr_accessor method and not the attribute,
23
23
  # allowing for that to be overwritten
24
24
  #
25
+ undef :housenumber
25
26
  def housenumber
26
27
  "[#{@housenumber}]"
27
28
  end
@@ -197,4 +198,4 @@ describe "Saving #to_xml" do
197
198
  expect(subject.xpath('country/description').text).to eq "A lovely country"
198
199
  end
199
200
  end
200
- end
201
+ end
@@ -28,6 +28,7 @@ module ToXMLWithNamespaces
28
28
  # to_xml will default to the attr_accessor method and not the attribute,
29
29
  # allowing for that to be overwritten
30
30
  #
31
+ undef :housenumber
31
32
  def housenumber
32
33
  "[#{@housenumber}]"
33
34
  end
@@ -178,7 +179,7 @@ describe "Saving #to_xml", "with xml namespaces" do
178
179
 
179
180
  context "when an element type is a HappyMapper subclass" do
180
181
  it "saves attributes" do
181
- expect(subject.xpath('country:country/@country:countryCode').text).to eq "us"
182
+ expect(subject.xpath('country:country/@countryCode').text).to eq "us"
182
183
  end
183
184
 
184
185
  it "saves elements" do
@@ -190,7 +191,42 @@ describe "Saving #to_xml", "with xml namespaces" do
190
191
  context "with a default namespace" do
191
192
  it "writes the default namespace to xml without repeating xmlns" do
192
193
  recipe = ToXMLWithNamespaces::Recipe.new(:ingredients => ['One Cup Flour', 'Two Scoops of Lovin'])
193
- expect(recipe.to_xml).to match /xmlns=\"urn:eventis:prodis:onlineapi:1\.0\"/
194
+ expect(recipe.to_xml).to match(/xmlns=\"urn:eventis:prodis:onlineapi:1\.0\"/)
194
195
  end
195
196
  end
197
+
198
+ context 'namespace supplied by element declaration trumps namespace ' \
199
+ 'specified by element class' do
200
+
201
+ let(:expected_xml) do
202
+ <<-XML.gsub(/^\s*\|/, '')
203
+ |<?xml version="1.0"?>
204
+ |<coffeemachine xmlns:coffee="http://coffee.org/Coffee/0.1" xmlns:beverage="http://beverages.org/Beverage/0.1">
205
+ | <beverage:beverage name="coffee"/>
206
+ |</coffeemachine>
207
+ XML
208
+ end
209
+
210
+ class Beverage
211
+ include HappyMapper
212
+ namespace 'coffee'
213
+
214
+ attribute :name, String
215
+ end
216
+
217
+ class CoffeeMachine
218
+ include HappyMapper
219
+ register_namespace 'coffee', "http://coffee.org/Coffee/0.1"
220
+ register_namespace 'beverage', "http://beverages.org/Beverage/0.1"
221
+
222
+ element :beverage, 'beverage', namespace: 'beverage'
223
+ end
224
+
225
+ it 'uses the element declaration namespace on the element' do
226
+ machine = CoffeeMachine.new
227
+ machine.beverage = Beverage.new.tap {|obj| obj.name = 'coffee'}
228
+ expect(machine.to_xml).to eq(expected_xml)
229
+ end
230
+ end
231
+
196
232
  end
@@ -55,14 +55,14 @@ describe "Wildcard Root Tag" do
55
55
  let(:xml) { Nokogiri::XML(subject.to_xml) }
56
56
 
57
57
  it 'should map different elements to same class' do
58
- subject.blargs.should_not be_nil
59
- subject.jellos.should_not be_nil
58
+ expect(subject.blargs).not_to be_nil
59
+ expect(subject.jellos).not_to be_nil
60
60
  end
61
61
 
62
62
  it 'should filter on xpath appropriately' do
63
- subject.blargs.should have(2).items
64
- subject.jellos.should have(1).items
65
- subject.subjellos.should have(1).items
63
+ expect(subject.blargs.size).to eq(2)
64
+ expect(subject.jellos.size).to eq(1)
65
+ expect(subject.subjellos.size).to eq(1)
66
66
  end
67
67
 
68
68
  def base_with(name,href,other)
@@ -83,14 +83,14 @@ describe "Wildcard Root Tag" do
83
83
  end
84
84
 
85
85
  it 'should #to_xml using parent element tag name' do
86
- xml.xpath('/root/description').text.should == 'some description'
86
+ expect(xml.xpath('/root/description').text).to eq('some description')
87
87
  validate_xpath("/root/blarg[1]","blargname1","http://blarg.com","")
88
88
  validate_xpath("/root/blarg[2]","blargname2","http://blarg.com","")
89
89
  validate_xpath("/root/jello[1]","jelloname","http://jello.com","")
90
90
  end
91
91
 
92
92
  it "should properly respect child HappyMapper tags if tag isn't provided on the element defintion" do
93
- xml.xpath('root/subelement').should have(1).item
93
+ expect(xml.xpath('root/subelement').size).to eq(1)
94
94
  end
95
95
  end
96
96
  end
@@ -31,7 +31,7 @@ describe "wrap which allows you to specify a wrapper element" do
31
31
  expect(subject.name).to eq 'myname'
32
32
  expect(subject.description).to eq 'some description'
33
33
  expect(subject.subclass.myattr).to eq 'attrvalue'
34
- expect(subject.subclass.items).to have(2).items
34
+ expect(subject.subclass.items.size).to eq(2)
35
35
  expect(subject.subclass.items[0]).to eq 'item1'
36
36
  expect(subject.subclass.items[1]).to eq 'item2'
37
37
  expect(subject.number).to eq 12345
@@ -72,7 +72,7 @@ describe "wrap which allows you to specify a wrapper element" do
72
72
  expect(xml.xpath('/root/name').text).to eq 'myname'
73
73
  expect(xml.xpath('/root/mywraptag/description').text).to eq 'some description'
74
74
  expect(xml.xpath('/root/mywraptag/subclass/@myattr').text).to eq 'attrvalue'
75
- expect(xml.xpath('/root/mywraptag/subclass/item')).to have(2).items
75
+ expect(xml.xpath('/root/mywraptag/subclass/item').size).to eq(2)
76
76
  expect(xml.xpath('/root/mywraptag/subclass/item[1]').text).to eq 'item1'
77
77
  expect(xml.xpath('/root/mywraptag/subclass/item[2]').text).to eq 'item2'
78
78
  expect(xml.xpath('/root/number').text).to eq '12345'
@@ -65,19 +65,19 @@ describe "Specifying elements and attributes with an xpath" do
65
65
  end
66
66
 
67
67
  it "should find the subitems based on the xpath" do
68
- expect(subject.more_details_text).to have(2).items
68
+ expect(subject.more_details_text.size).to eq(2)
69
69
  expect(subject.more_details_text.first).to eq "more 1"
70
70
  expect(subject.more_details_text.last).to eq "more 2"
71
71
  end
72
72
 
73
73
  it "should find the subitems based on the xpath" do
74
- expect(subject.more_details).to have(2).items
74
+ expect(subject.more_details.size).to eq(2)
75
75
  expect(subject.more_details.first).to eq "this one"
76
76
  expect(subject.more_details.last).to eq "another one"
77
77
  end
78
78
 
79
79
  it "should find the subitems based on the xpath" do
80
- expect(subject.more_details_alternative).to have(2).items
80
+ expect(subject.more_details_alternative.size).to eq(2)
81
81
  expect(subject.more_details_alternative.first).to eq "this one"
82
82
  expect(subject.more_details_alternative.last).to eq "another one"
83
83
  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.5.9
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Le Berrigaud
@@ -10,48 +10,53 @@ authors:
10
10
  - Roland Swingler
11
11
  - Etienne Vallette d'Osia
12
12
  - Franklin Webber
13
+ - Matijs van Zuijlen
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
- date: 2014-02-18 00:00:00.000000000 Z
17
+ date: 2017-09-17 00:00:00.000000000 Z
17
18
  dependencies:
18
19
  - !ruby/object:Gem::Dependency
19
20
  name: nokogiri
20
21
  requirement: !ruby/object:Gem::Requirement
21
22
  requirements:
22
- - - ~>
23
+ - - "~>"
23
24
  - !ruby/object:Gem::Version
24
25
  version: '1.5'
25
26
  type: :runtime
26
27
  prerelease: false
27
28
  version_requirements: !ruby/object:Gem::Requirement
28
29
  requirements:
29
- - - ~>
30
+ - - "~>"
30
31
  - !ruby/object:Gem::Version
31
32
  version: '1.5'
32
33
  - !ruby/object:Gem::Dependency
33
34
  name: rspec
34
35
  requirement: !ruby/object:Gem::Requirement
35
36
  requirements:
36
- - - ~>
37
+ - - "~>"
37
38
  - !ruby/object:Gem::Version
38
- version: '2.8'
39
+ version: '3.0'
39
40
  type: :development
40
41
  prerelease: false
41
42
  version_requirements: !ruby/object:Gem::Requirement
42
43
  requirements:
43
- - - ~>
44
+ - - "~>"
44
45
  - !ruby/object:Gem::Version
45
- version: '2.8'
46
+ version: '3.0'
46
47
  description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
47
48
  Happymapper)
48
- email: franklin.webber@gmail.com
49
+ email: matijs@matijs.net
49
50
  executables: []
50
51
  extensions: []
51
52
  extra_rdoc_files:
52
53
  - README.md
53
54
  - CHANGELOG.md
55
+ - License
54
56
  files:
57
+ - CHANGELOG.md
58
+ - License
59
+ - README.md
55
60
  - lib/happymapper.rb
56
61
  - lib/happymapper/anonymous_mapper.rb
57
62
  - lib/happymapper/attribute.rb
@@ -60,8 +65,6 @@ files:
60
65
  - lib/happymapper/supported_types.rb
61
66
  - lib/happymapper/text_node.rb
62
67
  - lib/happymapper/version.rb
63
- - README.md
64
- - CHANGELOG.md
65
68
  - spec/attribute_default_value_spec.rb
66
69
  - spec/attributes_spec.rb
67
70
  - spec/fixtures/address.xml
@@ -90,6 +93,7 @@ files:
90
93
  - spec/fixtures/set_config_options.xml
91
94
  - spec/fixtures/statuses.xml
92
95
  - spec/fixtures/subclass_namespace.xml
96
+ - spec/fixtures/unformatted_address.xml
93
97
  - spec/fixtures/wrapper.xml
94
98
  - spec/happymapper/attribute_spec.rb
95
99
  - spec/happymapper/element_spec.rb
@@ -108,7 +112,7 @@ files:
108
112
  - spec/wilcard_tag_name_spec.rb
109
113
  - spec/wrap_spec.rb
110
114
  - spec/xpath_spec.rb
111
- homepage: http://github.com/dam5s/happymapper
115
+ homepage: http://github.com/mvz/happymapper
112
116
  licenses:
113
117
  - MIT
114
118
  metadata: {}
@@ -118,17 +122,17 @@ require_paths:
118
122
  - lib
119
123
  required_ruby_version: !ruby/object:Gem::Requirement
120
124
  requirements:
121
- - - '>='
125
+ - - ">="
122
126
  - !ruby/object:Gem::Version
123
- version: '0'
127
+ version: 1.9.3
124
128
  required_rubygems_version: !ruby/object:Gem::Requirement
125
129
  requirements:
126
- - - '>='
130
+ - - ">="
127
131
  - !ruby/object:Gem::Version
128
132
  version: '0'
129
133
  requirements: []
130
134
  rubyforge_project:
131
- rubygems_version: 2.1.9
135
+ rubygems_version: 2.6.11
132
136
  signing_key:
133
137
  specification_version: 3
134
138
  summary: Provides a simple way to map XML to Ruby Objects and back again.
@@ -161,6 +165,7 @@ test_files:
161
165
  - spec/fixtures/set_config_options.xml
162
166
  - spec/fixtures/statuses.xml
163
167
  - spec/fixtures/subclass_namespace.xml
168
+ - spec/fixtures/unformatted_address.xml
164
169
  - spec/fixtures/wrapper.xml
165
170
  - spec/happymapper/attribute_spec.rb
166
171
  - spec/happymapper/element_spec.rb
@@ -179,4 +184,3 @@ test_files:
179
184
  - spec/wilcard_tag_name_spec.rb
180
185
  - spec/wrap_spec.rb
181
186
  - spec/xpath_spec.rb
182
- has_rdoc: