om 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/om.gemspec CHANGED
@@ -15,15 +15,18 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = '>= 1.9.3'
17
17
 
18
+ s.add_dependency 'activemodel', '>= 5.1', '< 7'
18
19
  s.add_dependency 'activesupport'
19
- s.add_dependency 'activemodel'
20
- s.add_dependency 'solrizer', '~> 3.3'
21
20
  s.add_dependency('nokogiri', ">= 1.4.2")
22
- s.add_development_dependency "rspec", "~> 2.0"
23
- s.add_development_dependency "rake"
24
- s.add_development_dependency "yard"
21
+ s.add_dependency 'solrizer', '~> 3.3'
25
22
  s.add_development_dependency "awesome_print"
23
+ s.add_development_dependency 'coveralls'
26
24
  s.add_development_dependency "equivalent-xml", ">= 0.2.4"
25
+ s.add_development_dependency "pry-byebug"
26
+ s.add_development_dependency "rake"
27
+ s.add_development_dependency "rspec", "~> 3.8"
28
+ s.add_development_dependency "rspec_junit_formatter"
29
+ s.add_development_dependency "yard"
27
30
 
28
31
  s.files = `git ls-files`.split("\n")
29
32
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,106 +1,127 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "calling set_terminology more than once" do
4
+ context 'with a Class exposing the #foo accessor' do
5
+ before(:all) do
6
+ class ReentrantTerminology
7
+ include OM::XML::Document
4
8
 
5
- before(:all) do
6
- class ReentrantTerminology
7
- include OM::XML::Document
8
-
9
- set_terminology do |t|
10
- t.root :path => 'root', :xmlns => "asdf"
11
- t.foo
9
+ set_terminology do |t|
10
+ t.root :path => 'root', :xmlns => "asdf"
11
+ t.foo
12
+ end
12
13
  end
13
14
  end
14
- end
15
15
 
16
- describe "before" do
17
-
18
- subject do
19
- xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
20
- ReentrantTerminology.from_xml(xml)
16
+ after(:all) do
17
+ Object.send(:remove_const, :ReentrantTerminology)
21
18
  end
22
19
 
23
- it "can get foo" do
24
- expect(subject.foo).to eq ['fooval']
25
- end
20
+ describe "before" do
21
+ subject do
22
+ xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
23
+ ReentrantTerminology.from_xml(xml)
24
+ end
26
25
 
27
- it "cannot get bar" do
28
- expect { subject.bar }.to raise_error NoMethodError
29
- end
26
+ it "can get foo" do
27
+ expect(subject.foo).to eq ['fooval']
28
+ end
30
29
 
30
+ it "cannot get bar" do
31
+ expect { subject.bar }.to raise_error NoMethodError
32
+ end
33
+ end
31
34
  end
32
35
 
33
36
  describe "after" do
34
-
35
- before(:all) do
36
- class ReentrantTerminology
37
- set_terminology do |t|
38
- t.root :path => 'root', :xmlns => "asdf"
39
- t.bar
37
+ context 'with a Class exposing the #bar accessor' do
38
+ before(:all) do
39
+ class ReentrantTerminology
40
+ include OM::XML::Document
41
+ set_terminology do |t|
42
+ t.root :path => 'root', :xmlns => "asdf"
43
+ t.bar
44
+ end
40
45
  end
41
46
  end
42
- end
43
47
 
44
- subject do
45
- xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
46
- ReentrantTerminology.from_xml(xml)
47
- end
48
+ after(:all) do
49
+ Object.send(:remove_const, :ReentrantTerminology)
50
+ end
48
51
 
49
- it "cannot get foo" do
50
- expect { subject.foo }.to raise_error NoMethodError
51
- end
52
+ subject do
53
+ xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
54
+ ReentrantTerminology.from_xml(xml)
55
+ end
52
56
 
53
- it "can now get bar" do
54
- expect(subject.bar).to eq ['barval']
55
- end
57
+ it "cannot get foo" do
58
+ expect { subject.foo }.to raise_error NoMethodError
59
+ end
56
60
 
61
+ it "can now get bar" do
62
+ expect(subject.bar).to eq ['barval']
63
+ end
64
+ end
57
65
  end
58
66
 
59
67
  describe "re-entrant modification" do
60
-
61
-
62
- before(:all) do
63
- class ReentrantTerminology
64
- set_terminology do |t|
65
- t.root :path => 'root', :xmlns => "asdf"
66
- t.foo
68
+ let(:xml) { '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>' }
69
+
70
+ context 'with a Class exposing the #foo accessor' do
71
+ subject(:terminology) { FooReentrantTerminology.from_xml(xml) }
72
+
73
+ before(:all) do
74
+ class FooReentrantTerminology
75
+ include OM::XML::Document
76
+ set_terminology do |t|
77
+ t.root :path => 'root', :xmlns => "asdf"
78
+ t.foo
79
+ end
67
80
  end
68
81
  end
69
82
 
70
- class ReentrantTerminology
71
- extend_terminology do |t|
72
- t.bar
73
- end
83
+ after(:all) do
84
+ Object.send(:remove_const, :FooReentrantTerminology)
74
85
  end
75
- end
76
-
77
- subject do
78
- xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
79
- ReentrantTerminology.from_xml(xml)
80
- end
81
86
 
82
- it "can get foo" do
83
- expect(subject.foo).to eq ['fooval']
84
- end
87
+ it "can get foo" do
88
+ expect(terminology.foo).to eq ['fooval']
89
+ end
85
90
 
86
- it "can get bar" do
87
- expect(subject.bar).to eq ['barval']
88
- end
91
+ context 'with a Class exposing the #bar accessor' do
92
+ subject(:terminology) { BarReentrantTerminology.from_xml(xml) }
89
93
 
90
- end
94
+ before do
95
+ class BarReentrantTerminology < FooReentrantTerminology
96
+ include OM::XML::Document
97
+ extend_terminology do |t|
98
+ t.bar
99
+ end
100
+ end
101
+ end
91
102
 
92
- describe "subclass modification" do
103
+ after(:all) do
104
+ Object.send(:remove_const, :BarReentrantTerminology)
105
+ end
93
106
 
107
+ it "can get bar" do
108
+ expect(terminology.bar).to eq ['barval']
109
+ end
110
+ end
111
+ end
112
+ end
94
113
 
114
+ context 'with Classes exposing the #foo and #bar accessors' do
95
115
  before(:all) do
96
116
  class ReentrantTerminology
117
+ include OM::XML::Document
97
118
  set_terminology do |t|
98
119
  t.root :path => 'root', :xmlns => "asdf"
99
120
  t.foo
100
121
  end
101
122
  end
102
123
 
103
- class LocalReentrantTerminology
124
+ class LocalReentrantTerminology
104
125
  include OM::XML::Document
105
126
  use_terminology(ReentrantTerminology)
106
127
  extend_terminology do |t|
@@ -109,26 +130,32 @@ describe "calling set_terminology more than once" do
109
130
  end
110
131
  end
111
132
 
112
- subject do
113
- xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
114
- LocalReentrantTerminology.from_xml(xml)
133
+ after(:all) do
134
+ Object.send(:remove_const, :ReentrantTerminology)
135
+ Object.send(:remove_const, :LocalReentrantTerminology)
115
136
  end
116
137
 
117
- it "shouldn't bleed up the inheritence stack" do
118
- xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
119
- t = ReentrantTerminology.from_xml(xml)
138
+ describe "subclass modification" do
120
139
 
121
- expect { t.bar }.to raise_error NoMethodError
122
- end
140
+ subject do
141
+ xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
142
+ LocalReentrantTerminology.from_xml(xml)
143
+ end
123
144
 
124
- it "can get foo" do
125
- expect(subject.foo).to eq ['fooval']
126
- end
145
+ it "shouldn't bleed up the inheritence stack" do
146
+ xml = '<root xmlns="asdf"><foo>fooval</foo><bar>barval</bar></root>'
147
+ t = ReentrantTerminology.from_xml(xml)
127
148
 
128
- it "can get bar" do
129
- expect(subject.bar).to eq ['barval']
130
- end
149
+ expect { t.bar }.to raise_error NoMethodError
150
+ end
131
151
 
132
- end
152
+ it "can get foo" do
153
+ expect(subject.foo).to eq ['fooval']
154
+ end
133
155
 
156
+ it "can get bar" do
157
+ expect(subject.bar).to eq ['barval']
158
+ end
159
+ end
160
+ end
134
161
  end
@@ -1,20 +1,37 @@
1
- if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
2
- require 'simplecov'
3
- require 'simplecov-rcov'
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
6
- SimpleCov.start
7
- end
8
-
1
+ require 'equivalent-xml/rspec_matchers'
2
+ require 'logger'
9
3
  require 'om'
4
+ require 'pry-byebug'
10
5
  require 'rspec'
11
- require 'equivalent-xml/rspec_matchers'
12
6
  require 'samples'
13
- require 'logger'
7
+
8
+ def coverage_needed?
9
+ ENV['COVERAGE'] || ENV['TRAVIS']
10
+ end
11
+
12
+ if coverage_needed?
13
+ require 'simplecov'
14
+ require 'coveralls'
15
+ SimpleCov.root(File.expand_path('../..', __FILE__))
16
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
17
+ [
18
+ SimpleCov::Formatter::HTMLFormatter,
19
+ Coveralls::SimpleCov::Formatter
20
+ ]
21
+ )
22
+ SimpleCov.start('rails') do
23
+ add_filter '/devel'
24
+ add_filter '/lib/om/version.rb'
25
+ add_filter '/lib/tasks'
26
+ add_filter '/spec'
27
+ end
28
+ end
14
29
 
15
30
  OM.logger = Logger.new(STDERR)
16
31
 
17
32
  RSpec.configure do |config|
33
+ config.full_backtrace = true if ENV['TRAVIS']
34
+ #config.fixture_path = File.expand_path("../fixtures", __FILE__)
18
35
  end
19
36
 
20
37
  def fixture(file)
@@ -1,28 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "OM::XML::TermValueOperators" do
4
-
4
+
5
5
  describe "find_by_terms" do
6
6
  before(:each) do
7
7
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
8
8
  end
9
-
9
+
10
10
  it "should do" do
11
11
  expect(@article.find_by_terms({:journal=>0}).length).to eq 1
12
12
  end
13
13
  end
14
-
14
+
15
15
  describe "update_values" do
16
16
  before(:each) do
17
17
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
18
18
  end
19
-
19
+
20
20
  it "should respond with a hash of updated values and their indexes" do
21
- test_args = {[{"person"=>"0"},"description"]=>["mork", "york"]}
21
+ test_args = {[{"person"=>"0"},"description"]=>["mork", "york"]}
22
22
  result = @article.update_values(test_args)
23
23
  expect(result).to eq({"person_0_description"=>["mork", "york"]})
24
24
  end
25
-
25
+
26
26
  it "should update the xml in the specified datastream and know that changes have been made" do
27
27
  expect(@article.term_values({:person=>0}, :first_name)).to eq ["GIVEN NAMES"]
28
28
  test_args = {[{:person=>0}, :first_name]=>"Replacement FirstName"}
@@ -30,39 +30,39 @@ describe "OM::XML::TermValueOperators" do
30
30
  expect(@article.term_values({:person=>0}, :first_name)).to eq ["Replacement FirstName"]
31
31
  expect(@article).to be_changed
32
32
  end
33
-
33
+
34
34
  it "should update the xml according to the find_by_terms_and_values in the given hash" do
35
35
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
36
36
  result = @article.update_values(terms_attributes)
37
37
  expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
38
-
38
+
39
39
  # Trying again with a more complex update hash
40
40
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"], [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
41
41
  result = @article.update_values(terms_attributes)
42
42
  expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"], "person_1_last_name"=>["Andronicus"],"person_1_first_name"=>["Titus"], "person_1_role"=>["otherrole1","otherrole2"]})
43
43
  expect(@article).to be_changed
44
44
  end
45
-
45
+
46
46
  it "should work when you re-run the command" do
47
47
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
48
48
  result = @article.update_values(terms_attributes)
49
49
 
50
50
  expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
51
51
  expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
52
-
52
+
53
53
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
54
54
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
55
55
  result = @article.update_values(terms_attributes)
56
56
  expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
57
57
  expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
58
58
  result = @article.update_values(terms_attributes)
59
-
59
+
60
60
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
61
61
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
62
62
  result = @article.update_values(terms_attributes)
63
63
  expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
64
64
  expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
65
-
65
+
66
66
  # Trying again with a more complex update hash
67
67
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"], [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
68
68
  result = @article.update_values(terms_attributes)
@@ -1,10 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "OM::XML::TemplateRegistry" do
4
+ let(:xml) { '<people xmlns="urn:registry-test"><person title="Actor">Alice</person></people>' }
5
+ let(:test_document) { RegistryTest.from_xml(xml) }
6
+ let(:expect_before) do
7
+ %{<people xmlns="urn:registry-test"><person title="Builder">Bob</person><person title="Actor">Alice</person></people>}
8
+ end
9
+ let(:expect_after) do
10
+ %{<people xmlns="urn:registry-test"><person title="Actor">Alice</person><person title="Builder">Bob</person></people>}
11
+ end
12
+ let(:expect_instead) do
13
+ %{<people xmlns="urn:registry-test"><person title="Builder">Bob</person></people>}
14
+ end
4
15
 
5
- before(:all) do
16
+ before do
6
17
  class RegistryTest
7
-
8
18
  include OM::XML::Document
9
19
 
10
20
  set_terminology do |t|
@@ -19,23 +29,13 @@ describe "OM::XML::TemplateRegistry" do
19
29
  xml.text(name)
20
30
  end
21
31
  end
22
-
23
32
  end
24
33
  end
25
-
26
- after(:all) do
34
+
35
+ after do
27
36
  Object.send(:remove_const, :RegistryTest)
28
37
  end
29
38
 
30
- before(:each) do
31
- @test_document = RegistryTest.from_xml('<people xmlns="urn:registry-test"><person title="Actor">Alice</person></people>')
32
- @expectations = {
33
- :before => %{<people xmlns="urn:registry-test"><person title="Builder">Bob</person><person title="Actor">Alice</person></people>},
34
- :after => %{<people xmlns="urn:registry-test"><person title="Actor">Alice</person><person title="Builder">Bob</person></people>},
35
- :instead => %{<people xmlns="urn:registry-test"><person title="Builder">Bob</person></people>}
36
- }
37
- end
38
-
39
39
  describe "template definitions" do
40
40
  it "should contain predefined templates" do
41
41
  expect(RegistryTest.template_registry.node_types).to include(:person)
@@ -52,176 +52,186 @@ describe "OM::XML::TemplateRegistry" do
52
52
  expect(RegistryTest.template_registry.node_types).to include(:zombie)
53
53
  end
54
54
 
55
- it "should instantiate a detached node from a template" do
56
- node = RegistryTest.template_registry.instantiate(:zombie, 'Zeke')
57
- expectation = Nokogiri::XML('<monster wants="braaaaainz">Zeke</monster>').root
58
- expect(node).to be_equivalent_to(expectation)
55
+ context 'when a zombie template has been defined' do
56
+ before do
57
+ RegistryTest.define_template :zombie do |xml,name|
58
+ xml.monster(:wants => 'braaaaainz') do
59
+ xml.text(name)
60
+ end
61
+ end
62
+ end
63
+
64
+ it "should instantiate a detached node from a template" do
65
+ node = RegistryTest.template_registry.instantiate(:zombie, 'Zeke')
66
+ expectation = Nokogiri::XML('<monster wants="braaaaainz">Zeke</monster>').root
67
+ expect(node).to be_equivalent_to(expectation)
68
+ end
69
+
70
+ it "should undefine existing templates" do
71
+ expect(RegistryTest.template_registry.node_types).to include(:zombie)
72
+ RegistryTest.template_registry.undefine :zombie
73
+ expect(RegistryTest.template_registry.node_types).not_to include(:zombie)
74
+ end
59
75
  end
60
-
76
+
61
77
  it "should raise an error when trying to instantiate an unknown node_type" do
62
78
  expect { RegistryTest.template_registry.instantiate(:demigod, 'Hercules') }.to raise_error(NameError)
63
79
  end
64
-
80
+
65
81
  it "should raise an exception if a missing method name doesn't match a node_type" do
66
82
  expect { RegistryTest.template_registry.demigod('Hercules') }.to raise_error(NameError)
67
83
  end
68
-
69
- it "should undefine existing templates" do
70
- expect(RegistryTest.template_registry.node_types).to include(:zombie)
71
- RegistryTest.template_registry.undefine :zombie
72
- expect(RegistryTest.template_registry.node_types).not_to include(:zombie)
73
- end
74
-
84
+
75
85
  it "should complain if the template name isn't a symbol" do
76
86
  expect(lambda { RegistryTest.template_registry.define("die!") { |xml| xml.this_never_happened } }).to raise_error(TypeError)
77
87
  end
78
-
88
+
79
89
  it "should report on whether a given template is defined" do
80
90
  expect(RegistryTest.template_registry.has_node_type?(:person)).to eq true
81
91
  expect(RegistryTest.template_registry.has_node_type?(:zombie)).to eq false
82
92
  end
83
-
93
+
84
94
  it "should include defined node_types as method names for introspection" do
85
95
  expect(RegistryTest.template_registry.methods).to include('person')
86
96
  end
87
97
  end
88
-
98
+
89
99
  describe "template-based document manipulations" do
90
100
  it "should accept a Nokogiri::XML::Node as target" do
91
- @test_document.template_registry.after(@test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
92
- expect(@test_document.ng_xml.root.elements.length).to eq 2
101
+ test_document.template_registry.after(test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
102
+ expect(test_document.ng_xml.root.elements.length).to eq 2
93
103
  end
94
104
 
95
105
  it "should accept a Nokogiri::XML::NodeSet as target" do
96
- @test_document.template_registry.after(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
97
- expect(@test_document.ng_xml.root.elements.length).to eq 2
106
+ test_document.template_registry.after(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
107
+ expect(test_document.ng_xml.root.elements.length).to eq 2
98
108
  end
99
-
109
+
100
110
  it "should instantiate a detached node from a template using the template name as a method" do
101
111
  node = RegistryTest.template_registry.person('Odin', 'All-Father')
102
112
  expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
103
113
  expect(node).to be_equivalent_to(expectation)
104
114
  end
105
-
115
+
106
116
  it "should add_child" do
107
- return_value = @test_document.template_registry.add_child(@test_document.ng_xml.root, :person, 'Bob', 'Builder')
108
- expect(return_value).to eq @test_document.find_by_terms(:person => 1).first
109
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
117
+ return_value = test_document.template_registry.add_child(test_document.ng_xml.root, :person, 'Bob', 'Builder')
118
+ expect(return_value).to eq test_document.find_by_terms(:person => 1).first
119
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
110
120
  end
111
-
121
+
112
122
  it "should add_next_sibling" do
113
- return_value = @test_document.template_registry.add_next_sibling(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
114
- expect(return_value).to eq @test_document.find_by_terms(:person => 1).first
115
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
123
+ return_value = test_document.template_registry.add_next_sibling(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
124
+ expect(return_value).to eq test_document.find_by_terms(:person => 1).first
125
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
116
126
  end
117
127
 
118
128
  it "should add_previous_sibling" do
119
- return_value = @test_document.template_registry.add_previous_sibling(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
120
- expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
121
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
129
+ return_value = test_document.template_registry.add_previous_sibling(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
130
+ expect(return_value).to eq(test_document.find_by_terms(:person => 0).first)
131
+ expect(test_document.ng_xml).to be_equivalent_to(expect_before).respecting_element_order
122
132
  end
123
133
 
124
134
  it "should after" do
125
- return_value = @test_document.template_registry.after(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
126
- expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
127
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
135
+ return_value = test_document.template_registry.after(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
136
+ expect(return_value).to eq(test_document.find_by_terms(:person => 0).first)
137
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
128
138
  end
129
139
 
130
140
  it "should before" do
131
- return_value = @test_document.template_registry.before(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
132
- expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
133
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
141
+ return_value = test_document.template_registry.before(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
142
+ expect(return_value).to eq(test_document.find_by_terms(:person => 1).first)
143
+ expect(test_document.ng_xml).to be_equivalent_to(expect_before).respecting_element_order
134
144
  end
135
145
 
136
146
  it "should replace" do
137
- target_node = @test_document.find_by_terms(:person => 0).first
138
- return_value = @test_document.template_registry.replace(target_node, :person, 'Bob', 'Builder')
139
- expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
140
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
147
+ target_node = test_document.find_by_terms(:person => 0).first
148
+ return_value = test_document.template_registry.replace(target_node, :person, 'Bob', 'Builder')
149
+ expect(return_value).to eq(test_document.find_by_terms(:person => 0).first)
150
+ expect(test_document.ng_xml).to be_equivalent_to(expect_instead).respecting_element_order
141
151
  end
142
152
 
143
153
  it "should swap" do
144
- target_node = @test_document.find_by_terms(:person => 0).first
145
- return_value = @test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder')
154
+ target_node = test_document.find_by_terms(:person => 0).first
155
+ return_value = test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder')
146
156
  expect(return_value).to eq target_node
147
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
157
+ expect(test_document.ng_xml).to be_equivalent_to(expect_instead).respecting_element_order
148
158
  end
149
-
159
+
150
160
  it "should yield the result if a block is given" do
151
- target_node = @test_document.find_by_terms(:person => 0).first
161
+ target_node = test_document.find_by_terms(:person => 0).first
152
162
  expectation = Nokogiri::XML('<person xmlns="urn:registry-test" title="Actor">Alice</person>').root
153
- expect(@test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
163
+ expect(test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
154
164
  expect(old_node).to be_equivalent_to(expectation)
155
165
  old_node
156
166
  }).to be_equivalent_to(expectation)
157
167
  end
158
168
  end
159
-
169
+
160
170
  describe "document-based document manipulations" do
161
171
  it "should accept a Nokogiri::XML::Node as target" do
162
- @test_document.after_node(@test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
163
- expect(@test_document.ng_xml.root.elements.length).to eq 2
172
+ test_document.after_node(test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
173
+ expect(test_document.ng_xml.root.elements.length).to eq 2
164
174
  end
165
175
 
166
176
  it "should accept a Nokogiri::XML::NodeSet as target" do
167
- @test_document.after_node(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
168
- expect(@test_document.ng_xml.root.elements.length).to eq 2
177
+ test_document.after_node(test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
178
+ expect(test_document.ng_xml.root.elements.length).to eq 2
169
179
  end
170
-
180
+
171
181
  it "should accept a term-pointer array as target" do
172
- @test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
173
- expect(@test_document.ng_xml.root.elements.length).to eq 2
182
+ test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
183
+ expect(test_document.ng_xml.root.elements.length).to eq 2
174
184
  end
175
-
185
+
176
186
  it "should instantiate a detached node from a template" do
177
- node = @test_document.template(:person, 'Odin', 'All-Father')
187
+ node = test_document.template(:person, 'Odin', 'All-Father')
178
188
  expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
179
189
  expect(node).to be_equivalent_to(expectation)
180
190
  end
181
191
 
182
192
  it "should add_child_node" do
183
- return_value = @test_document.add_child_node(@test_document.ng_xml.root, :person, 'Bob', 'Builder')
184
- expect(return_value).to eq @test_document.find_by_terms(:person => 1).first
185
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
193
+ return_value = test_document.add_child_node(test_document.ng_xml.root, :person, 'Bob', 'Builder')
194
+ expect(return_value).to eq test_document.find_by_terms(:person => 1).first
195
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
186
196
  end
187
-
197
+
188
198
  it "should add_next_sibling_node" do
189
- return_value = @test_document.add_next_sibling_node([:person => 0], :person, 'Bob', 'Builder')
190
- expect(return_value).to eq @test_document.find_by_terms(:person => 1).first
191
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
199
+ return_value = test_document.add_next_sibling_node([:person => 0], :person, 'Bob', 'Builder')
200
+ expect(return_value).to eq test_document.find_by_terms(:person => 1).first
201
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
192
202
  end
193
203
 
194
204
  it "should add_previous_sibling_node" do
195
- return_value = @test_document.add_previous_sibling_node([:person => 0], :person, 'Bob', 'Builder')
196
- expect(return_value).to eq @test_document.find_by_terms(:person => 0).first
197
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
205
+ return_value = test_document.add_previous_sibling_node([:person => 0], :person, 'Bob', 'Builder')
206
+ expect(return_value).to eq test_document.find_by_terms(:person => 0).first
207
+ expect(test_document.ng_xml).to be_equivalent_to(expect_before).respecting_element_order
198
208
  end
199
209
 
200
210
  it "should after_node" do
201
- return_value = @test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
202
- expect(return_value).to eq @test_document.find_by_terms(:person => 0).first
203
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
211
+ return_value = test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
212
+ expect(return_value).to eq test_document.find_by_terms(:person => 0).first
213
+ expect(test_document.ng_xml).to be_equivalent_to(expect_after).respecting_element_order
204
214
  end
205
215
 
206
216
  it "should before_node" do
207
- return_value = @test_document.before_node([:person => 0], :person, 'Bob', 'Builder')
208
- expect(return_value).to eq @test_document.find_by_terms(:person => 1).first
209
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
217
+ return_value = test_document.before_node([:person => 0], :person, 'Bob', 'Builder')
218
+ expect(return_value).to eq test_document.find_by_terms(:person => 1).first
219
+ expect(test_document.ng_xml).to be_equivalent_to(expect_before).respecting_element_order
210
220
  end
211
221
 
212
222
  it "should replace_node" do
213
- target_node = @test_document.find_by_terms(:person => 0).first
214
- return_value = @test_document.replace_node(target_node, :person, 'Bob', 'Builder')
215
- expect(return_value).to eq @test_document.find_by_terms(:person => 0).first
216
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
223
+ target_node = test_document.find_by_terms(:person => 0).first
224
+ return_value = test_document.replace_node(target_node, :person, 'Bob', 'Builder')
225
+ expect(return_value).to eq test_document.find_by_terms(:person => 0).first
226
+ expect(test_document.ng_xml).to be_equivalent_to(expect_instead).respecting_element_order
217
227
  end
218
228
 
219
229
  it "should swap_node" do
220
- target_node = @test_document.find_by_terms(:person => 0).first
221
- return_value = @test_document.swap_node(target_node, :person, 'Bob', 'Builder')
230
+ target_node = test_document.find_by_terms(:person => 0).first
231
+ return_value = test_document.swap_node(target_node, :person, 'Bob', 'Builder')
222
232
  expect(return_value).to eq target_node
223
- expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
233
+ expect(test_document.ng_xml).to be_equivalent_to(expect_instead).respecting_element_order
224
234
  end
225
235
  end
226
-
236
+
227
237
  end