xml-mapping_extensions 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6974aa25a580ab47d6ffc41468fe2afb54c6ad91
4
- data.tar.gz: 4fd09884318b53fdbdf1f3de954fbe87677e867a
3
+ metadata.gz: 4ad2038c6915f4e3195269c95f734366b100701f
4
+ data.tar.gz: e9385d3e05c59809e21425a2a2fada61975a35bf
5
5
  SHA512:
6
- metadata.gz: 54d02c4c2bbae8388b21956cdc68f7183e100c321c3eb38ae3c54c597308fe6969d20e296aac0375eea25a886565e120eec9b815c72cfa1ad1ca4e5c7f27329d
7
- data.tar.gz: bb25f1d1b4de7cdf86d8110a2b1264f4b8f31fa83058418a4c3743ff7499160764c7377dd47222a76f754a6c8131d3dfad249bd0f6ab921ccfad50db35e0f5ec
6
+ metadata.gz: 6f3af4513a661edf05a8ad119745fe5556e59e7ca4bf0de81def9962fe8e00446f8005af34f82c1273dc8d724b87c49f1350881048c9e29d103eb481ecaeaaee
7
+ data.tar.gz: 4af18d3e1fb46313683ea91e9ba60fc9e62ee36237783fda16cc691fa1c37b3148336deb6be2ab44e966bb03d8e68690862113ba4156c6de0edd07baa15f8a8e
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.1 (16 November 2015)
2
+
3
+ - Modified `EnumNodeBase` to deal with either enum object instances or enum value
4
+ constants (e.g. `MyEnum::MY_VALUE` -- which happens to be the string value
5
+ of that enum instance, not the enum instance itself as one might expect).
6
+
1
7
  ## 0.2.0 (16 November 2015)
2
8
 
3
9
  - Fixed `EnumNodeBase` to correctly parse string values as enum instances,
@@ -22,7 +22,7 @@ module XML
22
22
  end
23
23
 
24
24
  def to_xml_text(value)
25
- value.value
25
+ value.respond_to?(:value) ? value.value : value.to_s
26
26
  end
27
27
 
28
28
  end
@@ -1,6 +1,6 @@
1
1
  module XML
2
2
  module MappingExtensions
3
3
  # The version of this gem
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
6
6
  end
data/spec/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_from: ../.rubocop.yml
2
+
3
+ Metrics/MethodLength:
4
+ Enabled: false
5
+
6
+ Metrics/ModuleLength:
7
+ Enabled: false
@@ -1,5 +1,51 @@
1
1
  require 'rspec/expectations'
2
2
  require 'mime/types'
3
+ require 'equivalent-xml'
4
+
5
+ RSpec::Matchers.define :be_xml do |expected|
6
+
7
+ def to_nokogiri(xml)
8
+ return nil unless xml
9
+ case xml
10
+ when Nokogiri::XML::Element
11
+ xml
12
+ when Nokogiri::XML::Document
13
+ xml.root
14
+ when String
15
+ to_nokogiri(Nokogiri::XML(xml))
16
+ when REXML::Element
17
+ to_nokogiri(xml.to_s)
18
+ else
19
+ fail "be_xml() expected XML, got #{xml.class}"
20
+ end
21
+ end
22
+
23
+ def to_pretty(nokogiri)
24
+ return nil unless nokogiri
25
+ out = StringIO.new
26
+ save_options = Nokogiri::XML::Node::SaveOptions::FORMAT | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
27
+ nokogiri.write_xml_to(out, encoding: 'UTF-8', indent: 2, save_with: save_options)
28
+ out.string
29
+ end
30
+
31
+ match do |actual|
32
+ expected_xml = to_nokogiri(expected) || fail("expected value #{expected} does not appear to be XML")
33
+ actual_xml = to_nokogiri(actual)
34
+
35
+ EquivalentXml.equivalent?(expected_xml, actual_xml, element_order: false, normalize_whitespace: true)
36
+ end
37
+
38
+ failure_message do |actual|
39
+ expected_string = to_pretty(to_nokogiri(expected))
40
+ actual_string = to_pretty(to_nokogiri(actual)) || actual
41
+ "expected XML:\n#{expected_string}\n\nbut was:\n#{actual_string}"
42
+ end
43
+
44
+ failure_message_when_negated do |actual|
45
+ actual_xml = to_element(actual) || actual
46
+ "expected not to get XML:\n\t#{actual_xml}"
47
+ end
48
+ end
3
49
 
4
50
  RSpec::Matchers.define :be_time do |expected|
5
51
 
@@ -20,6 +20,8 @@ module XML
20
20
  include ::XML::Mapping
21
21
  my_enum_node :my_enum, '@my_enum', default_value: nil
22
22
 
23
+ root_element_name 'elem'
24
+
23
25
  def self.from_str(enum_str)
24
26
  xml_string = enum_str ? "<elem my_enum='#{enum_str}'/>" : '<elem/>'
25
27
  doc = REXML::Document.new(xml_string)
@@ -58,6 +60,20 @@ module XML
58
60
  it 'doesn\'t set an attribute for a nil value' do
59
61
  expect(to_text(nil)).to be_nil
60
62
  end
63
+
64
+ it 'accepts enum constants' do
65
+ elem = EnumNodeBaseSpecElem.new
66
+ elem.my_enum = MyEnum::BAZ_QUX
67
+ xml_string = '<elem my_enum="baz_qux"/>'
68
+ expect(elem.save_to_xml).to be_xml(xml_string)
69
+ end
70
+
71
+ it 'round-trips to XML' do
72
+ xml_string = '<elem my_enum="baz_qux"/>'
73
+ doc = REXML::Document.new(xml_string)
74
+ elem = EnumNodeBaseSpecElem.load_from_xml(doc.root)
75
+ expect(elem.save_to_xml).to be_xml(xml_string)
76
+ end
61
77
  end
62
78
  end
63
79
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'ruby-enum', '~> 0.4'
27
27
  spec.add_dependency 'xml-mapping', '~> 0.10'
28
28
 
29
+ spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
29
30
  spec.add_development_dependency 'rake', '~> 10.4'
30
31
  spec.add_development_dependency 'rspec', '~> 3.2'
31
32
  spec.add_development_dependency 'rubocop', '~> 0.32.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml-mapping_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: equivalent-xml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - lib/xml/mapping_extensions/time_node.rb
176
190
  - lib/xml/mapping_extensions/uri_node.rb
177
191
  - lib/xml/mapping_extensions/version.rb
192
+ - spec/.rubocop.yml
178
193
  - spec/rspec_custom_matchers.rb
179
194
  - spec/spec_helper.rb
180
195
  - spec/unit/xml/mapping_extensions/date_node_spec.rb
@@ -209,6 +224,7 @@ signing_key:
209
224
  specification_version: 4
210
225
  summary: Some extensions for for XML::Mapping
211
226
  test_files:
227
+ - spec/.rubocop.yml
212
228
  - spec/rspec_custom_matchers.rb
213
229
  - spec/spec_helper.rb
214
230
  - spec/unit/xml/mapping_extensions/date_node_spec.rb