harvestdor 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,9 +12,9 @@ describe 'Harvestdor::Client oai harvesting' do
12
12
  describe "druids_via_oai" do
13
13
  before(:each) do
14
14
  oai_response = double('oai_response')
15
- oai_response.stub(:entries).and_return(['foo', 'bar'])
16
- oai_response.stub(:resumption_token).and_return('')
17
- @harvestdor_client.oai_client.stub(:list_identifiers).with(an_instance_of(Hash)) {
15
+ allow(oai_response).to receive(:entries).and_return(['foo', 'bar'])
16
+ allow(oai_response).to receive(:resumption_token).and_return('')
17
+ allow(@harvestdor_client.oai_client).to receive(:list_identifiers).with(an_instance_of(Hash)) {
18
18
  oai_response
19
19
  }
20
20
  end
@@ -24,14 +24,14 @@ describe 'Harvestdor::Client oai harvesting' do
24
24
  header2 = OAI::Header.new(nil)
25
25
  header2.identifier = 'oai:searchworks.stanford.edu/druid:bar'
26
26
  oai_response = double('oai_response')
27
- oai_response.stub(:entries).and_return([header1, header2])
28
- @harvestdor_client.druids_via_oai.should == ['foo', 'bar']
27
+ allow(oai_response).to receive(:entries).and_return([header1, header2])
28
+ expect(@harvestdor_client.druids_via_oai).to eql(['foo', 'bar'])
29
29
  end
30
30
  it "should have results viewable as an array" do
31
- @harvestdor_client.druids_via_oai.should be_an_instance_of(Array)
31
+ expect(@harvestdor_client.druids_via_oai).to be_an_instance_of(Array)
32
32
  end
33
33
  it "should have enumerable results" do
34
- @harvestdor_client.druids_via_oai.should respond_to(:each, :count)
34
+ expect(@harvestdor_client.druids_via_oai).to respond_to(:each, :count)
35
35
  end
36
36
  it "should yield to a passed block" do
37
37
  expect { |b| @harvestdor_client.druids_via_oai(&b) }.to yield_successive_args('foo', 'bar')
@@ -41,9 +41,9 @@ describe 'Harvestdor::Client oai harvesting' do
41
41
  describe "oai_records" do
42
42
  before(:each) do
43
43
  @oai_response = double('oai_response')
44
- @oai_response.stub(:entries).and_return([1, 2])
45
- @oai_response.stub(:resumption_token).and_return('')
46
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
44
+ allow(@oai_response).to receive(:entries).and_return([1, 2])
45
+ allow(@oai_response).to receive(:resumption_token).and_return('')
46
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
47
47
  @oai_response
48
48
  }
49
49
  end
@@ -56,14 +56,14 @@ describe 'Harvestdor::Client oai harvesting' do
56
56
  header2.identifier = 'oai:searchworks.stanford.edu/druid:bar'
57
57
  oai_rec2 = OAI::Record.new(nil)
58
58
  oai_rec2.header = header2
59
- @oai_response.stub(:entries).and_return([oai_rec1, oai_rec2])
60
- @harvestdor_client.oai_records.should == [oai_rec1, oai_rec2]
59
+ allow(@oai_response).to receive(:entries).and_return([oai_rec1, oai_rec2])
60
+ expect(@harvestdor_client.oai_records).to eql([oai_rec1, oai_rec2])
61
61
  end
62
62
  it "should have results viewable as an array" do
63
- @harvestdor_client.oai_records.should be_an_instance_of(Array)
63
+ expect(@harvestdor_client.oai_records).to be_an_instance_of(Array)
64
64
  end
65
65
  it "should have enumerable results" do
66
- @harvestdor_client.oai_records.should respond_to(:each, :count)
66
+ expect(@harvestdor_client.oai_records).to respond_to(:each, :count)
67
67
  end
68
68
  it "should yield to a passed block" do
69
69
  expect { |b| @harvestdor_client.oai_records(&b) }.to yield_successive_args(1, 2)
@@ -73,9 +73,9 @@ describe 'Harvestdor::Client oai harvesting' do
73
73
  describe "oai_headers" do
74
74
  before(:each) do
75
75
  @oai_response = double('oai_response')
76
- @oai_response.stub(:entries).and_return([1, 2])
77
- @oai_response.stub(:resumption_token).and_return('')
78
- @harvestdor_client.oai_client.stub(:list_identifiers).with(an_instance_of(Hash)) {
76
+ allow(@oai_response).to receive(:entries).and_return([1, 2])
77
+ allow(@oai_response).to receive(:resumption_token).and_return('')
78
+ allow(@harvestdor_client.oai_client).to receive(:list_identifiers).with(an_instance_of(Hash)) {
79
79
  @oai_response
80
80
  }
81
81
  end
@@ -84,14 +84,14 @@ describe 'Harvestdor::Client oai harvesting' do
84
84
  header1.identifier = 'oai:searchworks.stanford.edu/druid:foo'
85
85
  header2 = OAI::Header.new(nil)
86
86
  header2.identifier = 'oai:searchworks.stanford.edu/druid:bar'
87
- @oai_response.stub(:entries).and_return([header1, header2])
88
- @harvestdor_client.oai_headers.should == [header1, header2]
87
+ allow(@oai_response).to receive(:entries).and_return([header1, header2])
88
+ expect(@harvestdor_client.oai_headers).to eql([header1, header2])
89
89
  end
90
90
  it "should have results viewable as an array" do
91
- @harvestdor_client.oai_headers.should be_an_instance_of(Array)
91
+ expect(@harvestdor_client.oai_headers).to be_an_instance_of(Array)
92
92
  end
93
93
  it "should have enumerable results" do
94
- @harvestdor_client.oai_headers.should respond_to(:each, :count)
94
+ expect(@harvestdor_client.oai_headers).to respond_to(:each, :count)
95
95
  end
96
96
  it "should yield to a passed block" do
97
97
  expect { |b| @harvestdor_client.oai_headers(&b) }.to yield_successive_args(1, 2)
@@ -102,12 +102,12 @@ describe 'Harvestdor::Client oai harvesting' do
102
102
  it "should return OAI::Record object" do
103
103
  oai_rec = OAI::Record.new(nil)
104
104
  oai_resp = double('oai_response')
105
- oai_resp.stub(:record).and_return(oai_rec)
106
- @harvestdor_client.oai_client.stub(:get_record) {
105
+ allow(oai_resp).to receive(:record).and_return(oai_rec)
106
+ allow(@harvestdor_client.oai_client).to receive(:get_record){
107
107
  oai_resp
108
108
  }
109
- @harvestdor_client.oai_record('druid').should == oai_rec
110
- @harvestdor_client.oai_record('druid', 'mods').should == oai_rec
109
+ expect(@harvestdor_client.oai_record('druid')).to eql(oai_rec)
110
+ expect(@harvestdor_client.oai_record('druid', 'mods')).to eql(oai_rec)
111
111
  end
112
112
  end
113
113
 
@@ -120,57 +120,57 @@ describe 'Harvestdor::Client oai harvesting' do
120
120
 
121
121
  end
122
122
  it "should use client's default values for OAI arguments if they are not present in the method param hash" do
123
- @harvestdor_client.send(:scrub_oai_args).should == @expected_oai_args
123
+ expect(@harvestdor_client.send(:scrub_oai_args)).to eql(@expected_oai_args)
124
124
  end
125
125
  it "should use OAI arguments from the method param hash if they are present" do
126
126
  passed_options = {:metadata_prefix => 'mods', :from => '2012-11-30'}
127
- @harvestdor_client.send(:scrub_oai_args, passed_options).should == @expected_oai_args.merge(passed_options)
127
+ expect(@harvestdor_client.send(:scrub_oai_args, passed_options)).to eql(@expected_oai_args.merge(passed_options))
128
128
  end
129
129
  it "should use nil value for option when it is passed in options hash" do
130
130
  client = Harvestdor::Client.new({:default_from_date => '2012-01-01'})
131
- client.config.default_from_date.should == '2012-01-01'
131
+ expect(client.config.default_from_date).to eql('2012-01-01')
132
132
  passed_options = {:from => nil}
133
- client.send(:scrub_oai_args, passed_options)[:from].should == nil
133
+ expect(client.send(:scrub_oai_args, passed_options)[:from]).to eql(nil)
134
134
  end
135
135
  end
136
136
 
137
137
  describe "harvest" do
138
138
  it "should perform a list_records OAI request when first arg is true" do
139
139
  oai_response = double('oai_response')
140
- oai_response.stub(:entries).and_return([])
141
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
140
+ allow(oai_response).to receive(:entries).and_return([])
141
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
142
142
  oai_response
143
143
  }
144
- @harvestdor_client.oai_client.should_receive(:list_records)
144
+ expect(@harvestdor_client.oai_client).to receive(:list_records)
145
145
  @harvestdor_client.send(:harvest, :list_records, {})
146
146
  end
147
147
 
148
148
  it "should perform a list_identifiers OAI request when first arg is false" do
149
149
  oai_response = double('oai_response')
150
- oai_response.stub(:entries).and_return([])
151
- @harvestdor_client.oai_client.stub(:list_identifiers).with(an_instance_of(Hash)) {
150
+ allow(oai_response).to receive(:entries).and_return([])
151
+ allow(@harvestdor_client.oai_client).to receive(:list_identifiers).with(an_instance_of(Hash)) {
152
152
  oai_response
153
153
  }
154
- @harvestdor_client.oai_client.should_receive(:list_identifiers)
154
+ expect(@harvestdor_client.oai_client).to receive(:list_identifiers)
155
155
  @harvestdor_client.send(:harvest, :list_identifiers, {})
156
156
  end
157
157
 
158
158
  it "should use passed OAI arguments" do
159
159
  oai_response = double('oai_response')
160
- oai_response.stub(:entries).and_return([])
161
- @harvestdor_client.oai_client.stub(:list_identifiers).with(an_instance_of(Hash)) {
160
+ allow(oai_response).to receive(:entries).and_return([])
161
+ allow(@harvestdor_client.oai_client).to receive(:list_identifiers).with(an_instance_of(Hash)) {
162
162
  oai_response
163
163
  }
164
164
  oai_options_hash = {:metadata_prefix => 'mods', :from => '2012-11-30'}
165
- @harvestdor_client.oai_client.should_receive(:list_identifiers).with(oai_options_hash)
165
+ expect(@harvestdor_client.oai_client).to receive(:list_identifiers).with(oai_options_hash)
166
166
  @harvestdor_client.send(:harvest, :list_identifiers, oai_options_hash)
167
167
  end
168
168
 
169
169
  it "should yield to a passed block" do
170
170
  oai_response = double('oai_response')
171
- oai_response.stub(:entries).and_return([1, 2])
172
- oai_response.stub(:resumption_token).and_return('')
173
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
171
+ allow(oai_response).to receive(:entries).and_return([1, 2])
172
+ allow(oai_response).to receive(:resumption_token).and_return('')
173
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
174
174
  oai_response
175
175
  }
176
176
  expect { |b| @harvestdor_client.send(:harvest, :list_records, {}, &b) }.to yield_successive_args(1, 2)
@@ -179,34 +179,34 @@ describe 'Harvestdor::Client oai harvesting' do
179
179
  context "resumption tokens" do
180
180
  it "should stop processing when no records/headers are received" do
181
181
  oai_response = double('oai_response')
182
- oai_response.stub(:entries).and_return([])
183
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
182
+ allow(oai_response).to receive(:entries).and_return([])
183
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
184
184
  oai_response
185
185
  }
186
186
 
187
187
  i = 0
188
188
  @harvestdor_client.send(:harvest, :list_records, {}) { |record| i += 1 }
189
- i.should == 0
189
+ expect(i).to eql(0)
190
190
  end
191
191
 
192
192
  it "should stop processing when the resumption token is empty" do
193
193
  oai_response_with_token = double('oai_response')
194
- oai_response_with_token.stub(:entries).and_return([1,2,3,4,5])
195
- oai_response_with_token.stub(:resumption_token).and_return('')
196
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
194
+ allow(oai_response_with_token).to receive(:entries).and_return([1,2,3,4,5])
195
+ allow(oai_response_with_token).to receive(:resumption_token).and_return('')
196
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
197
197
  oai_response_with_token
198
198
  }
199
199
 
200
200
  i = 0
201
201
  @harvestdor_client.send(:harvest, :list_records, {}) { |record| i += 1 }
202
- i.should == 5
202
+ expect(i).to eql(5)
203
203
  end
204
204
 
205
205
  it "should stop processing when there was no resumption token" do
206
206
  oai_response_with_token = double('oai_response')
207
- oai_response_with_token.stub(:entries).and_return([1,2,3,4,5])
208
- oai_response_with_token.stub(:resumption_token).and_return(nil)
209
- @harvestdor_client.oai_client.stub(:list_records).with(an_instance_of(Hash)) {
207
+ allow(oai_response_with_token).to receive(:entries).and_return([1,2,3,4,5])
208
+ allow(oai_response_with_token).to receive(:resumption_token).and_return(nil)
209
+ allow(@harvestdor_client.oai_client).to receive(:list_records).with(an_instance_of(Hash)) {
210
210
  oai_response_with_token
211
211
  }
212
212
 
@@ -16,18 +16,22 @@ describe 'Harvestdor::Client OAI Harvesting Integration Tests', :integration =>
16
16
  @oai_args = {:metadata_prefix => 'mods', :from => nil, :until => nil, :set => 'is_governed_by_hy787xj5878'}
17
17
  end
18
18
  it "should be able to harvest headers" do
19
- headers = @test_hclient.oai_headers(@oai_args)
20
- headers.should be_an_instance_of(Array)
21
- headers.size.should > 0
22
- headers.size.should < 50 # no resumption token
23
- headers.first.should be_an_instance_of(OAI::Header)
19
+ VCR.use_cassette('headers') do
20
+ headers = @test_hclient.oai_headers(@oai_args)
21
+ expect(headers).to be_an_instance_of(Array)
22
+ expect(headers.size).to be > 0
23
+ expect(headers.size).to be < 50 # no resumption token
24
+ expect(headers.first).to be_an_instance_of(OAI::Header)
25
+ end
24
26
  end
25
27
  it "should be able to harvest records" do
26
- records = @test_hclient.oai_records(@oai_args)
27
- records.should be_an_instance_of(Array)
28
- records.size.should > 0
29
- records.size.should < 50 # no resumption token
30
- records.first.should be_an_instance_of(OAI::Record)
28
+ VCR.use_cassette('records') do
29
+ records = @test_hclient.oai_records(@oai_args)
30
+ expect(records).to be_an_instance_of(Array)
31
+ expect(records.size).to be > 0
32
+ expect(records.size).to be < 50 # no resumption token
33
+ expect(records.first).to be_an_instance_of(OAI::Record)
34
+ end
31
35
  end
32
36
  end
33
37
  context "with resumption tokens" do
@@ -37,29 +41,31 @@ describe 'Harvestdor::Client OAI Harvesting Integration Tests', :integration =>
37
41
  it "should be able to harvest headers" do
38
42
  skip "need to find small set > 50 on test"
39
43
  headers = @test_hclient.oai_headers(@oai_args)
40
- headers.should be_an_instance_of(Array)
41
- headers.size.should > 50
42
- headers.first.should be_an_instance_of(OAI::Header)
44
+ expect(headers).to be_an_instance_of(Array)
45
+ expect(headers.size).to be > 50
46
+ expect(headers.first).to be_an_instance_of(OAI::Header)
43
47
  end
44
48
  it "should be able to harvest records" do
45
- pending "need to find small set > 50 on test"
49
+ skip "need to find small set > 50 on test"
46
50
  records = @test_hclient.harvest_records(@oai_args)
47
- records.should be_an_instance_of(Array)
48
- records.size.should > 50
49
- records.first.should be_an_instance_of(OAI::Record)
51
+ expect(records).to be_an_instance_of(Array)
52
+ expect(records.size).to be > 50
53
+ expect(records.first).to be_an_instance_of(OAI::Record)
50
54
  end
51
55
  end
52
56
  context "oai_record (single record request)" do
53
57
  before(:all) do
54
- @rec = @test_hclient.oai_record('jt959wc5586')
58
+ VCR.use_cassette('jt959wc5586_test') do
59
+ @rec = @test_hclient.oai_record('jt959wc5586')
60
+ end
55
61
  end
56
62
  it "should get a single OAI::Record object" do
57
- @rec.should be_an_instance_of(OAI::Record)
63
+ expect(@rec).to be_an_instance_of(OAI::Record)
58
64
  end
59
65
  it "should keep utf-8 encoded characters intact" do
60
66
  xml = Nokogiri::XML(@rec.metadata.to_s)
61
67
  xml.remove_namespaces!
62
- xml.root.xpath('/metadata/mods/titleInfo/subTitle').text.should =~ /^recueil complet des débats législatifs & politiques des chambres françaises/
68
+ expect(xml.root.xpath('/metadata/mods/titleInfo/subTitle').text).to match /^recueil complet des débats législatifs & politiques des chambres françaises/
63
69
  end
64
70
  end
65
71
  end
@@ -74,18 +80,22 @@ describe 'Harvestdor::Client OAI Harvesting Integration Tests', :integration =>
74
80
  @oai_args = {:metadata_prefix => 'mods', :from => nil, :until => nil, :set => 'is_governed_by_sd064kn5856'}
75
81
  end
76
82
  it "should be able to harvest headers" do
77
- headers = @prod_hclient.oai_headers(@oai_args)
78
- headers.should be_an_instance_of(Array)
79
- headers.size.should > 0
80
- headers.size.should < 50 # no resumption token
81
- headers.first.should be_an_instance_of(OAI::Header)
83
+ VCR.use_cassette('prod_headers') do
84
+ headers = @prod_hclient.oai_headers(@oai_args)
85
+ expect(headers).to be_an_instance_of(Array)
86
+ expect(headers.size).to be > 0
87
+ expect(headers.size).to be < 50 # no resumption token
88
+ expect(headers.first).to be_an_instance_of(OAI::Header)
89
+ end
82
90
  end
83
91
  it "should be able to harvest records" do
84
- records = @prod_hclient.oai_records(@oai_args)
85
- records.should be_an_instance_of(Array)
86
- records.size.should > 0
87
- records.size.should < 50 # no resumption token
88
- records.first.should be_an_instance_of(OAI::Record)
92
+ VCR.use_cassette('prod_records') do
93
+ records = @prod_hclient.oai_records(@oai_args)
94
+ expect(records).to be_an_instance_of(Array)
95
+ expect(records.size).to be > 0
96
+ expect(records.size).to be < 50 # no resumption token
97
+ expect(records.first).to be_an_instance_of(OAI::Record)
98
+ end
89
99
  end
90
100
  end
91
101
  context "with resumption tokens" do
@@ -94,30 +104,34 @@ describe 'Harvestdor::Client OAI Harvesting Integration Tests', :integration =>
94
104
  @oai_args = {:metadata_prefix => 'mods', :from => nil, :until => nil, :set => 'is_member_of_collection_jh957jy1101'}
95
105
  end
96
106
  it "should be able to harvest headers" do
97
- headers = @prod_hclient.oai_headers(@oai_args)
98
- headers.should be_an_instance_of(Array)
99
- headers.size.should > 50
100
- headers.first.should be_an_instance_of(OAI::Header)
107
+ VCR.use_cassette('headers_with_resumption') do
108
+ headers = @prod_hclient.oai_headers(@oai_args)
109
+ expect(headers).to be_an_instance_of(Array)
110
+ expect(headers.size).to be > 50
111
+ expect(headers.first).to be_an_instance_of(OAI::Header)
112
+ end
101
113
  end
102
114
  it "should be able to harvest records" do
103
- pending "the request always seems to time out"
115
+ skip "the request always seems to time out"
104
116
  records = @prod_hclient.oai_records(@oai_args)
105
- records.should be_an_instance_of(Array)
106
- records.size.should > 50
107
- records.first.should be_an_instance_of(OAI::Record)
117
+ expect(records).to be_an_instance_of(Array)
118
+ expect(records.size).to be > 50
119
+ expect(records.first).to be_an_instance_of(OAI::Record)
108
120
  end
109
121
  end
110
122
  context "oai_record (single record request)" do
111
123
  before(:all) do
112
- @rec = @prod_hclient.oai_record('jt959wc5586')
124
+ VCR.use_cassette('jt959wc5586_prod') do
125
+ @rec = @prod_hclient.oai_record('jt959wc5586')
126
+ end
113
127
  end
114
128
  it "should get a single OAI::Record object" do
115
- @rec.should be_an_instance_of(OAI::Record)
129
+ expect(@rec).to be_an_instance_of(OAI::Record)
116
130
  end
117
131
  it "should keep utf-8 encoded characters intact" do
118
132
  xml = Nokogiri::XML(@rec.metadata.to_s)
119
133
  xml.remove_namespaces!
120
- xml.root.xpath('/metadata/mods/titleInfo/subTitle').text.should =~ /^recueil complet des débats législatifs & politiques des chambres françaises/
134
+ expect(xml.root.xpath('/metadata/mods/titleInfo/subTitle').text).to match /^recueil complet des débats législatifs & politiques des chambres françaises/
121
135
  end
122
136
  end
123
137
  end
@@ -17,35 +17,41 @@ describe Harvestdor::Client do
17
17
  end
18
18
 
19
19
  it "#mods returns a Nokogiri::XML::Document from the purl mods" do
20
- x = Harvestdor.mods(@druid, @purl)
21
- x.should be_kind_of(Nokogiri::XML::Document)
22
- x.root.name.should == 'mods'
23
- x.root.namespace.href.should == Harvestdor::MODS_NAMESPACE
20
+ VCR.use_cassette('purl_mods') do
21
+ x = Harvestdor.mods(@druid, @purl)
22
+ expect(x).to be_kind_of(Nokogiri::XML::Document)
23
+ expect(x.root.name).to eql('mods')
24
+ expect(x.root.namespace.href).to eql(Harvestdor::MODS_NAMESPACE)
25
+ end
24
26
  end
25
27
 
26
28
  context "#public_xml" do
27
29
  it "#public_xml retrieves entire public xml as a Nokogiri::XML::Document when called with druid" do
28
- px = Harvestdor.public_xml(@druid, @purl)
29
- px.should be_kind_of(Nokogiri::XML::Document)
30
- px.root.name.should == 'publicObject'
31
- px.root.attributes['id'].text.should == "druid:#{@druid}"
30
+ VCR.use_cassette('public_xml') do
31
+ px = Harvestdor.public_xml(@druid, @purl)
32
+ expect(px).to be_kind_of(Nokogiri::XML::Document)
33
+ expect(px.root.name).to eql('publicObject')
34
+ expect(px.root.attributes['id'].text).to eql("druid:#{@druid}")
35
+ end
32
36
  end
33
37
  it "raises Harvestdor::Errors::MissingPurlPage if there is no purl page for the druid" do
34
- expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPurlPage)
38
+ VCR.use_cassette('missing_purl') do
39
+ expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPurlPage)
40
+ end
35
41
  end
36
42
  it "raises Harvestdor::Errors::MissingPublicXML if purl page returns nil document" do
37
- URI::HTTP.any_instance.should_receive(:open).and_return(nil)
43
+ expect_any_instance_of(URI::HTTP).to receive(:open).and_return(nil)
38
44
  expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPublicXml)
39
45
  end
40
46
  end
41
47
 
42
48
  context "#pub_xml" do
43
49
  it "retrieves public_xml via fetch when first arg is a druid" do
44
- Harvestdor.should_receive(:public_xml).with(@druid, @purl)
50
+ expect(Harvestdor).to receive(:public_xml).with(@druid, @purl)
45
51
  Harvestdor.pub_xml(@druid, @purl)
46
52
  end
47
53
  it "returns the first arg if it is a Nokogiri::XML::Document" do
48
- Harvestdor.pub_xml(@ng_pub_xml).should === @ng_pub_xml
54
+ expect(Harvestdor.pub_xml(@ng_pub_xml)).to eql(@ng_pub_xml)
49
55
  end
50
56
  it "raises error for unknown arg type" do
51
57
  expect { Harvestdor.pub_xml(Array.new)}.to raise_error(RuntimeError, "expected String or Nokogiri::XML::Document for first argument, got Array")
@@ -54,16 +60,18 @@ describe Harvestdor::Client do
54
60
 
55
61
  context "#content_metadata" do
56
62
  it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
57
- cm = Harvestdor.content_metadata(@druid, @purl)
58
- cm.should be_kind_of(Nokogiri::XML::Document)
59
- cm.root.name.should == 'contentMetadata'
60
- cm.root.attributes['objectId'].text.should == @druid
63
+ VCR.use_cassette('content_metadata') do
64
+ cm = Harvestdor.content_metadata(@druid, @purl)
65
+ expect(cm).to be_kind_of(Nokogiri::XML::Document)
66
+ expect(cm.root.name).to eql('contentMetadata')
67
+ expect(cm.root.attributes['objectId'].text).to eql(@druid)
68
+ end
61
69
  end
62
70
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
63
71
  cm = Harvestdor.content_metadata(@ng_pub_xml)
64
- cm.should be_kind_of(Nokogiri::XML::Document)
65
- cm.root.name.should == 'contentMetadata'
66
- cm.root.attributes['objectId'].text.should == @druid
72
+ expect(cm).to be_kind_of(Nokogiri::XML::Document)
73
+ expect(cm.root.name).to eql('contentMetadata')
74
+ expect(cm.root.attributes['objectId'].text).to eql(@druid)
67
75
  end
68
76
  it "raises MissingContentMetadata error if there is no contentMetadata in the public_xml for the druid" do
69
77
  pub_xml = "<publicObject id='druid:#{@druid}'>#{@id_md_xml}#{@rights_md_xml}</publicObject>"
@@ -73,17 +81,19 @@ describe Harvestdor::Client do
73
81
 
74
82
  context "#identity_metadata" do
75
83
  it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
76
- im = Harvestdor.identity_metadata(@druid, @purl)
77
- im.should be_kind_of(Nokogiri::XML::Document)
78
- im.root.name.should == 'identityMetadata'
79
- im.root.xpath('objectId').text.should == "druid:#{@druid}"
84
+ VCR.use_cassette('identity_metadata') do
85
+ im = Harvestdor.identity_metadata(@druid, @purl)
86
+ expect(im).to be_kind_of(Nokogiri::XML::Document)
87
+ expect(im.root.name).to eql('identityMetadata')
88
+ expect(im.root.xpath('objectId').text).to eql("druid:#{@druid}")
89
+ end
80
90
  end
81
91
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
82
- URI::HTTP.any_instance.should_not_receive(:open)
92
+ expect_any_instance_of(URI::HTTP).not_to receive(:open)
83
93
  im = Harvestdor.identity_metadata(@ng_pub_xml)
84
- im.should be_kind_of(Nokogiri::XML::Document)
85
- im.root.name.should == 'identityMetadata'
86
- im.root.xpath('objectId').text.should == "druid:#{@druid}"
94
+ expect(im).to be_kind_of(Nokogiri::XML::Document)
95
+ expect(im.root.name).to eql('identityMetadata')
96
+ expect(im.root.xpath('objectId').text).to eql("druid:#{@druid}")
87
97
  end
88
98
  it "raises MissingIdentityMetadata error if there is no identityMetadata in the public_xml for the druid" do
89
99
  pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@rights_md_xml}</publicObject>"
@@ -93,15 +103,17 @@ describe Harvestdor::Client do
93
103
 
94
104
  context "#rights_metadata" do
95
105
  it "#rights_metadata returns a Nokogiri::XML::Document from the public xml fetched with druid" do
96
- rm = Harvestdor.rights_metadata(@druid, @purl)
97
- rm.should be_kind_of(Nokogiri::XML::Document)
98
- rm.root.name.should == 'rightsMetadata'
106
+ VCR.use_cassette('rights_metadata') do
107
+ rm = Harvestdor.rights_metadata(@druid, @purl)
108
+ expect(rm).to be_kind_of(Nokogiri::XML::Document)
109
+ expect(rm.root.name).to eql('rightsMetadata')
110
+ end
99
111
  end
100
112
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
101
- URI::HTTP.any_instance.should_not_receive(:open)
113
+ expect_any_instance_of(URI::HTTP).not_to receive(:open)
102
114
  rm = Harvestdor.rights_metadata(@ng_pub_xml)
103
- rm.should be_kind_of(Nokogiri::XML::Document)
104
- rm.root.name.should == 'rightsMetadata'
115
+ expect(rm).to be_kind_of(Nokogiri::XML::Document)
116
+ expect(rm.root.name).to eql('rightsMetadata')
105
117
  end
106
118
  it "raises MissingRightsMetadata error if there is no identityMetadata in the public_xml for the druid" do
107
119
  pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
@@ -111,17 +123,19 @@ describe Harvestdor::Client do
111
123
 
112
124
  context "#rdf" do
113
125
  it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
114
- rdf = Harvestdor.rdf(@druid, @purl)
115
- rdf.should be_kind_of(Nokogiri::XML::Document)
116
- rdf.root.name.should == 'RDF'
117
- rdf.root.namespace.href.should == Harvestdor::RDF_NAMESPACE
126
+ VCR.use_cassette('rdf') do
127
+ rdf = Harvestdor.rdf(@druid, @purl)
128
+ expect(rdf).to be_kind_of(Nokogiri::XML::Document)
129
+ expect(rdf.root.name).to eql('RDF')
130
+ expect(rdf.root.namespace.href).to eql(Harvestdor::RDF_NAMESPACE)
131
+ end
118
132
  end
119
133
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
120
- URI::HTTP.any_instance.should_not_receive(:open)
134
+ expect_any_instance_of(URI::HTTP).not_to receive(:open)
121
135
  rdf = Harvestdor.rdf(@ng_pub_xml)
122
- rdf.should be_kind_of(Nokogiri::XML::Document)
123
- rdf.root.name.should == 'RDF'
124
- rdf.root.namespace.href.should == Harvestdor::RDF_NAMESPACE
136
+ expect(rdf).to be_kind_of(Nokogiri::XML::Document)
137
+ expect(rdf.root.name).to eql('RDF')
138
+ expect(rdf.root.namespace.href).to eql(Harvestdor::RDF_NAMESPACE)
125
139
  end
126
140
  it "raises MissingRDF error if there is no RDF in the public_xml for the druid" do
127
141
  pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
@@ -131,17 +145,19 @@ describe Harvestdor::Client do
131
145
 
132
146
  context "#dc" do
133
147
  it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
134
- dc = Harvestdor.dc(@druid, @purl)
135
- dc.should be_kind_of(Nokogiri::XML::Document)
136
- dc.root.name.should == 'dc'
137
- dc.root.namespace.href.should == Harvestdor::OAI_DC_NAMESPACE
148
+ VCR.use_cassette('dc') do
149
+ dc = Harvestdor.dc(@druid, @purl)
150
+ expect(dc).to be_kind_of(Nokogiri::XML::Document)
151
+ expect(dc.root.name).to eql('dc')
152
+ expect(dc.root.namespace.href).to eql(Harvestdor::OAI_DC_NAMESPACE)
153
+ end
138
154
  end
139
155
  it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
140
- URI::HTTP.any_instance.should_not_receive(:open)
156
+ expect_any_instance_of(URI::HTTP).not_to receive(:open)
141
157
  dc = Harvestdor.dc(@ng_pub_xml)
142
- dc.should be_kind_of(Nokogiri::XML::Document)
143
- dc.root.name.should == 'dc'
144
- dc.root.namespace.href.should == Harvestdor::OAI_DC_NAMESPACE
158
+ expect(dc).to be_kind_of(Nokogiri::XML::Document)
159
+ expect(dc.root.name).to eql('dc')
160
+ expect(dc.root.namespace.href).to eql(Harvestdor::OAI_DC_NAMESPACE)
145
161
  end
146
162
  it "raises MissingDC error if there is no DC in the public_xml for the druid" do
147
163
  pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
@@ -155,40 +171,40 @@ describe Harvestdor::Client do
155
171
  @druid = 'bb375wb8869'
156
172
  end
157
173
  it "public_xml calls Harvestdor.public_xml with config.purl" do
158
- Harvestdor.should_receive(:public_xml).with(@druid, @client.config.purl)
174
+ expect(Harvestdor).to receive(:public_xml).with(@druid, @client.config.purl)
159
175
  @client.public_xml(@druid)
160
176
  end
161
177
  it "content_metadata calls Harvestdor.content_metadata with config.purl" do
162
- Harvestdor.should_receive(:content_metadata).with(@druid, @client.config.purl)
178
+ expect(Harvestdor).to receive(:content_metadata).with(@druid, @client.config.purl)
163
179
  @client.content_metadata(@druid)
164
180
  end
165
181
  it "identity_metadata calls Harvestdor.identity_metadata with config.purl" do
166
- Harvestdor.should_receive(:identity_metadata).with(@druid, @client.config.purl)
182
+ expect(Harvestdor).to receive(:identity_metadata).with(@druid, @client.config.purl)
167
183
  @client.identity_metadata(@druid)
168
184
  end
169
185
  it "rights_metadata calls Harvestdor.rights_metadata with config.purl" do
170
- Harvestdor.should_receive(:rights_metadata).with(@druid, @client.config.purl)
186
+ expect(Harvestdor).to receive(:rights_metadata).with(@druid, @client.config.purl)
171
187
  @client.rights_metadata(@druid)
172
188
  end
173
189
  it "rdf calls Harvestdor.rdf with config.purl" do
174
- Harvestdor.should_receive(:rdf).with(@druid, @client.config.purl)
190
+ expect(Harvestdor).to receive(:rdf).with(@druid, @client.config.purl)
175
191
  @client.rdf(@druid)
176
192
  end
177
193
  it "dc calls Harvestdor.dc with config.purl" do
178
- Harvestdor.should_receive(:dc).with(@druid, @client.config.purl)
194
+ expect(Harvestdor).to receive(:dc).with(@druid, @client.config.purl)
179
195
  @client.dc(@druid)
180
196
  end
181
197
  it "mods calls Harvestdor.mods with config.purl" do
182
- Harvestdor.should_receive(:mods).with(@druid, @client.config.purl)
198
+ expect(Harvestdor).to receive(:mods).with(@druid, @client.config.purl)
183
199
  @client.mods(@druid)
184
200
  end
185
201
  it "methods for parts of public_xml should work with Nokogiri::XML::Document arg (and not fetch)" do
186
- URI::HTTP.any_instance.should_not_receive(:open)
187
- @client.content_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
188
- @client.identity_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
189
- @client.rights_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
190
- @client.rdf(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
191
- @client.dc(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
202
+ expect_any_instance_of(URI::HTTP).not_to receive(:open)
203
+ expect(@client.content_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
204
+ expect(@client.identity_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
205
+ expect(@client.rights_metadata(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
206
+ expect(@client.rdf(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
207
+ expect(@client.dc(@ng_pub_xml)).to be_kind_of(Nokogiri::XML::Document)
192
208
  end
193
209
  end
194
210
  end