if ENV["CODECLIMATE_REPO_TOKEN"] # report coverage only for latest mri ruby if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.2.0" require "codeclimate-test-reporter" CodeClimate::TestReporter.start end else require "simplecov" SimpleCov.start end require "mabmapper" require "mabmapper/aleph_mab_xml_engine" require "hashdiff" require "nokogiri" require "yaml" begin require "pry" rescue LoadError end RSpec.configure do |config| # begin --- rspec 3.1 generator config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end # end --- rspec 3.1 generator end def asset_dir File.expand_path(File.join(File.dirname(__FILE__), "assets")) end def mab_xml_builder(identifier="aleph-publish:000000000", &block) Nokogiri::XML::Builder.new do send( :"OAI-PMH", "xmlns" => "http://www.openarchives.org/OAI/2.0/", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd" ) do ListRecords do record do header do |_xml| _xml.identifier identifier end metadata do record("xmlns" => "http://www.ddb.de/professionell/mabxml/mabxml-1.xsd") do define_singleton_method(:controlfield) do |_tag, _text| send(:method_missing, :controlfield, _text, tag: _tag) end define_singleton_method(:datafield) do |_tag, _attributes = {}, &_block| send(:method_missing, :datafield, {tag: _tag}.merge(_attributes), &_block) end define_singleton_method(:subfield) do |_code, _text| send(:method_missing, :subfield, _text, code: _code) end define_singleton_method(:journal!) do controlfield("052", "p") end instance_eval(&block) end end end end end end .to_xml end def transform(mab_xml) Mabmapper::AlephMabXmlEngine.new.process(nil, mab_xml).to_hash end def read_asset(path_to_file) File.read(File.expand_path(File.join(asset_dir, path_to_file))) end