roxml 3.2.2 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -0
  3. data/Gemfile +9 -6
  4. data/Gemfile.lock +98 -40
  5. data/History.txt +15 -0
  6. data/README.rdoc +3 -2
  7. data/Rakefile +9 -21
  8. data/VERSION +1 -1
  9. data/examples/search_query.rb +17 -0
  10. data/lib/roxml.rb +9 -3
  11. data/lib/roxml/definition.rb +4 -9
  12. data/lib/roxml/xml/parsers/libxml.rb +11 -27
  13. data/lib/roxml/xml/parsers/nokogiri.rb +13 -26
  14. data/lib/roxml/xml/references.rb +33 -21
  15. data/roxml.gemspec +40 -40
  16. data/spec/definition_spec.rb +85 -104
  17. data/spec/examples/active_record_spec.rb +13 -13
  18. data/spec/examples/amazon_spec.rb +13 -13
  19. data/spec/examples/current_weather_spec.rb +6 -6
  20. data/spec/examples/dashed_elements_spec.rb +3 -3
  21. data/spec/examples/library_spec.rb +3 -3
  22. data/spec/examples/library_with_fines_spec.rb +7 -7
  23. data/spec/examples/person_spec.rb +27 -27
  24. data/spec/examples/post_spec.rb +4 -4
  25. data/spec/examples/search_query_spec.rb +26 -0
  26. data/spec/examples/twitter_spec.rb +4 -4
  27. data/spec/reference_spec.rb +2 -2
  28. data/spec/regression_spec.rb +13 -8
  29. data/spec/roxml_spec.rb +56 -61
  30. data/spec/shared_specs.rb +2 -2
  31. data/spec/spec_helper.rb +2 -0
  32. data/spec/xml/array_spec.rb +2 -2
  33. data/spec/xml/attributes_spec.rb +7 -7
  34. data/spec/xml/encoding_spec.rb +9 -9
  35. data/spec/xml/namespace_spec.rb +40 -21
  36. data/spec/xml/namespaces_spec.rb +3 -3
  37. data/spec/xml/object_spec.rb +7 -7
  38. data/spec/xml/parser_spec.rb +2 -8
  39. data/spec/xml/text_spec.rb +6 -6
  40. data/test/fixtures/book_with_octal_pages.xml +2 -3
  41. data/test/test_helper.rb +1 -2
  42. data/test/unit/definition_test.rb +26 -27
  43. data/test/unit/deprecations_test.rb +23 -2
  44. data/test/unit/to_xml_test.rb +9 -9
  45. data/test/unit/xml_attribute_test.rb +3 -2
  46. data/test/unit/xml_block_test.rb +3 -2
  47. data/test/unit/xml_bool_test.rb +7 -8
  48. data/test/unit/xml_convention_test.rb +4 -3
  49. data/test/unit/xml_hash_test.rb +5 -13
  50. data/test/unit/xml_initialize_test.rb +4 -3
  51. data/test/unit/xml_name_test.rb +3 -2
  52. data/test/unit/xml_namespace_test.rb +4 -3
  53. data/test/unit/xml_object_test.rb +8 -7
  54. data/test/unit/xml_required_test.rb +7 -6
  55. data/test/unit/xml_text_test.rb +3 -2
  56. data/website/index.html +11 -11
  57. metadata +114 -61
  58. data/test/load_test.rb +0 -6
@@ -46,37 +46,24 @@ module ROXML
46
46
  file << doc.serialize
47
47
  end
48
48
  end
49
- end
50
-
51
- Document = Nokogiri::XML::Document
52
- Element = Nokogiri::XML::Element
53
- Node = Nokogiri::XML::Node
54
-
55
- class Document
56
- alias :roxml_search :search
57
-
58
- def default_namespace
59
- 'xmlns' if root.namespaces['xmlns']
60
- end
61
- end
62
49
 
63
- module NodeExtensions
64
- def roxml_search(xpath, roxml_namespaces = {})
65
- xpath = "./#{xpath}"
66
- (roxml_namespaces.present? ? search(xpath, roxml_namespaces) : search(xpath))
50
+ def default_namespace(doc)
51
+ doc = doc.document if doc.respond_to?(:document)
52
+ 'xmlns' if doc.root.namespaces['xmlns']
67
53
  end
68
54
 
69
- def default_namespace
70
- document.default_namespace
55
+ def search(xml, xpath, roxml_namespaces = {})
56
+ case xml
57
+ when Nokogiri::XML::Document
58
+ xml.search(xpath, roxml_namespaces)
59
+ else
60
+ xpath = "./#{xpath}"
61
+ (roxml_namespaces.present? ? xml.search(xpath, roxml_namespaces) : xml.search(xpath))
62
+ end
71
63
  end
72
64
  end
73
65
 
74
- class Element
75
- include NodeExtensions
76
- end
77
-
78
- class Node
79
- include NodeExtensions
80
- end
66
+ Document = Nokogiri::XML::Document
67
+ Node = Nokogiri::XML::Node
81
68
  end
82
69
  end
@@ -1,5 +1,7 @@
1
+ require "rexml/xpath_parser"
2
+
1
3
  module ROXML
2
- class RequiredElementMissing < Exception # :nodoc:
4
+ class RequiredElementMissing < ArgumentError # :nodoc:
3
5
  end
4
6
 
5
7
  #
@@ -32,8 +34,9 @@ module ROXML
32
34
  end
33
35
 
34
36
  def value_in(xml)
35
- value = fetch_value(XML::Node.from(xml))
36
- value = default if value.nil?
37
+ xml = XML::Node.from(xml)
38
+ value = fetch_value(xml)
39
+ value = default if default && (value.nil? || value.to_s.empty?)
37
40
 
38
41
  value = apply_blocks(value)
39
42
  value = freeze(value) if value && opts.frozen?
@@ -51,20 +54,30 @@ module ROXML
51
54
  end
52
55
 
53
56
  def namespacify(what)
54
- if what.to_s.present? && !what.to_s.include?(':') && opts.namespace != false
55
- [opts.namespace, @instance.class.roxml_namespace, @default_namespace].each do |namespace|
56
- return opts.namespace == '*' ? (what == '*' ? "*" : "*[local-name()='#{what}']") : "#{namespace}:#{what}" if namespace
57
+ if what.to_s.present? && opts.namespace != false && ns = [opts.namespace, @instance.class.roxml_namespace, @default_namespace].compact.map(&:to_s).first
58
+ parser = REXML::Parsers::XPathParser.new
59
+ parsed = parser.parse what
60
+
61
+ parsed.each_cons(4).with_index.each do |a,i|
62
+ if a[0..2] == [:child, :qname, ""]
63
+ if ns == "*"
64
+ parsed[i+1,3] = [:any, :predicate, [:eq, [:function, "local-name", []], [:literal, a[3]]]] if a[3] != "*"
65
+ else
66
+ a[2].replace ns
67
+ end
68
+ end
57
69
  end
70
+
71
+ parser.abbreviate parsed
72
+ else
73
+ what
58
74
  end
59
- what
60
75
  end
61
76
 
62
77
  def apply_blocks(val)
63
- begin
64
- blocks.inject(val) {|val, block| block.call(val) }
65
- rescue Exception => ex
66
- raise ex, "#{accessor}: #{ex.message}"
67
- end
78
+ blocks.inject(val) {|val, block| block.call(val) }
79
+ rescue Exception => ex
80
+ raise ex, "#{accessor}: #{ex.message}"
68
81
  end
69
82
 
70
83
  def freeze(val)
@@ -90,26 +103,25 @@ module ROXML
90
103
 
91
104
  def wrap(xml, opts = {:always_create => false})
92
105
  wrap_with = @auto_vals ? auto_wrapper : wrapper
93
-
106
+
94
107
  return xml if !wrap_with || xml.name == wrap_with
95
108
 
96
109
  wraps = wrap_with.to_s.split('/')
97
- wraps.inject(xml) do |node,wrap|
98
- if !opts[:always_create] && (child = node.children.find {|c| c.name == wrap })
110
+ wraps.inject(xml) do |node,wrap|
111
+ if !opts[:always_create] && (child = node.children.find {|c| c.name == wrap })
99
112
  child
100
113
  else
101
- XML.add_node(node, wrap)
114
+ XML.add_node(node, wrap)
102
115
  end
103
- end
104
-
116
+ end
105
117
  end
106
118
 
107
119
  def nodes_in(xml)
108
- @default_namespace = xml.default_namespace
109
- vals = xml.roxml_search(xpath, @instance.class.roxml_namespaces)
120
+ @default_namespace = XML.default_namespace(xml)
121
+ vals = XML.search(xml, xpath, @instance.class.roxml_namespaces)
110
122
 
111
123
  if several? && vals.empty? && !wrapper && auto_xpath
112
- vals = xml.roxml_search(auto_xpath, @instance.class.roxml_namespaces)
124
+ vals = XML.search(xml, auto_xpath, @instance.class.roxml_namespaces)
113
125
  @auto_vals = !vals.empty?
114
126
  end
115
127
 
@@ -1,17 +1,19 @@
1
- # Generated by jeweler
1
+ # Generated by juwelier
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: roxml 4.1.1 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = "roxml"
8
- s.version = "3.2.2"
8
+ s.name = "roxml".freeze
9
+ s.version = "4.1.1"
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
12
- s.date = "2012-01-30"
13
- s.description = "ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.\nUsing simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care\nof the marshalling and unmarshalling of mapped attributes so that developers can focus on\nbuilding first-class Ruby classes. As a result, ROXML simplifies the development of\nRESTful applications, Web Services, and XML-RPC.\n"
14
- s.email = "ben.woosley@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Ben Woosley".freeze, "Zak Mandhro".freeze, "Anders Engstrom".freeze, "Russ Olsen".freeze]
14
+ s.date = "2020-07-06"
15
+ s.description = "ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML.\nUsing simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care\nof the marshalling and unmarshalling of mapped attributes so that developers can focus on\nbuilding first-class Ruby classes. As a result, ROXML simplifies the development of\nRESTful applications, Web Services, and XML-RPC.\n".freeze
16
+ s.email = "ben.woosley@gmail.com".freeze
15
17
  s.extra_rdoc_files = [
16
18
  "History.txt",
17
19
  "README.rdoc"
@@ -19,6 +21,7 @@ Gem::Specification.new do |s|
19
21
  s.files = [
20
22
  ".gitmodules",
21
23
  ".rspec",
24
+ ".travis.yml",
22
25
  "Gemfile",
23
26
  "Gemfile.lock",
24
27
  "History.txt",
@@ -35,6 +38,7 @@ Gem::Specification.new do |s|
35
38
  "examples/person.rb",
36
39
  "examples/posts.rb",
37
40
  "examples/rails.rb",
41
+ "examples/search_query.rb",
38
42
  "examples/twitter.rb",
39
43
  "examples/xml/active_record.xml",
40
44
  "examples/xml/amazon.xml",
@@ -61,6 +65,7 @@ Gem::Specification.new do |s|
61
65
  "spec/examples/library_with_fines_spec.rb",
62
66
  "spec/examples/person_spec.rb",
63
67
  "spec/examples/post_spec.rb",
68
+ "spec/examples/search_query_spec.rb",
64
69
  "spec/examples/twitter_spec.rb",
65
70
  "spec/reference_spec.rb",
66
71
  "spec/regression_spec.rb",
@@ -107,7 +112,6 @@ Gem::Specification.new do |s|
107
112
  "test/fixtures/person.xml",
108
113
  "test/fixtures/person_with_guarded_mothers.xml",
109
114
  "test/fixtures/person_with_mothers.xml",
110
- "test/load_test.rb",
111
115
  "test/mocks/dictionaries.rb",
112
116
  "test/mocks/mocks.rb",
113
117
  "test/support/fixtures.rb",
@@ -128,40 +132,36 @@ Gem::Specification.new do |s|
128
132
  "test/unit/xml_text_test.rb",
129
133
  "website/index.html"
130
134
  ]
131
- s.homepage = "http://roxml.rubyforge.org"
132
- s.require_paths = ["lib"]
133
- s.rubyforge_project = "roxml"
134
- s.rubygems_version = "1.8.10"
135
- s.summary = "Ruby Object to XML mapping library"
135
+ s.homepage = "https://github.com/Empact/roxml".freeze
136
+ s.rubygems_version = "3.1.2".freeze
137
+ s.summary = "Ruby Object to XML mapping library".freeze
136
138
 
137
139
  if s.respond_to? :specification_version then
138
- s.specification_version = 3
140
+ s.specification_version = 4
141
+ end
139
142
 
140
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
141
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.0"])
142
- s.add_runtime_dependency(%q<nokogiri>, [">= 1.3.3"])
143
- s.add_development_dependency(%q<rake>, [">= 0"])
144
- s.add_development_dependency(%q<jeweler>, [">= 0"])
145
- s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
146
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
147
- s.add_development_dependency(%q<activerecord>, [">= 2.2.2"])
148
- else
149
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
150
- s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
151
- s.add_dependency(%q<rake>, [">= 0"])
152
- s.add_dependency(%q<jeweler>, [">= 0"])
153
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
154
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
155
- s.add_dependency(%q<activerecord>, [">= 2.2.2"])
156
- end
143
+ if s.respond_to? :add_runtime_dependency then
144
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
145
+ s.add_runtime_dependency(%q<nokogiri>.freeze, [">= 1.3.3"])
146
+ s.add_development_dependency(%q<rake>.freeze, ["~> 0.9"])
147
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
148
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
149
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.7.0"])
150
+ s.add_development_dependency(%q<sqlite3>.freeze, [">= 1.2.4"])
151
+ s.add_development_dependency(%q<activerecord>.freeze, [">= 4.0"])
152
+ s.add_development_dependency(%q<rack>.freeze, ["< 2.0.0"])
153
+ s.add_development_dependency(%q<equivalent-xml>.freeze, [">= 0.6.0"])
157
154
  else
158
- s.add_dependency(%q<activesupport>, [">= 2.3.0"])
159
- s.add_dependency(%q<nokogiri>, [">= 1.3.3"])
160
- s.add_dependency(%q<rake>, [">= 0"])
161
- s.add_dependency(%q<jeweler>, [">= 0"])
162
- s.add_dependency(%q<rspec>, [">= 2.0.0"])
163
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.4"])
164
- s.add_dependency(%q<activerecord>, [">= 2.2.2"])
155
+ s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
156
+ s.add_dependency(%q<nokogiri>.freeze, [">= 1.3.3"])
157
+ s.add_dependency(%q<rake>.freeze, ["~> 0.9"])
158
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
159
+ s.add_dependency(%q<minitest>.freeze, [">= 0"])
160
+ s.add_dependency(%q<rspec>.freeze, ["~> 3.7.0"])
161
+ s.add_dependency(%q<sqlite3>.freeze, [">= 1.2.4"])
162
+ s.add_dependency(%q<activerecord>.freeze, [">= 4.0"])
163
+ s.add_dependency(%q<rack>.freeze, ["< 2.0.0"])
164
+ s.add_dependency(%q<equivalent-xml>.freeze, [">= 0.6.0"])
165
165
  end
166
166
  end
167
167
 
@@ -4,19 +4,19 @@ require_relative './spec_helper'
4
4
  describe ROXML::Definition do
5
5
  describe "#name_explicit?" do
6
6
  it "should indicate whether from option is present" do
7
- ROXML::Definition.new(:element, :from => 'somewhere').name_explicit?.should be_true
8
- ROXML::Definition.new(:element).name_explicit?.should be_false
7
+ expect(ROXML::Definition.new(:element, :from => 'somewhere').name_explicit?).to be_truthy
8
+ expect(ROXML::Definition.new(:element).name_explicit?).to be_falsey
9
9
  end
10
10
 
11
11
  it "should not consider name proxies as explicit" do
12
- ROXML::Definition.new(:element, :from => :attr).name_explicit?.should be_false
13
- ROXML::Definition.new(:element, :from => :content).name_explicit?.should be_false
12
+ expect(ROXML::Definition.new(:element, :from => :attr).name_explicit?).to be_falsey
13
+ expect(ROXML::Definition.new(:element, :from => :content).name_explicit?).to be_falsey
14
14
  end
15
15
  end
16
16
 
17
17
  shared_examples_for "DateTime reference" do
18
18
  it "should return nil on empty string" do
19
- @subject.blocks.first.call(" ").should be_nil
19
+ expect(@subject.blocks.first.call(" ")).to be_nil
20
20
  end
21
21
 
22
22
  it "should return a time version of the string" do
@@ -25,14 +25,14 @@ describe ROXML::Definition do
25
25
 
26
26
  context "when passed an array of values" do
27
27
  it "should timify all of them" do
28
- @subject.blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s).should == ["1970-09-03T12:05:00+00:00", "1700-05-22T15:00:00+00:00"]
28
+ expect(@subject.blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s)).to eq(["1970-09-03T12:05:00+00:00", "1700-05-22T15:00:00+00:00"])
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
33
  shared_examples_for "Date reference" do
34
34
  it "should return nil on empty string" do
35
- @subject.blocks.first.call(" ").should be_nil
35
+ expect(@subject.blocks.first.call(" ")).to be_nil
36
36
  end
37
37
 
38
38
  it "should return a time version of the string" do
@@ -41,26 +41,26 @@ describe ROXML::Definition do
41
41
 
42
42
  context "when passed an array of values" do
43
43
  it "should timify all of them" do
44
- @subject.blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s).should == ["1970-09-03", "1776-07-04"]
44
+ expect(@subject.blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s)).to eq(["1970-09-03", "1776-07-04"])
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
49
  it "should unescape xml entities" do
50
- ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
50
+ expect(ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
51
51
  <xml>
52
52
  <question>&quot;Wickard &amp; Filburn&quot; &gt;</question>
53
53
  <question> &lt; McCulloch &amp; Maryland?</question>
54
54
  </xml>
55
- }).should == ["\"Wickard & Filburn\" >", " < McCulloch & Maryland?"]
55
+ })).to eq(["\"Wickard & Filburn\" >", " < McCulloch & Maryland?"])
56
56
  end
57
57
 
58
58
  it "should unescape utf characters in xml" do
59
- ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
59
+ expect(ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
60
60
  <xml>
61
61
  <question>ROXML\342\204\242</question>
62
62
  </xml>
63
- }).should == ["ROXML™"]
63
+ })).to eq(["ROXML™"])
64
64
  end
65
65
 
66
66
  describe "attr name" do
@@ -87,8 +87,8 @@ describe ROXML::Definition do
87
87
  describe "=> []" do
88
88
  it "should means array of texts" do
89
89
  opts = ROXML::Definition.new(:authors, :as => [])
90
- opts.array?.should be_true
91
- opts.sought_type.should == :text
90
+ expect(opts.array?).to be_truthy
91
+ expect(opts.sought_type).to eq(:text)
92
92
  end
93
93
  end
94
94
 
@@ -99,7 +99,7 @@ describe ROXML::Definition do
99
99
 
100
100
  it "should store type" do
101
101
  opts = ROXML::Definition.new(:name, :as => RoxmlClass)
102
- opts.sought_type.should == RoxmlClass
102
+ expect(opts.sought_type).to eq(RoxmlClass)
103
103
  end
104
104
  end
105
105
 
@@ -112,35 +112,35 @@ describe ROXML::Definition do
112
112
 
113
113
  it "should accept type" do
114
114
  opts = ROXML::Definition.new(:name, :as => OctalInteger)
115
- opts.sought_type.should == OctalInteger
115
+ expect(opts.sought_type).to eq(OctalInteger)
116
116
  end
117
117
  end
118
118
 
119
119
  describe "=> NonRoxmlClass" do
120
120
  it "should fail with a warning" do
121
- proc { ROXML::Definition.new(:authors, :as => Module) }.should raise_error(ArgumentError)
121
+ expect { ROXML::Definition.new(:authors, :as => Module) }.to raise_error(ArgumentError)
122
122
  end
123
123
  end
124
124
 
125
125
  describe "=> [NonRoxmlClass]" do
126
126
  it "should raise" do
127
- proc { ROXML::Definition.new(:authors, :as => [Module]) }.should raise_error(ArgumentError)
127
+ expect { ROXML::Definition.new(:authors, :as => [Module]) }.to raise_error(ArgumentError)
128
128
  end
129
129
  end
130
130
 
131
131
  describe "=> {}" do
132
132
  shared_examples_for "hash options declaration" do
133
133
  it "should represent a hash" do
134
- @opts.hash?.should be_true
134
+ expect(@opts.hash?).to be_truthy
135
135
  end
136
136
 
137
137
  it "should have hash definition" do
138
- {@opts.hash.key.sought_type => @opts.hash.key.name}.should == @hash_args[:key]
139
- {@opts.hash.value.sought_type => @opts.hash.value.name}.should == @hash_args[:value]
138
+ expect({@opts.hash.key.sought_type => @opts.hash.key.name}).to eq(@hash_args[:key])
139
+ expect({@opts.hash.value.sought_type => @opts.hash.value.name}).to eq(@hash_args[:value])
140
140
  end
141
141
 
142
142
  it "should not represent an array" do
143
- @opts.array?.should be_false
143
+ expect(@opts.array?).to be_falsey
144
144
  end
145
145
  end
146
146
 
@@ -193,32 +193,32 @@ describe ROXML::Definition do
193
193
  end
194
194
 
195
195
  it "should be detected as array reference" do
196
- @opts.array?.should be_true
196
+ expect(@opts.array?).to be_truthy
197
197
  end
198
198
 
199
199
  it "should be normal otherwise" do
200
- @opts.sought_type.should == :text
201
- @opts.blocks.size.should == 1
200
+ expect(@opts.sought_type).to eq(:text)
201
+ expect(@opts.blocks.size).to eq(1)
202
202
  end
203
203
  end
204
204
 
205
205
  it "should have no blocks without a shorthand" do
206
- ROXML::Definition.new(:count).blocks.should be_empty
206
+ expect(ROXML::Definition.new(:count).blocks).to be_empty
207
207
  end
208
208
 
209
209
  it "should raise on unknown :as" do
210
- proc { ROXML::Definition.new(:count, :as => :bogus) }.should raise_error(ArgumentError)
211
- proc { ROXML::Definition.new(:count, :as => :foat) }.should raise_error(ArgumentError)
210
+ expect { ROXML::Definition.new(:count, :as => :bogus) }.to raise_error(ArgumentError)
211
+ expect { ROXML::Definition.new(:count, :as => :foat) }.to raise_error(ArgumentError)
212
212
  end
213
213
 
214
214
  shared_examples_for "block shorthand type declaration" do
215
215
  it "should translate nil to nil" do
216
- @definition.blocks.first.call(nil).should be_nil
216
+ expect(@definition.blocks.first.call(nil)).to be_nil
217
217
  end
218
218
 
219
219
  it "should translate empty strings to nil" do
220
- @definition.blocks.first.call("").should be_nil
221
- @definition.blocks.first.call(" ").should be_nil
220
+ expect(@definition.blocks.first.call("")).to be_nil
221
+ expect(@definition.blocks.first.call(" ")).to be_nil
222
222
  end
223
223
  end
224
224
 
@@ -230,20 +230,21 @@ describe ROXML::Definition do
230
230
  it_should_behave_like "block shorthand type declaration"
231
231
 
232
232
  it "should translate text to integers" do
233
- @definition.blocks.first['3'].should == 3
234
- @definition.blocks.first['792'].should == 792
233
+ expect(@definition.blocks.first['3']).to eq(3)
234
+ expect(@definition.blocks.first['792']).to eq(792)
235
+ expect(@definition.blocks.first['08']).to eq(8)
236
+ expect(@definition.blocks.first['279.23']).to eq(279)
235
237
  end
236
238
 
237
- it "should raise on non-integer values" do
238
- proc { @definition.blocks.first['08'] }.should raise_error(ArgumentError)
239
- proc { @definition.blocks.first['793.12'] }.should raise_error(ArgumentError)
240
- proc { @definition.blocks.first['junk 11'] }.should raise_error(ArgumentError)
241
- proc { @definition.blocks.first['11sttf'] }.should raise_error(ArgumentError)
239
+ it "should extract whatever is possible and fall back to 0" do
240
+ expect(@definition.blocks.first['junk 11']).to eql(0)
241
+ expect(@definition.blocks.first['.?sttf']).to eql(0)
242
+ expect(@definition.blocks.first['11sttf']).to eql(11)
242
243
  end
243
244
 
244
245
  context "when passed an array" do
245
246
  it "should translate the array elements to integer" do
246
- @definition.blocks.first.call(["792", "12", "328"]).should == [792, 12, 328]
247
+ expect(@definition.blocks.first.call(["792", "12", "328"])).to eq([792, 12, 328])
247
248
  end
248
249
  end
249
250
  end
@@ -256,18 +257,18 @@ describe ROXML::Definition do
256
257
  it_should_behave_like "block shorthand type declaration"
257
258
 
258
259
  it "should translate text to float" do
259
- @definition.blocks.first['3'].should == 3.0
260
- @definition.blocks.first['12.7'].should == 12.7
260
+ expect(@definition.blocks.first['3']).to eq(3.0)
261
+ expect(@definition.blocks.first['12.7']).to eq(12.7)
261
262
  end
262
263
 
263
264
  it "should raise on non-float values" do
264
- proc { @definition.blocks.first['junk 11.3'] }.should raise_error(ArgumentError)
265
- proc { @definition.blocks.first['11.1sttf'] }.should raise_error(ArgumentError)
265
+ expect { @definition.blocks.first['junk 11.3'] }.to raise_error(ArgumentError)
266
+ expect { @definition.blocks.first['11.1sttf'] }.to raise_error(ArgumentError)
266
267
  end
267
268
 
268
269
  context "when passed an array" do
269
270
  it "should translate the array elements to integer" do
270
- @definition.blocks.first.call(["792.13", "240", "3.14"]).should == [792.13, 240.0, 3.14]
271
+ expect(@definition.blocks.first.call(["792.13", "240", "3.14"])).to eq([792.13, 240.0, 3.14])
271
272
  end
272
273
  end
273
274
  end
@@ -280,67 +281,42 @@ describe ROXML::Definition do
280
281
  it_should_behave_like "block shorthand type declaration"
281
282
 
282
283
  it "should translate text to decimal numbers" do
283
- @definition.blocks.first['3'].should == BigDecimal.new("3.0")
284
- @definition.blocks.first['0.3'].should == BigDecimal.new("0.3")
285
- end
286
-
287
- it "should extract what it can, and fall back to 0" do
288
- @definition.blocks.first['junk 11'].should eql(BigDecimal.new("0"))
289
- @definition.blocks.first['11sttf'].should eql(BigDecimal.new("11.0"))
284
+ expect(@definition.blocks.first['3']).to eq(BigDecimal("3.0"))
285
+ expect(@definition.blocks.first['0.3']).to eq(BigDecimal("0.3"))
290
286
  end
291
287
 
292
- context "when passed an array" do
293
- it "should translate the array elements to integer" do
294
- @definition.blocks.first.call(["12.1", "328.2"]).should == [BigDecimal.new("12.1"), BigDecimal.new("328.2")]
288
+ # Ruby behavior of BigDecimal changed in 2.4, this test is not valid on older rubies
289
+ if RUBY_VERSION >= "2.4"
290
+ it "should raise on non-decimal values" do
291
+ expect { @definition.blocks.first['junk 11'] }.to raise_error(ArgumentError)
295
292
  end
296
293
  end
297
- end
298
-
299
- describe "Fixnum" do
300
- before do
301
- @definition = ROXML::Definition.new(:fixnumvalue, :as => Fixnum)
302
- end
303
-
304
- it_should_behave_like "block shorthand type declaration"
305
-
306
- it "should translate text to integers" do
307
- @definition.blocks.first['3'].should == 3
308
- @definition.blocks.first['792'].should == 792
309
- @definition.blocks.first['08'].should == 8
310
- @definition.blocks.first['279.23'].should == 279
311
- end
312
-
313
- it "should extract whatever is possible and fall back to 0" do
314
- @definition.blocks.first['junk 11'].should eql(0)
315
- @definition.blocks.first['.?sttf'].should eql(0)
316
- @definition.blocks.first['11sttf'].should eql(11)
317
- end
318
294
 
319
295
  context "when passed an array" do
320
296
  it "should translate the array elements to integer" do
321
- @definition.blocks.first.call(["792", "12", "328"]).should == [792, 12, 328]
297
+ expect(@definition.blocks.first.call(["12.1", "328.2"])).to eq([BigDecimal("12.1"), BigDecimal("328.2")])
322
298
  end
323
299
  end
324
300
  end
325
301
 
326
302
  describe ":bool" do
327
303
  it "should boolify individual values" do
328
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("1").should be_true
329
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("True").should be_true
330
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("Yes").should be_true
304
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("1")).to be_truthy
305
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("True")).to be_truthy
306
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("Yes")).to be_truthy
331
307
  end
332
308
 
333
309
  context "when an array is passed in" do
334
310
  it "should boolify arrays of values" do
335
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("0").should be_false
336
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("false").should be_false
337
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("nO").should be_false
311
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("0")).to be_falsey
312
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("false")).to be_falsey
313
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("nO")).to be_falsey
338
314
  end
339
315
  end
340
316
 
341
317
  context "when no value is detected" do
342
318
  it "should return nil" do
343
- ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("junk").should be_nil
319
+ expect(ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("junk")).to be_nil
344
320
  end
345
321
 
346
322
  context "when a literal block is available" do
@@ -351,16 +327,16 @@ describe ROXML::Definition do
351
327
 
352
328
  describe "Time" do
353
329
  it "should return nil on empty string" do
354
- ROXML::Definition.new(:floatvalue, :as => Time).blocks.first.call(" ").should be_nil
330
+ expect(ROXML::Definition.new(:floatvalue, :as => Time).blocks.first.call(" ")).to be_nil
355
331
  end
356
332
 
357
333
  it "should return a time version of the string" do
358
- ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call("12:31am").min.should == 31
334
+ expect(ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call("12:31am").min).to eq(31)
359
335
  end
360
336
 
361
337
  context "when passed an array of values" do
362
338
  it "should timify all of them" do
363
- ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call(["12:31am", "3:00pm", "11:59pm"]).map(&:min).should == [31, 0, 59]
339
+ expect(ROXML::Definition.new(:datevalue, :as => Time).blocks.first.call(["12:31am", "3:00pm", "11:59pm"]).map(&:min)).to eq([31, 0, 59])
364
340
  end
365
341
  end
366
342
  end
@@ -380,12 +356,12 @@ describe ROXML::Definition do
380
356
  end
381
357
 
382
358
  it "should prohibit multiple shorthands" do
383
- proc { ROXML::Definition.new(:count, :as => [Float, Integer]) }.should raise_error(ArgumentError)
359
+ expect { ROXML::Definition.new(:count, :as => [Float, Integer]) }.to raise_error(ArgumentError)
384
360
  end
385
361
 
386
362
  it "should stack block shorthands with explicit blocks" do
387
- ROXML::Definition.new(:count, :as => Integer) {|val| val.to_i }.blocks.size.should == 2
388
- ROXML::Definition.new(:count, :as => Float) {|val| val.object_id }.blocks.size.should == 2
363
+ expect(ROXML::Definition.new(:count, :as => Integer) {|val| val.to_i }.blocks.size).to eq(2)
364
+ expect(ROXML::Definition.new(:count, :as => Float) {|val| val.object_id }.blocks.size).to eq(2)
389
365
  end
390
366
  end
391
367
  end
@@ -393,17 +369,17 @@ describe ROXML::Definition do
393
369
  describe ":from" do
394
370
  shared_examples_for "attribute reference" do
395
371
  it "should be interpreted as :attr" do
396
- @opts.sought_type.should == :attr
372
+ expect(@opts.sought_type).to eq(:attr)
397
373
  end
398
374
 
399
375
  it "should strip '@' from name" do
400
- @opts.name.should == 'attr_name'
376
+ expect(@opts.name).to eq('attr_name')
401
377
  end
402
378
 
403
379
  it "should unescape xml entities" do
404
- @opts.to_ref(RoxmlObject.new).value_in(%{
380
+ expect(@opts.to_ref(RoxmlObject.new).value_in(%{
405
381
  <question attr_name="&quot;Wickard &amp; Filburn&quot; &gt; / &lt; McCulloch &amp; Marryland?" />
406
- }).should == "\"Wickard & Filburn\" > / < McCulloch & Marryland?"
382
+ })).to eq("\"Wickard & Filburn\" > / < McCulloch & Marryland?")
407
383
  end
408
384
  end
409
385
 
@@ -425,12 +401,12 @@ describe ROXML::Definition do
425
401
 
426
402
  describe ":content" do
427
403
  it "should be recognized" do
428
- ROXML::Definition.new(:author).content?.should be_false
429
- ROXML::Definition.new(:author, :from => :content).content?.should == true
404
+ expect(ROXML::Definition.new(:author).content?).to be_falsey
405
+ expect(ROXML::Definition.new(:author, :from => :content).content?).to eq(true)
430
406
  end
431
407
 
432
408
  it "should be equivalent to :from => '.'" do
433
- ROXML::Definition.new(:author, :from => '.').content?.should == true
409
+ expect(ROXML::Definition.new(:author, :from => '.').content?).to eq(true)
434
410
  end
435
411
  end
436
412
  end
@@ -438,28 +414,27 @@ describe ROXML::Definition do
438
414
  describe ":in" do
439
415
  context "as xpath" do
440
416
  it "should pass through as wrapper" do
441
- ROXML::Definition.new(:manufacturer, :in => './').wrapper.should == './'
417
+ expect(ROXML::Definition.new(:manufacturer, :in => './').wrapper).to eq('./')
442
418
  end
443
419
  end
444
420
 
445
421
  context "as xpath" do
446
422
  it "should pass through as wrapper" do
447
- ROXML::Definition.new(:manufacturer, :in => 'wrapper').wrapper.should == 'wrapper'
423
+ expect(ROXML::Definition.new(:manufacturer, :in => 'wrapper').wrapper).to eq('wrapper')
448
424
  end
449
425
  end
450
426
  end
451
427
 
452
428
  describe "options" do
453
-
454
429
  shared_examples_for "boolean option" do
455
430
  it "should be recognized" do
456
431
  ROXML::Definition.new(:author, :from => :content, @option => true).respond_to?(:"#{@option}?")
457
- ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?").should be_true
458
- ROXML::Definition.new(:author, :from => :content, @option => false).send(:"#{@option}?").should be_false
432
+ expect(ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?")).to be_truthy
433
+ expect(ROXML::Definition.new(:author, :from => :content, @option => false).send(:"#{@option}?")).to be_falsey
459
434
  end
460
435
 
461
436
  it "should default to false" do
462
- ROXML::Definition.new(:author, :from => :content).send(:"#{@option}?").should be_false
437
+ expect(ROXML::Definition.new(:author, :from => :content).send(:"#{@option}?")).to be_falsey
463
438
  end
464
439
  end
465
440
 
@@ -471,8 +446,8 @@ describe ROXML::Definition do
471
446
  it_should_behave_like "boolean option"
472
447
 
473
448
  it "should not be allowed together with :else" do
474
- proc { ROXML::Definition.new(:author, :from => :content, :required => true, :else => 'Johnny') }.should raise_error(ArgumentError)
475
- proc { ROXML::Definition.new(:author, :from => :content, :required => false, :else => 'Johnny') }.should_not raise_error
449
+ expect { ROXML::Definition.new(:author, :from => :content, :required => true, :else => 'Johnny') }.to raise_error(ArgumentError)
450
+ expect { ROXML::Definition.new(:author, :from => :content, :required => false, :else => 'Johnny') }.to_not raise_error
476
451
  end
477
452
  end
478
453
 
@@ -492,4 +467,10 @@ describe ROXML::Definition do
492
467
  it_should_behave_like "boolean option"
493
468
  end
494
469
  end
470
+
471
+ describe 'frozen_string_literal behavior' do
472
+ it 'should not raise error' do
473
+ expect { ROXML::Definition.new(:element, :from => '@somewhere'.freeze) }.not_to raise_error(FrozenError)
474
+ end
475
+ end
495
476
  end