nom-xml 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8abc2d0f36fabb997f6ff163e1670b7cafc87fe
4
+ data.tar.gz: daa5e3899254a527f80d0762825b201f77177d96
5
+ SHA512:
6
+ metadata.gz: 75349d3a759439a1b24b1d4b10042e4bce8536e6cbb97b6383b2663914a6bd0acbf0f414bedd4b15a2b0539fc50fc195e1239dd3e11cf85178d0a1cf05f64f1f
7
+ data.tar.gz: 35099fbec920fc5ef8e47f688ee1a92925da789588666006ac0718c006fc153000f8852ecfd08d62573bb75a5da2fcaabd60ab61c1e04f52e0c901c5cfc98c93
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .DS_Store
2
+ .bundle
3
+ .idea
4
+ .ruby-gemset
5
+ .ruby-version
6
+ .rvmrc
7
+ .yardoc
8
+ *.gem
9
+ Gemfile.lock
10
+ coverage
11
+ coverage.data
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml CHANGED
@@ -1,6 +1,13 @@
1
+ notifications:
2
+ email: false
3
+
4
+ gemfile:
5
+ - gemfiles/rails3.gemfile
6
+ - gemfiles/rails4.gemfile
7
+
1
8
  rvm:
2
- - "1.9.3"
9
+ - 1.9.3
3
10
  - jruby-19mode
4
11
  - rbx-19mode
5
- - jruby-18mode
6
- - "1.8.7"
12
+ - 2.0.0
13
+ - 2.1.2
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -6,5 +6,3 @@ gem 'simplecov', :platform => :ruby_19
6
6
  gem 'rcov', :platform => :ruby_18
7
7
  gem 'debugger', :platform => :mri_19
8
8
  gem "redcarpet", :platform => :ruby_19
9
-
10
- gem 'nokogiri', '1.5.6.rc2'
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../"
4
+
5
+ gem 'activesupport', '~> 3.2', '>= 3.2.18'
6
+
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../"
4
+
5
+ gem 'activesupport', '~> 4.1'
6
+
@@ -1,6 +1,6 @@
1
1
  module Nom::XML::Decorators::NodeSet
2
-
3
- def values_for_term term
2
+
3
+ def values_for_term term
4
4
  result = self
5
5
  result = result.select &(term.options[:if]) if term.options[:if].is_a? Proc
6
6
  result = result.reject &(term.options[:unless]) if term.options[:unless].is_a? Proc
@@ -22,30 +22,31 @@ module Nom::XML::Decorators::NodeSet
22
22
  end
23
23
 
24
24
  return return_value
25
- end
25
+ end
26
26
 
27
- ##
28
- # Add a #method_missing handler to NodeSets. If all of the elements in the Nodeset
29
- # respond to a method (e.g. if it is a term accessor), call that method on all the
30
- # elements in the node
31
- def method_missing sym, *args, &block
32
- if self.all? { |node| node.respond_to? sym }
33
- result = self.collect { |node| node.send(sym, *args, &block) }.flatten
34
- self.class.new(self.document, result) rescue result
35
- else
27
+ ##
28
+ # Add a #method_missing handler to NodeSets. If all of the elements in the Nodeset
29
+ # respond to a method (e.g. if it is a term accessor), call that method on all the
30
+ # elements in the node
31
+ def method_missing sym, *args, &block
32
+ if self.all? { |node| node.respond_to? sym }
33
+ result = self.collect { |node| node.send(sym, *args, &block) }.flatten
34
+ self.class.new(self.document, result) rescue result
35
+ else
36
36
  begin
37
37
  self.document.template_registry.send(sym, self, *args, &block)
38
38
  rescue NameError
39
39
  super
40
40
  end
41
- end
42
- end
41
+ end
42
+ end
43
43
 
44
- def respond_to? sym
44
+ # ruby 2.0 sends two arguments to respond_to?
45
+ def respond_to? sym, priv = false
45
46
  if self.all? { |node| node.respond_to? sym }
46
- true
47
+ true
47
48
  else
48
- super
49
+ super
49
50
  end
50
- end
51
+ end
51
52
  end
@@ -30,7 +30,10 @@ module Nom::XML::Decorators::Terminology
30
30
 
31
31
  alias_method :respond_to_without_terms?, :respond_to?
32
32
 
33
- def respond_to? method
33
+ # As of ruby 2.0, respond_to includes an optional 2nd arg:
34
+ # a boolean controlling whether private methods are targeted.
35
+ # We don't actually care for term accessors (none private).
36
+ def respond_to? method, private = false
34
37
  super || self.term_accessors[method.to_sym]
35
38
  end
36
39
 
@@ -39,7 +42,7 @@ module Nom::XML::Decorators::Terminology
39
42
  def terms
40
43
  @terms ||= self.ancestors.map { |p| p.term_accessors(self).map { |keys, values| values } }.flatten.compact.uniq
41
44
  end
42
-
45
+
43
46
  protected
44
47
  ##
45
48
  # Collection of salient terminology accessors for this node
@@ -6,19 +6,14 @@ module Nom::XML
6
6
  ##
7
7
  # Apply NOM decorators to Nokogiri classes
8
8
  def nom!
9
- unless decorators(Nokogiri::XML::Node).include? Nom::XML::Decorators::Terminology
10
- decorators(Nokogiri::XML::Node) << Nom::XML::Decorators::Terminology
11
- end
12
- unless decorators(Nokogiri::XML::Attr).include? Nom::XML::Decorators::Terminology
13
- decorators(Nokogiri::XML::Attr) << Nom::XML::Decorators::Terminology
14
- end
15
-
16
- unless decorators(Nokogiri::XML::NodeSet).include? Nom::XML::Decorators::NodeSet
17
- decorators(Nokogiri::XML::NodeSet) << Nom::XML::Decorators::NodeSet
18
- end
19
-
20
- unless decorators(Nokogiri::XML::Document).include? Nom::XML::Decorators::TemplateRegistry
21
- decorators(Nokogiri::XML::Document) << Nom::XML::Decorators::TemplateRegistry
9
+ decorations = {
10
+ Nokogiri::XML::Node => Nom::XML::Decorators::Terminology,
11
+ Nokogiri::XML::Attr => Nom::XML::Decorators::Terminology,
12
+ Nokogiri::XML::NodeSet => Nom::XML::Decorators::NodeSet,
13
+ Nokogiri::XML::Document => Nom::XML::Decorators::TemplateRegistry
14
+ }
15
+ decorations.each_pair do |host, decorator|
16
+ decorators(host) << decorator unless decorators(host).include? decorator
22
17
  end
23
18
 
24
19
  decorate!
@@ -1,5 +1,5 @@
1
1
  module Nom
2
2
  module XML
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.2'
4
4
  end
5
5
  end
data/nom-xml.gemspec CHANGED
@@ -12,14 +12,15 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{ A library to help you tame sprawling XML schemas. }
13
13
  s.description = %q{ NOM allows you to define a “terminology” to ease translation between XML and ruby objects }
14
14
 
15
- s.add_dependency 'activesupport'
15
+ s.add_dependency 'activesupport', '>= 3.2.18' # could be rails/AS 3 or 4+, but we don't support old insecure versions
16
16
  s.add_dependency 'i18n'
17
17
  s.add_dependency 'nokogiri'
18
18
 
19
- s.add_development_dependency "rspec"
19
+ s.add_development_dependency 'equivalent-xml', '~> 0.5.1'
20
+ s.add_development_dependency 'rspec', '~> 3.1'
20
21
  s.add_development_dependency "rake"
21
22
  s.add_development_dependency "yard"
22
- s.add_development_dependency "equivalent-xml"
23
+
23
24
  s.files = `git ls-files`.split("\n")
24
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -40,76 +40,76 @@ describe "Namespaces example" do
40
40
  }
41
41
 
42
42
  it "should work with existing reserved method names when override is present" do
43
- subject.author.first.description.text.should include('asdf')
43
+ expect(subject.author.first.description.text).to include('asdf')
44
44
  end
45
45
 
46
46
  it "should return nodesets by default" do
47
- subject.personal_authors.should be_a_kind_of(Nokogiri::XML::NodeSet)
47
+ expect(subject.personal_authors).to be_a_kind_of(Nokogiri::XML::NodeSet)
48
48
  end
49
49
 
50
50
  it "should return single elements on demand" do
51
- subject.personal_authors.first.namePart.should be_a_kind_of(Nokogiri::XML::Element)
51
+ expect(subject.personal_authors.first.namePart).to be_a_kind_of(Nokogiri::XML::Element)
52
52
  end
53
53
 
54
54
  it "should return attributes as single-valued" do
55
- subject.personal_authors.first.valueURI.should be_a_kind_of(Nokogiri::XML::Attr)
55
+ expect(subject.personal_authors.first.valueURI).to be_a_kind_of(Nokogiri::XML::Attr)
56
56
  end
57
57
 
58
58
 
59
59
  it "should treat attributes with an accessor as a single-able element" do
60
- subject.author.first.authorityURI.should == 'http://id.loc.gov/authorities/names'
60
+ expect(subject.author.first.authorityURI).to eq('http://id.loc.gov/authorities/names')
61
61
  end
62
62
 
63
63
  it "should share terms over matched nodes" do
64
- subject.personal_authors.first.namePart.text.should == "Alterman, Eric"
64
+ expect(subject.personal_authors.first.namePart.text).to eq("Alterman, Eric")
65
65
  end
66
66
 
67
67
  it "should return single elements out of nodesets correctly" do
68
- subject.personal_authors.namePart.should be_a_kind_of(Nokogiri::XML::NodeSet)
68
+ expect(subject.personal_authors.namePart).to be_a_kind_of(Nokogiri::XML::NodeSet)
69
69
  end
70
70
 
71
71
  it "should create enumerable objects" do
72
- subject.personal_authors.should respond_to(:each)
73
- subject.personal_authors.should have(1).node
72
+ expect(subject.personal_authors).to respond_to(:each)
73
+ expect(subject.personal_authors.size).to eq(1)
74
74
  end
75
75
 
76
76
  it "should provide accessors" do
77
77
  eric =subject.personal_authors.first
78
78
 
79
- eric.namePart.text.should == "Alterman, Eric"
80
- eric.roleTerm.text.should == "creator"
79
+ expect(eric.namePart.text).to eq("Alterman, Eric")
80
+ expect(eric.roleTerm.text).to eq("creator")
81
81
 
82
- eric.roleTerm._type.text.should == "text"
82
+ expect(eric.roleTerm._type.text).to eq("text")
83
83
  end
84
84
 
85
85
  it "should let you mix and match xpaths and nom accessors" do
86
- subject.language.value.should include('eng')
87
- subject.xpath('//mods:language', 'mods' => 'http://www.loc.gov/mods/v3').value.should include('eng')
86
+ expect(subject.language.value).to include('eng')
87
+ expect(subject.xpath('//mods:language', 'mods' => 'http://www.loc.gov/mods/v3').value).to include('eng')
88
88
  end
89
89
 
90
90
  it "should work with attributes" do
91
91
  eric =subject.personal_authors.first
92
- eric.valueURI.to_s.should == 'http://id.loc.gov/authorities/names/n92101908'
92
+ expect(eric.valueURI.to_s).to eq('http://id.loc.gov/authorities/names/n92101908')
93
93
  end
94
94
 
95
95
  it "should allow you to access a term from the node" do
96
- subject.personal_authors.namePart.terms.map { |term|term.options[:index_as] }.flatten.should include(:type_1)
96
+ expect(subject.personal_authors.namePart.terms.map { |term|term.options[:index_as] }.flatten).to include(:type_1)
97
97
  end
98
98
 
99
99
  it "should allow you to use multiple terms to address the same node" do
100
100
  t = subject.xpath('//mods:name', subject.terminology.namespaces).first.terms
101
- t.map { |x| x.name }.should include(:author, :personal_authors)
101
+ expect(t.map { |x| x.name }).to include(:author, :personal_authors)
102
102
  end
103
103
 
104
104
  it "should let you go from a terminology to nodes" do
105
- subject.terminology.flatten.length.should == 14
105
+ expect(subject.terminology.flatten.length).to eq(14)
106
106
 
107
- subject.terminology.flatten.select { |x| x.options[:index_as] }.should have(2).terms
108
- subject.terminology.flatten.select { |x| x.options[:index_as] }.map { |x| x.nodes }.flatten.should have(2).nodes
107
+ expect(subject.terminology.flatten.select { |x| x.options[:index_as] }.size).to eq(2)
108
+ expect(subject.terminology.flatten.select { |x| x.options[:index_as] }.map { |x| x.nodes }.flatten.size).to eq(2)
109
109
  end
110
110
 
111
111
  it "should let you go from a term to a terminology" do
112
- subject.personal_authors.terms.first.terminology.should == subject.terminology
112
+ expect(subject.personal_authors.terms.first.terminology).to eq(subject.terminology)
113
113
  end
114
114
 
115
115
  end
@@ -25,10 +25,10 @@ describe "Namespaces example" do
25
25
  }
26
26
 
27
27
  it "should get nodes" do
28
- subject.table.tr.td.map { |x| x.text }.should include("Apples", "Bananas")
28
+ expect(subject.table.tr.td.map { |x| x.text }).to include("Apples", "Bananas")
29
29
  end
30
30
 
31
31
  it "should get nodes from the other namespace" do
32
- subject.furniture_table._name.text.should include("African Coffee Table")
32
+ expect(subject.furniture_table._name.text).to include("African Coffee Table")
33
33
  end
34
34
  end
@@ -33,33 +33,33 @@ describe "Nutrition" do
33
33
  }
34
34
 
35
35
  it "should be able to access things via xpath, and then continue with terminology selectors" do
36
- subject.xpath('//food').first._name.text.should == "Avocado Dip"
36
+ expect(subject.xpath('//food').first._name.text).to eq("Avocado Dip")
37
37
  end
38
38
 
39
39
  it "should have total fat information" do
40
- subject.daily_values.total_fat.text.should == "65"
41
- subject.daily_values.total_fat.value.should include(65)
42
- subject.daily_values.total_fat.units.text.should =='g'
40
+ expect(subject.daily_values.total_fat.text).to eq("65")
41
+ expect(subject.daily_values.total_fat.value).to include(65)
42
+ expect(subject.daily_values.total_fat.units.text).to eq('g')
43
43
 
44
- subject.foods.total_fat.value.inject(:+).should == 117
44
+ expect(subject.foods.total_fat.value.inject(:+)).to eq(117)
45
45
  end
46
46
 
47
47
  it "should have food names" do
48
- subject.foods._name.text.should include("Avocado Dip")
48
+ expect(subject.foods._name.text).to include("Avocado Dip")
49
49
  end
50
50
 
51
51
  it "should have xpath selectors" do
52
- subject.foods(:name => 'Avocado Dip').total_fat.value.first.should == 11
53
- subject.foods('total-fat/text() = 11')._name.text.should == "Avocado Dip"
52
+ expect(subject.foods(:name => 'Avocado Dip').total_fat.value.first).to eq(11)
53
+ expect(subject.foods('total-fat/text() = 11')._name.text).to eq("Avocado Dip")
54
54
  end
55
55
 
56
56
  it "should have global terms" do
57
- subject.daily_values.total_fat.unit_value.should include('65g')
58
- subject.foods.first.at('serving').unit_value.should include('29g')
57
+ expect(subject.daily_values.total_fat.unit_value).to include('65g')
58
+ expect(subject.foods.first.at('serving').unit_value).to include('29g')
59
59
  end
60
60
 
61
61
  it "should accept if in proc-form" do
62
62
  subject.daily_values.total_fat.units_if == subject.daily_values.total_fat.units
63
- subject.daily_values.total_fat.units_if_false.should be_empty
63
+ expect(subject.daily_values.total_fat.units_if_false).to be_empty
64
64
  end
65
65
  end
@@ -37,8 +37,7 @@ describe "Template Registry example" do
37
37
  }
38
38
 
39
39
  it "should work" do
40
- pending if defined? JRUBY_VERSION
41
40
  subject.root.add_child(subject.template(:a, 'asdf'))
42
- subject.a.should have(2).items
41
+ expect(subject.a.size).to eq(2)
43
42
  end
44
43
  end
@@ -1,73 +1,69 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Nom::XML::Decorators::NodeSet do
4
- subject {
5
- doc = Nokogiri::XML '<root><a n="1"/><b /><c /></root>'
6
- doc.nom!
7
- doc
8
- }
4
+ subject {
5
+ doc = Nokogiri::XML '<root><a n="1"/><b /><c /></root>'
6
+ doc.nom!
7
+ doc
8
+ }
9
9
  describe "#values_for_term" do
10
10
 
11
-
12
11
  it "should do if" do
13
- t = mock(:options => { :if => lambda { |x| false }})
14
-
15
- t1 = mock(:options => { :if => lambda { |x| true }})
12
+ t = double(:options => { :if => lambda { |x| false }})
13
+ t1 = double(:options => { :if => lambda { |x| true }})
16
14
 
17
- subject.xpath('//*').values_for_term(t).should be_empty
18
- subject.xpath('//*').values_for_term(t1).should_not be_empty
15
+ expect(subject.xpath('//*').values_for_term(t)).to be_empty
16
+ expect(subject.xpath('//*').values_for_term(t1)).not_to be_empty
19
17
  end
20
18
 
21
19
  it "should do unless" do
22
- t = mock(:options => { :unless => lambda { |x| false }})
23
-
24
- t1 = mock(:options => { :unless => lambda { |x| true }})
20
+ t = double(:options => { :unless => lambda { |x| false }})
21
+ t1 = double(:options => { :unless => lambda { |x| true }})
25
22
 
26
- subject.xpath('//*').values_for_term(t).should_not be_empty
27
- subject.xpath('//*').values_for_term(t1).should be_empty
23
+ expect(subject.xpath('//*').values_for_term(t)).not_to be_empty
24
+ expect(subject.xpath('//*').values_for_term(t1)).to be_empty
28
25
  end
29
26
 
30
27
  it "should do a nil accessor" do
31
- t = mock(:options => { :accessor => nil})
32
-
33
- subject.xpath('//*').values_for_term(t).should == subject.xpath('//*')
28
+ t = double(:options => { :accessor => nil})
29
+ expect(subject.xpath('//*').values_for_term(t)).to eq(subject.xpath('//*'))
34
30
  end
35
31
 
36
32
  it "should do a Proc accessor" do
37
- t = mock(:options => { :accessor => lambda { |x| 1 }})
38
- subject.xpath('//a').values_for_term(t).should == [1]
33
+ t = double(:options => { :accessor => lambda { |x| 1 }})
34
+ expect(subject.xpath('//a').values_for_term(t)).to eq([1])
39
35
  end
40
36
 
41
37
  it "should do a symbol accessor" do
42
- t = mock(:options => { :accessor => :z})
43
- subject.xpath('//a').first.should_receive(:z).and_return(1)
44
- subject.xpath('//a').values_for_term(t).should == [1]
38
+ t = double(:options => { :accessor => :z })
39
+ allow(subject.xpath('//a').first).to receive(:z).and_return(1)
40
+ expect(subject.xpath('//a').values_for_term(t)).to eq([1])
45
41
  end
46
42
 
47
43
  it "should do single" do
48
- t = mock(:options => { :single => true})
49
- subject.xpath('//*').values_for_term(t).should == subject.xpath('//*').first
50
-
44
+ t = double(:options => { :single => true})
45
+ expect(subject.xpath('//*').values_for_term(t)).to eq(subject.xpath('//*').first)
51
46
  end
52
47
 
53
48
  it "should treat an attribute as a single" do
54
- t = mock(:options => { })
55
- subject.xpath('//@n').values_for_term(t).should be_a_kind_of Nokogiri::XML::Attr
56
-
49
+ t = double(:options => { })
50
+ expect(subject.xpath('//@n').values_for_term(t)).to be_a_kind_of Nokogiri::XML::Attr
57
51
  end
58
52
  end
59
53
 
60
54
  describe "method missing and respond to" do
61
55
  it "should respond to methods on nodes if all nodes in the nodeset respond to the method" do
62
- subject.xpath('//*').should respond_to :text
56
+ expect(subject.xpath('//*')).to respond_to :text
57
+ expect(subject.xpath('//*').respond_to?(:text, true)).to be_truthy
58
+ expect(subject.xpath('//*').respond_to?(:text, false)).to be_truthy
63
59
  end
64
60
 
65
61
  it "should respond to methods on nodes if all nodes in the nodeset respond to the method" do
66
- subject.xpath('//*').should_not respond_to :text_123
62
+ expect(subject.xpath('//*')).not_to respond_to :text_123
67
63
  end
68
64
 
69
65
  it "should work" do
70
- subject.xpath('//*').name.should include("a", "b", "c")
66
+ expect(subject.xpath('//*').name).to include("a", "b", "c")
71
67
  end
72
68
  end
73
- end
69
+ end
@@ -21,9 +21,9 @@ describe Nom::XML::NokogiriExtension do
21
21
  it "should decorate Nodes and Nodesets with our decorators" do
22
22
  doc.nom!
23
23
 
24
- doc.root.should be_a_kind_of(Nom::XML::Decorators::Terminology)
24
+ expect(doc.root).to be_a_kind_of(Nom::XML::Decorators::Terminology)
25
25
 
26
- doc.xpath('//*').should be_a_kind_of(Nom::XML::Decorators::NodeSet)
26
+ expect(doc.xpath('//*')).to be_a_kind_of(Nom::XML::Decorators::NodeSet)
27
27
  end
28
28
  end
29
29
  end
@@ -31,8 +31,8 @@ describe "NOM::XML::TemplateRegistry" do
31
31
 
32
32
  describe "template definitions" do
33
33
  it "should contain predefined templates" do
34
- subject.template_registry.node_types.should include(:person)
35
- subject.template_registry.node_types.should_not include(:zombie)
34
+ expect(subject.template_registry.node_types).to include(:person)
35
+ expect(subject.template_registry.node_types).not_to include(:zombie)
36
36
  end
37
37
 
38
38
  describe "ZOMG ZOMBIES!!11!!!1" do
@@ -44,36 +44,36 @@ describe "NOM::XML::TemplateRegistry" do
44
44
  end
45
45
  end
46
46
  it "should define new templates" do
47
- subject.template_registry.node_types.should include(:zombie)
47
+ expect(subject.template_registry.node_types).to include(:zombie)
48
48
  end
49
49
 
50
50
  it "should instantiate a detached node from a template" do
51
51
  node = subject.template_registry.instantiate(:zombie, 'Zeke')
52
52
  expectation = Nokogiri::XML('<monster wants="braaaaainz">Zeke</monster>').root
53
- node.should be_equivalent_to(expectation)
53
+ expect(node).to be_equivalent_to(expectation)
54
54
  end
55
55
 
56
56
  it "should raise an error when trying to instantiate an unknown node_type" do
57
- lambda { subject.template_registry.instantiate(:demigod, 'Hercules') }.should raise_error(NameError)
57
+ expect { subject.template_registry.instantiate(:demigod, 'Hercules') }.to raise_error(NameError)
58
58
  end
59
59
 
60
60
  it "should raise an exception if a missing method name doesn't match a node_type" do
61
- lambda { subject.template_registry.demigod('Hercules') }.should raise_error(NameError)
61
+ expect { subject.template_registry.demigod('Hercules') }.to raise_error(NameError)
62
62
  end
63
63
 
64
64
  it "should undefine existing templates" do
65
- subject.template_registry.node_types.should include(:zombie)
65
+ expect(subject.template_registry.node_types).to include(:zombie)
66
66
  subject.template_registry.undefine :zombie
67
- subject.template_registry.node_types.should_not include(:zombie)
67
+ expect(subject.template_registry.node_types).not_to include(:zombie)
68
68
  end
69
69
 
70
70
  it "should complain if the template name isn't a symbol" do
71
- lambda { subject.template_registry.define("die!") { |xml| subject.this_never_happened } }.should raise_error(TypeError)
71
+ expect { subject.template_registry.define("die!") { |xml| subject.this_never_happened } }.to raise_error(TypeError)
72
72
  end
73
73
 
74
74
  it "should report on whether a given template is defined" do
75
- subject.template_registry.has_node_type?(:zombie).should == true
76
- subject.template_registry.has_node_type?(:demigod).should == false
75
+ expect(subject.template_registry.has_node_type?(:zombie)).to eq(true)
76
+ expect(subject.template_registry.has_node_type?(:demigod)).to eq(false)
77
77
  end
78
78
 
79
79
  end
@@ -82,133 +82,133 @@ describe "NOM::XML::TemplateRegistry" do
82
82
  describe "template-based document manipulations" do
83
83
  it "should accept a Nokogiri::XML::Node as target" do
84
84
  subject.template_registry.after(subject.root.elements.first, :person, 'Bob', 'Builder')
85
- subject.root.elements.length.should == 2
85
+ expect(subject.root.elements.length).to eq(2)
86
86
  end
87
87
 
88
88
  it "should accept a Nokogiri::XML::NodeSet as target" do
89
89
  subject.template_registry.after(subject.root.elements, :person, 'Bob', 'Builder')
90
- subject.root.elements.length.should == 2
90
+ expect(subject.root.elements.length).to eq(2)
91
91
  end
92
92
 
93
93
  it "should instantiate a detached node from a template using the template name as a method" do
94
94
  node = subject.template_registry.person('Odin', 'All-Father')
95
95
  expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
96
- node.should be_equivalent_to(expectation)
96
+ expect(node).to be_equivalent_to(expectation)
97
97
  end
98
98
 
99
99
  it "should add_child" do
100
100
  return_value = subject.template_registry.add_child(subject.root, :person, 'Bob', 'Builder')
101
- return_value.should == subject.person[1]
102
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
101
+ expect(return_value).to eq(subject.person[1])
102
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
103
103
  end
104
104
 
105
105
  it "should add_next_sibling" do
106
106
  return_value = subject.template_registry.add_next_sibling(subject.person.first, :person, 'Bob', 'Builder')
107
- return_value.should == subject.person[1]
108
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
107
+ expect(return_value).to eq(subject.person[1])
108
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
109
109
  end
110
110
 
111
111
  it "should add_previous_sibling" do
112
112
  return_value = subject.template_registry.add_previous_sibling(subject.person.first, :person, 'Bob', 'Builder')
113
- return_value.should == subject.person.first
114
- subject.should be_equivalent_to(expectations[:before]).respecting_element_order
113
+ expect(return_value).to eq(subject.person.first)
114
+ expect(subject).to be_equivalent_to(expectations[:before]).respecting_element_order
115
115
  end
116
116
 
117
117
  it "should after" do
118
118
  return_value = subject.template_registry.after(subject.person.first, :person, 'Bob', 'Builder')
119
- return_value.should == subject.person.first
120
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
119
+ expect(return_value).to eq(subject.person.first)
120
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
121
121
  end
122
122
 
123
123
  it "should before" do
124
124
  return_value = subject.template_registry.before(subject.person.first, :person, 'Bob', 'Builder')
125
- return_value.should == subject.person[1]
126
- subject.should be_equivalent_to(expectations[:before]).respecting_element_order
125
+ expect(return_value).to eq(subject.person[1])
126
+ expect(subject).to be_equivalent_to(expectations[:before]).respecting_element_order
127
127
  end
128
128
 
129
129
  it "should replace" do
130
130
  target_node = subject.person.first
131
131
  return_value = subject.template_registry.replace(target_node, :person, 'Bob', 'Builder')
132
- return_value.should == subject.person.first
133
- subject.should be_equivalent_to(expectations[:instead]).respecting_element_order
132
+ expect(return_value).to eq(subject.person.first)
133
+ expect(subject).to be_equivalent_to(expectations[:instead]).respecting_element_order
134
134
  end
135
135
 
136
136
  it "should swap" do
137
137
  target_node = subject.person.first
138
138
  return_value = subject.template_registry.swap(target_node, :person, 'Bob', 'Builder')
139
- return_value.should == target_node
140
- subject.should be_equivalent_to(expectations[:instead]).respecting_element_order
139
+ expect(return_value).to eq(target_node)
140
+ expect(subject).to be_equivalent_to(expectations[:instead]).respecting_element_order
141
141
  end
142
142
 
143
143
  it "should yield the result if a block is given" do
144
144
  target_node = subject.person.first
145
145
  expectation = Nokogiri::XML('<person xmlns="urn:registry-test" title="Actor">Alice</person>').root
146
- subject.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
147
- old_node.should be_equivalent_to(expectation)
146
+ expect(subject.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
147
+ expect(old_node).to be_equivalent_to(expectation)
148
148
  old_node
149
- }.should be_equivalent_to(expectation)
149
+ }).to be_equivalent_to(expectation)
150
150
  end
151
151
  end
152
152
 
153
153
  describe "document-based document manipulations" do
154
154
  it "should accept a Nokogiri::XML::Node as target" do
155
155
  subject.root.elements.first.after_person('Bob', 'Builder')
156
- subject.root.elements.length.should == 2
156
+ expect(subject.root.elements.length).to eq(2)
157
157
  end
158
158
 
159
159
  it "should accept a Nokogiri::XML::NodeSet as target" do
160
160
  subject.person.after_person(:person, 'Bob', 'Builder')
161
- subject.root.elements.length.should == 2
161
+ expect(subject.root.elements.length).to eq(2)
162
162
  end
163
163
 
164
164
  it "should instantiate a detached node from a template" do
165
165
  node = subject.template_registry.instantiate(:person, 'Odin', 'All-Father')
166
166
  expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
167
- node.should be_equivalent_to(expectation)
167
+ expect(node).to be_equivalent_to(expectation)
168
168
  end
169
169
 
170
170
  it "should add_child_node" do
171
171
  return_value = subject.root.add_child_person('Bob', 'Builder')
172
- return_value.should == subject.person[1]
173
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
172
+ expect(return_value).to eq(subject.person[1])
173
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
174
174
  end
175
175
 
176
176
  it "should add_next_sibling_node" do
177
177
  return_value = subject.person[0].add_next_sibling_person('Bob', 'Builder')
178
- return_value.should == subject.person[1]
179
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
178
+ expect(return_value).to eq(subject.person[1])
179
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
180
180
  end
181
181
 
182
182
  it "should add_previous_sibling_node" do
183
183
  return_value = subject.person[0].add_previous_sibling_person('Bob', 'Builder')
184
- return_value.should == subject.person.first
185
- subject.should be_equivalent_to(expectations[:before]).respecting_element_order
184
+ expect(return_value).to eq(subject.person.first)
185
+ expect(subject).to be_equivalent_to(expectations[:before]).respecting_element_order
186
186
  end
187
187
 
188
188
  it "should after_node" do
189
189
  return_value = subject.person[0].after_person('Bob', 'Builder')
190
- return_value.should == subject.person.first
191
- subject.should be_equivalent_to(expectations[:after]).respecting_element_order
190
+ expect(return_value).to eq(subject.person.first)
191
+ expect(subject).to be_equivalent_to(expectations[:after]).respecting_element_order
192
192
  end
193
193
 
194
194
  it "should before_node" do
195
195
  return_value = subject.person[0].before_person('Bob', 'Builder')
196
- return_value.should == subject.person[1]
197
- subject.should be_equivalent_to(expectations[:before]).respecting_element_order
196
+ expect(return_value).to eq(subject.person[1])
197
+ expect(subject).to be_equivalent_to(expectations[:before]).respecting_element_order
198
198
  end
199
199
 
200
200
  it "should replace_node" do
201
201
  target_node = subject.person.first
202
202
  return_value = target_node.replace_person('Bob', 'Builder')
203
- return_value.should == subject.person.first
204
- subject.should be_equivalent_to(expectations[:instead]).respecting_element_order
203
+ expect(return_value).to eq(subject.person.first)
204
+ expect(subject).to be_equivalent_to(expectations[:instead]).respecting_element_order
205
205
  end
206
206
 
207
207
  it "should swap_node" do
208
208
  target_node = subject.person.first
209
209
  return_value = target_node.swap_person('Bob', 'Builder')
210
- return_value.should == target_node
211
- subject.should be_equivalent_to(expectations[:instead]).respecting_element_order
210
+ expect(return_value).to eq(target_node)
211
+ expect(subject).to be_equivalent_to(expectations[:instead]).respecting_element_order
212
212
  end
213
213
  end
214
214
 
@@ -29,7 +29,6 @@ describe "Nutrition" do
29
29
  end
30
30
 
31
31
  xml.nom!
32
-
33
32
  xml
34
33
  }
35
34
 
@@ -37,15 +36,16 @@ describe "Nutrition" do
37
36
 
38
37
  it "should warn you if you try to override already existing methods" do
39
38
  pending if defined? JRUBY_VERSION
40
- mock_term = {:text => mock(:options => {})}
41
- document.a.first.stub(:term_accessors).and_return mock_term
39
+ mock_term = {:text => double(:options => {})}
40
+ allow(document.a.first).to receive(:term_accessors).and_return mock_term
42
41
  expect { document.a.first.add_terminology_method_overrides! }.to raise_error /Trying to redefine/
43
42
  end
44
43
 
45
44
  it "should let you override the warning" do
46
- mock_term = {:text => mock(:options => { :override => true } )}
47
- document.a.first.stub(:term_accessors).and_return mock_term
48
- expect { document.a.first.add_terminology_method_overrides! }.to_not raise_error /Trying to redefine/
45
+ pending if defined? JRUBY_VERSION
46
+ mock_term = {:text => double(:options => { :override => true } )}
47
+ allow(document.a.first).to receive(:term_accessors).and_return mock_term
48
+ expect { document.a.first.add_terminology_method_overrides! }.to_not raise_error
49
49
  end
50
50
  end
51
51
 
@@ -55,20 +55,19 @@ describe "Nutrition" do
55
55
  subject { document.root }
56
56
 
57
57
  it "should not have any associated terminology terms" do
58
- subject.terms.should be_empty
58
+ expect(subject.terms).to be_empty
59
59
  end
60
-
61
60
  end
62
61
 
63
62
  context "node with a single term" do
64
63
  subject { document.xpath('//a').first }
65
64
 
66
65
  it "should have a single term" do
67
- subject.terms.should have(1).item
66
+ expect(subject.terms.size).to eq(1)
68
67
  end
69
68
 
70
69
  it "should find the right term" do
71
- subject.terms.map { |x| x.name }.should include(:a)
70
+ expect(subject.terms.map { |x| x.name }).to include(:a)
72
71
  end
73
72
  end
74
73
 
@@ -76,11 +75,11 @@ describe "Nutrition" do
76
75
  subject { document.xpath('//b').first }
77
76
 
78
77
  it "should have multiple terms" do
79
- subject.terms.should have(2).items
78
+ expect(subject.terms.size).to eq(2)
80
79
  end
81
80
 
82
81
  it "should find the right terms" do
83
- subject.terms.map { |x| x.name }.should include(:b, :b_ref)
82
+ expect(subject.terms.map { |x| x.name }).to include(:b, :b_ref)
84
83
  end
85
84
  end
86
85
  end
@@ -91,7 +90,7 @@ describe "Nutrition" do
91
90
  subject { document.xpath('//c').first }
92
91
 
93
92
  it "should have a child accessor" do
94
- subject.send(:term_accessors).keys.should include(:nested)
93
+ expect(subject.send(:term_accessors).keys).to include(:nested)
95
94
  end
96
95
  end
97
96
 
@@ -99,7 +98,7 @@ describe "Nutrition" do
99
98
  subject { document }
100
99
 
101
100
  it "should have all the root terms" do
102
- subject.send(:term_accessors).keys.should include(:a, :b, :c)
101
+ expect(subject.send(:term_accessors).keys).to include(:a, :b, :c)
103
102
  end
104
103
  end
105
104
 
@@ -107,11 +106,10 @@ describe "Nutrition" do
107
106
  subject { document.root }
108
107
 
109
108
  it "should have all the root terms" do
110
- subject.send(:term_accessors).keys.should include(:a, :b, :c)
109
+ expect(subject.send(:term_accessors).keys).to include(:a, :b, :c)
111
110
  end
112
111
  end
113
112
  end
114
113
 
115
-
116
114
  end
117
115
 
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe Nom::XML::Terminology do
4
4
  describe "#namespaces" do
5
5
  it "should pull the namespaces out of the terminology options" do
6
- Nom::XML::Terminology.new(nil, :namespaces => { 'asd' => '123'}).namespaces.should == { 'asd' => '123'}
6
+ expect(Nom::XML::Terminology.new(nil, :namespaces => { 'asd' => '123'}).namespaces).to eq({ 'asd' => '123'})
7
7
  end
8
8
 
9
9
  it "should return an empty hash if no namespace is provided" do
10
- Nom::XML::Terminology.new.namespaces.should == {}
10
+ expect(Nom::XML::Terminology.new.namespaces).to eq({})
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ describe Nom::XML::Terminology do
15
15
  it "should be an identity function" do
16
16
  a = Nom::XML::Terminology.new
17
17
 
18
- a.terminology.should == a
18
+ expect(a.terminology).to eq(a)
19
19
  end
20
20
  end
21
21
  end
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
3
3
  SimpleCov.start
4
4
  end
5
5
 
6
- require 'rspec/autorun'
6
+ require 'rspec'
7
7
  require 'nom'
8
8
  require 'equivalent-xml/rspec_matchers'
9
9
 
data/spec/test_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe Nom::XML do
15
15
 
16
16
  doc.nom!
17
17
 
18
- doc.b.should == "1"
18
+ expect(doc.b).to eq("1")
19
19
  end
20
20
  it "should do stuff with terminologies" do
21
21
  doc = Nokogiri::XML <<-eos
@@ -59,14 +59,14 @@ describe Nom::XML do
59
59
 
60
60
  doc.nom!
61
61
 
62
- doc.root.element_a.text.should == 'a value'
63
- doc.root.element_b.element_c.text.should == 'c value'
64
- doc.root.element_d.element_e.element_f.text.strip.should == 'f value'
65
- doc.root.element_d.element_e.foo.collect(&:text).should == ['bar']
66
- doc.root.element_d.element_e.foo_text.should == ['bar']
67
- doc.root.element_g.first.element_h.should == ['h value 1','h value 2']
68
- doc.root.element_g.element_h.should == ['h value 1','h value 2','h value 3']
69
- doc.root.element_g.whatever.should == ['element_h:h value 1','element_h:h value 2','element_h:h value 3']
62
+ expect(doc.root.element_a.text).to eq('a value')
63
+ expect(doc.root.element_b.element_c.text).to eq('c value')
64
+ expect(doc.root.element_d.element_e.element_f.text.strip).to eq('f value')
65
+ expect(doc.root.element_d.element_e.foo.collect(&:text)).to eq(['bar'])
66
+ expect(doc.root.element_d.element_e.foo_text).to eq(['bar'])
67
+ expect(doc.root.element_g.first.element_h).to eq(['h value 1','h value 2'])
68
+ expect(doc.root.element_g.element_h).to eq(['h value 1','h value 2','h value 3'])
69
+ expect(doc.root.element_g.whatever).to eq(['element_h:h value 1','element_h:h value 2','element_h:h value 3'])
70
70
  end
71
71
  end
72
72
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nom-xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.5.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Beer
@@ -10,122 +9,108 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2015-02-06 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
- version: '0'
20
+ version: 3.2.18
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
- version: '0'
27
+ version: 3.2.18
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: i18n
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ">="
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - ">="
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: nokogiri
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - ">="
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
- name: rspec
57
+ name: equivalent-xml
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - "~>"
69
61
  - !ruby/object:Gem::Version
70
- version: '0'
62
+ version: 0.5.1
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - "~>"
77
68
  - !ruby/object:Gem::Version
78
- version: '0'
69
+ version: 0.5.1
79
70
  - !ruby/object:Gem::Dependency
80
- name: rake
71
+ name: rspec
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - "~>"
85
75
  - !ruby/object:Gem::Version
86
- version: '0'
76
+ version: '3.1'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - "~>"
93
82
  - !ruby/object:Gem::Version
94
- version: '0'
83
+ version: '3.1'
95
84
  - !ruby/object:Gem::Dependency
96
- name: yard
85
+ name: rake
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - ">="
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - ">="
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
- name: equivalent-xml
99
+ name: yard
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - ">="
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - ">="
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
- description: ! ' NOM allows you to define a “terminology” to ease translation between
128
- XML and ruby objects '
112
+ description: " NOM allows you to define a “terminology” to ease translation between
113
+ XML and ruby objects "
129
114
  email: cabeer@stanford.edu mbklein@gmail.com
130
115
  executables: []
131
116
  extensions: []
@@ -133,11 +118,15 @@ extra_rdoc_files:
133
118
  - LICENSE
134
119
  - README.md
135
120
  files:
136
- - .travis.yml
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
137
124
  - Gemfile
138
125
  - LICENSE
139
126
  - README.md
140
127
  - Rakefile
128
+ - gemfiles/rails3.gemfile
129
+ - gemfiles/rails4.gemfile
141
130
  - lib/nom.rb
142
131
  - lib/nom/xml.rb
143
132
  - lib/nom/xml/decorators.rb
@@ -166,33 +155,26 @@ files:
166
155
  - spec/test_spec.rb
167
156
  homepage: http://github.com/cbeer/nom-xml
168
157
  licenses: []
158
+ metadata: {}
169
159
  post_install_message:
170
160
  rdoc_options: []
171
161
  require_paths:
172
162
  - lib
173
163
  required_ruby_version: !ruby/object:Gem::Requirement
174
- none: false
175
164
  requirements:
176
- - - ! '>='
165
+ - - ">="
177
166
  - !ruby/object:Gem::Version
178
167
  version: '0'
179
- segments:
180
- - 0
181
- hash: 623172737244635261
182
168
  required_rubygems_version: !ruby/object:Gem::Requirement
183
- none: false
184
169
  requirements:
185
- - - ! '>='
170
+ - - ">="
186
171
  - !ruby/object:Gem::Version
187
172
  version: '0'
188
- segments:
189
- - 0
190
- hash: 623172737244635261
191
173
  requirements: []
192
174
  rubyforge_project:
193
- rubygems_version: 1.8.23
175
+ rubygems_version: 2.4.5
194
176
  signing_key:
195
- specification_version: 3
177
+ specification_version: 4
196
178
  summary: A library to help you tame sprawling XML schemas.
197
179
  test_files:
198
180
  - spec/examples/mods_example_spec.rb