-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_helper.rb
More file actions
83 lines (64 loc) · 2.65 KB
/
spec_helper.rb
File metadata and controls
83 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# ------------------------------------------------------------
# Rails
ENV['RAILS_ENV'] = 'test'
# ------------------------------------------------------------
# Dependencies
require 'colorize'
require 'webmock/rspec'
require 'simplecov' if ENV['COVERAGE']
# ------------------------------------------------------------
# RSpec configuration
RSpec.configure do |config|
config.color = true
config.tty = true
config.formatter = :documentation
config.before { WebMock.disable_net_connect!(allow_localhost: true) }
config.after { WebMock.allow_net_connect! }
# Required for shared contexts (e.g. in ssh_helper.rb); see
# https://relishapp.com/rspec/rspec-core/docs/example-groups/shared-context#background
config.shared_context_metadata_behavior = :apply_to_host_groups
# System tests
# cf. https://medium.com/table-xi/a-quick-guide-to-rails-system-tests-in-rspec-b6e9e8a8b5f6
config.before(:each, type: :system) do
# Alpine Linux doesn't get along with webdrivers (https://github.com/titusfortner/webdrivers/issues/78),
# so we use Rack::Test instead of the Rails 6 default Selenium/Chrome. If/as/when we need JavaScript
# testing, we can try to find a more permanent solutino.
driven_by :rack_test, using: :rack_test
end
# AVPlayer configuration, or rather deconfiguration
config.before do
BerkeleyLibrary::AV::Config.send(:clear!) if defined?(AV::Config)
end
end
# ------------------------------------------------------------
# Utility methods
# TODO: use BerkeleyLibrary::Alma for this stuff
def sru_url_base
'https://berkeley.alma.exlibrisgroup.com/view/sru/01UCS_BER?version=1.2&operation=searchRetrieve&query='
end
def permalink_base
'https://search.library.berkeley.edu/permalink/01UCS_BER/iqob43/alma'
end
def alma_sru_url_for(record_id)
id_type = BerkeleyLibrary::AV::RecordId::Type.for_id(record_id)
if id_type == BerkeleyLibrary::AV::RecordId::Type::MILLENNIUM
full_bib = BerkeleyLibrary::AV::RecordId.ensure_check_digit(record_id)
return "#{sru_url_base}alma.other_system_number%3DUCB-#{full_bib}-01ucs_ber"
end
"#{sru_url_base}alma.mms_id%3D#{record_id}"
end
def alma_sru_data_path_for(record_id)
"spec/data/alma/#{record_id}-sru.xml"
end
def stub_sru_request(record_id, body: nil)
sru_url = alma_sru_url_for(record_id)
stub_request(:get, sru_url).to_return(status: 200, body: body || File.new(alma_sru_data_path_for(record_id)))
end
def stub_sru_head_request(record_id)
sru_url = alma_sru_url_for(record_id)
stub_request(:head, sru_url).to_return(status: 200)
end
def alma_marc_record_for(record_id)
marc_xml_path = alma_sru_data_path_for(record_id)
MARC::XMLReader.new(marc_xml_path).first
end