Skip to content

Commit 6ffd7c4

Browse files
authored
Merge pull request #62 from code4lib/get_tests_passing
Get tests passing when run locally (ActiveRecord 4.2)
2 parents 52aa1cc + 357c213 commit 6ffd7c4

29 files changed

+90
-139
lines changed

Gemfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ gemspec
55
gem 'jruby-openssl', :platform => :jruby
66

77
group :test do
8-
gem 'activerecord', '~> 4.0.0'
8+
gem 'activerecord', '~> 4.2.0'
99
gem 'activerecord-jdbcsqlite3-adapter', :platform => [:jruby]
1010
gem 'libxml-ruby', :platform => [:ruby, :mswin]
1111
gem 'rake'
1212
gem 'yard'
1313
gem 'redcarpet', :platform => :ruby # For fast, Github-like Markdown
1414
gem 'kramdown', :platform => :jruby # For Markdown without a C compiler
15-
gem 'rcov', '~> 0.9', :platform => [:ruby_18, :jruby]
1615
gem 'test-unit'
17-
gem 'simplecov', :platform => :ruby_19
18-
gem 'simplecov-rcov', :platform => :ruby_19
1916
gem 'sqlite3', :platform => [:ruby, :mswin]
2017
end

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ ruby-oai
22
========
33

44
ruby-oai is a Open Archives Protocol for Metadata Harvesting (OAI-PMH)
5-
library for Ruby. [OAI-PMH](http://openarchives.org) is a somewhat
6-
archaic protocol for sharing metadata between digital library repositories.
5+
library for Ruby. [OAI-PMH](http://openarchives.org) is a somewhat
6+
archaic protocol for sharing metadata between digital library repositories.
77
If you are looking to share metadata on the web you are probably better off
8-
using a feed format like [RSS](http://www.rssboard.org/rss-specification) or
9-
[Atom](http://www.atomenabled.org/). If have to work with a backwards
10-
digital repository that only offers OAI-PMH access then ruby-oai is your
8+
using a feed format like [RSS](http://www.rssboard.org/rss-specification) or
9+
[Atom](http://www.atomenabled.org/). If have to work with a backwards
10+
digital repository that only offers OAI-PMH access then ruby-oai is your
1111
friend.
1212

13-
The [OAI-PMH](http://openarchives.org) spec defines six verbs
14-
(`Identify`, `ListIdentifiers`, `ListRecords`,
13+
The [OAI-PMH](http://openarchives.org) spec defines six verbs
14+
(`Identify`, `ListIdentifiers`, `ListRecords`,
1515
`GetRecords`, `ListSets`, `ListMetadataFormat`) used for discovery and sharing of
1616
metadata.
1717

@@ -21,15 +21,15 @@ a interactive harvesting shell.
2121
Client
2222
------
2323

24-
The OAI client library is used for harvesting metadata from repositories.
24+
The OAI client library is used for harvesting metadata from repositories.
2525
For example to initiate a ListRecords request to pubmed you can:
2626

2727
```ruby
2828
require 'oai'
2929
client = OAI::Client.new 'http://www.pubmedcentral.gov/oai/oai.cgi', :headers => { "From" => "[email protected]" }
3030
response = client.list_records
3131
# Get the first page of records
32-
response.each do |record|
32+
response.each do |record|
3333
puts record.metadata
3434
end
3535
# Get the second page of records
@@ -81,6 +81,15 @@ Alternately it can be installed globally using RubyGems:
8181

8282
$ gem install oai
8383

84+
Running tests
85+
-------------
86+
87+
Tests are with Test::Unit, in a somewhat archaic/legacy style. Test setup especially is not how we would do things today. Run all tests with:
88+
89+
$ bundle exec rake test
90+
91+
There are also convenience tasks to run subsets of tests.
92+
8493
License
8594
-------
8695

Rakefile

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,73 +14,40 @@ require 'yard'
1414

1515
task :default => ["test", "yard"]
1616

17-
task :test => ["test:client", "test:provider", "test:activerecord_provider"]
17+
Rake::TestTask.new('test') do |t|
18+
t.description = "Run all Test::Unit tests"
1819

20+
t.libs << ['lib', 'test/client', 'test/provider', 'test/activerecord_provider']
21+
22+
t.pattern = 'test/{client,provider,activerecord_provider}/tc_*.rb'
23+
#t.verbose = true
24+
t.warning = false
25+
end
26+
27+
28+
# To run just subsets of tests
1929
namespace :test do
2030
Rake::TestTask.new('client') do |t|
2131
t.libs << ['lib', 'test/client']
2232
t.pattern = 'test/client/tc_*.rb'
23-
t.verbose = true
33+
#t.verbose = true
34+
t.warning = false
2435
end
2536

2637
Rake::TestTask.new('provider') do |t|
2738
t.libs << ['lib', 'test/provider']
2839
t.pattern = 'test/provider/tc_*.rb'
29-
t.verbose = true
40+
#t.verbose = true
41+
t.warning = false
3042
end
3143

32-
desc "Active Record base Provider Tests"
3344
Rake::TestTask.new('activerecord_provider') do |t|
45+
t.description = "Active Record base Provider Tests"
46+
3447
t.libs << ['lib', 'test/activerecord_provider']
3548
t.pattern = 'test/activerecord_provider/tc_*.rb'
36-
t.verbose = true
37-
end
38-
39-
desc 'Measures test coverage'
40-
# borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask
41-
task :coverage do
42-
rm_f "coverage"
43-
rm_f "coverage.data"
44-
if RUBY_VERSION =~ /^1.8/
45-
Rake::Task['rcov:client'].invoke
46-
Rake::Task['rcov:provider'].invoke
47-
Rake::Task['rcov:activerecord_provider'].invoke
48-
else
49-
ENV['COVERAGE'] = 'true'
50-
Rake::Task['test:client'].invoke
51-
Rake::Task['test:provider'].invoke
52-
Rake::Task['test:activerecord_provider'].invoke
53-
end
54-
55-
system("open coverage/index.html") if (PLATFORM['darwin'] if Kernel.const_defined? :PLATFORM) || (RUBY_PLATFORM =~ /darwin/ if Kernel.const_defined? :RUBY_PLATFORM)
56-
end
57-
58-
end
59-
60-
if RUBY_VERSION =~ /^1.8/
61-
require 'rcov/rcovtask'
62-
namespace :rcov do
63-
Rcov::RcovTask.new do |t|
64-
t.name = 'client'
65-
t.libs << ['lib', 'test/client']
66-
t.pattern = 'test/client/tc_*.rb'
67-
t.verbose = true
68-
t.rcov_opts = ['--aggregate coverage.data', '--text-summary']
69-
end
70-
71-
Rcov::RcovTask.new('provider') do |t|
72-
t.libs << ['lib', 'test/provider']
73-
t.pattern = 'test/provider/tc_*.rb'
74-
t.verbose = true
75-
t.rcov_opts = ['--aggregate coverage.data', '--text-summary']
76-
end
77-
78-
Rcov::RcovTask.new('activerecord_provider') do |t|
79-
t.libs << ['lib', 'test/activerecord_provider']
80-
t.pattern = 'test/activerecord_provider/tc_*.rb'
81-
t.verbose = true
82-
t.rcov_opts = ['--aggregate coverage.data', '--text-summary']
83-
end
49+
#t.verbose = true
50+
t.warning = false
8451
end
8552
end
8653

test/activerecord_provider/tc_ar_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'test_helper_ar_provider'
22

33
class ActiveRecordProviderTest < TransactionalTestCase
44

test/activerecord_provider/tc_ar_sets_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'test_helper_ar_provider'
22

33
class ActiveRecordSetProviderTest < TransactionalTestCase
44

test/activerecord_provider/tc_caching_paging_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'test_helper_ar_provider'
22

33
class CachingPagingProviderTest < TransactionalTestCase
44
include REXML

test/activerecord_provider/tc_simple_paging_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'test_helper_ar_provider'
22

33
class SimpleResumptionProviderTest < TransactionalTestCase
44
include REXML

test/activerecord_provider/test_helper.rb renamed to test/activerecord_provider/test_helper_ar_provider.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
require 'rubygems'
22

3-
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
4-
require 'simplecov'
5-
require 'simplecov-rcov'
6-
7-
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
8-
SimpleCov.start
9-
end
103
require 'test/unit'
114
require File.dirname(__FILE__) + '/config/connection'
125
require File.dirname(__FILE__) + '/helpers/providers'

test/client/helpers/provider.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
require 'webrick'
22
require File.dirname(__FILE__) + '/../../provider/models'
33

4-
class ComplexProvider < OAI::Provider::Base
5-
repository_name 'Complex Provider'
6-
repository_url 'http://localhost'
7-
record_prefix 'oai:test'
8-
source_model ComplexModel.new(100)
9-
end
104

115
class ProviderServer
6+
class ComplexClientProvider < OAI::Provider::Base
7+
repository_name 'Complex Provider'
8+
repository_url 'http://localhost'
9+
record_prefix 'oai:test'
10+
source_model ComplexModel.new(100)
11+
end
1212

1313
attr_reader :consumed, :server
1414

1515
def initialize(port, mount_point)
1616
@consumed = []
17-
@provider = ComplexProvider.new
17+
@provider = ComplexClientProvider.new
1818
@server = WEBrick::HTTPServer.new(
1919
:BindAddress => '127.0.0.1',
2020
:Logger => WEBrick::Log.new('/dev/null'),
@@ -62,4 +62,4 @@ def server_proc
6262
end
6363
end
6464

65-
end
65+
end

test/client/tc_exception.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require 'test_helper_client'
22

33
class ExceptionTest < Test::Unit::TestCase
44

@@ -9,7 +9,7 @@ def test_not_found
99

1010
def test_xml_error
1111
client = OAI::Client.new 'http://www.yahoo.com'
12-
begin
12+
begin
1313
client.identify
1414
rescue OAI::Exception => e
1515
assert_match /response not well formed XML/, e.to_s, 'xml error'
@@ -23,7 +23,7 @@ def test_oai_error
2323
end
2424
end
2525

26-
# must pass in options as a hash
26+
# must pass in options as a hash
2727
def test_parameter_error
2828
client = OAI::Client.new 'http://localhost:3333/oai'
2929
assert_raises(OAI::ArgumentException) {client.get_record('foo')}
@@ -32,5 +32,5 @@ def test_parameter_error
3232
assert_raises(OAI::ArgumentException) {client.list_metadata_formats('foo')}
3333
assert_raises(OAI::ArgumentException) {client.list_sets('foo')}
3434
end
35-
35+
3636
end

0 commit comments

Comments
 (0)