diff --git a/spec/sword/adapters/hyacinth_adapter_spec.rb b/spec/sword/adapters/hyacinth_adapter_spec.rb index 87e5df0..1e37b51 100644 --- a/spec/sword/adapters/hyacinth_adapter_spec.rb +++ b/spec/sword/adapters/hyacinth_adapter_spec.rb @@ -30,7 +30,7 @@ ########################################## encoding methods functionality specs describe 'encode methods' do - let(:hyacinth_adapter) { Sword::Adapters::HyacinthAdapter.new } + hyacinth_adapter = Sword::Adapters::HyacinthAdapter.new ########################################## #encode_abstract describe '#encode_abstract' do diff --git a/spec/sword/parsers/eprints_dc_xml_parser_spec.rb b/spec/sword/parsers/eprints_dc_xml_parser_spec.rb index 171bf4e..23a7c01 100644 --- a/spec/sword/parsers/eprints_dc_xml_parser_spec.rb +++ b/spec/sword/parsers/eprints_dc_xml_parser_spec.rb @@ -3,150 +3,38 @@ require 'sword/parsers/eprints_dc_xml_parser.rb' RSpec.describe Sword::Parsers::EprintsDcXmlParser do - subject(:epdcx_parser) { Sword::Parsers::EprintsDcXmlParser.new } let(:nokogiri_xml) { Nokogiri::XML(xml_file) } ########################################## Initial state describe 'Initial state' do context '#initialize sets @creators to' do it 'an empty array' do - expect(epdcx_parser.creators).to be_an_instance_of(Array) - expect(epdcx_parser.creators.empty?).to be(true) + expect(subject.creators).to be_an_instance_of(Array) + expect(subject.creators.empty?).to be(true) end end context '#initialize sets @subjects to' do it 'an empty array' do - expect(epdcx_parser.subjects).to be_an_instance_of(Array) - expect(epdcx_parser.subjects.empty?).to be(true) - end - end - end - - ########################################## API/interface - describe 'API/interface' do - context 'has attr_accessor for instance var' do - # http://purl.org/dc/terms/abstract - # http://dublincore.org/documents/dcmi-terms/#terms-abstract - it 'abstract' do - expect(subject).to respond_to(:abstract) - expect(subject).to respond_to(:abstract=) - end - - # http://purl.org/eprint/terms/bibliographicCitation - it 'bibliographic_citation' do - expect(subject).to respond_to(:bibliographic_citation) - expect(subject).to respond_to(:bibliographic_citation=) - end - - # http://purl.org/dc/elements/1.1/creator - # http://dublincore.org/documents/dcmi-terms/#terms-creator - it 'creators' do - expect(subject).to respond_to(:creators) - expect(subject).to respond_to(:creators=) - end - - # http://purl.org/dc/terms/available - # http://dublincore.org/documents/dcmi-terms/#terms-available - # format: YYYY-MM-DD - it 'date_available' do - expect(subject).to respond_to(:date_available) - expect(subject).to respond_to(:date_available=) - end - - # http://purl.org/dc/elements/1.1/identifier - # in this case, uri will be a doi - # http://dublincore.org/documents/dcmi-terms/#terms-identifier - it 'identifier' do - expect(subject).to respond_to(:identifier) - expect(subject).to respond_to(:identifier=) - end - - # http://purl.org/dc/elements/1.1/identifier - # Idenfifier is a URI: http://purl.org/dc/terms/URI - # in this case, uri will be a doi - # http://dublincore.org/documents/dcmi-terms/#terms-identifier - it 'identifier_uri' do - expect(subject).to respond_to(:identifier_uri) - expect(subject).to respond_to(:identifier_uri=) - end - - # http://purl.org/dc/elements/1.1/publisher - # https://www.dublincore.org/specifications/dublin-core/dcmi-terms/#http://purl.org/dc/terms/publisher - it 'publisher' do - expect(subject).to respond_to(:publisher) - expect(subject).to respond_to(:publisher=) - end - - # http://purl.org/dc/elements/1.1/subject - # http://dublincore.org/documents/dcmi-terms/#terms-subject - it 'subjects' do - expect(subject).to respond_to(:subjects) - expect(subject).to respond_to(:subjects=) - end - - # http://purl.org/dc/elements/1.1/title - # http://dublincore.org/documents/dcmi-terms/#terms-title - it 'title' do - expect(subject).to respond_to(:title) - expect(subject).to respond_to(:title=) - end - end - - context ' has the following instance method:' do - it '#get_abstract method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_abstract).with(1).arguments - end - - it '#get_date_available method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_date_available).with(1).arguments - end - - it '#get_identifier method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_identifier).with(1).arguments - end - - it '#get_identifier_uri method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_identifier_uri).with(1).arguments - end - - it '#get_publisher method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_publisher).with(1).arguments - end - - it '#get_title method that takes a Nokogiri::XML::Document to parse' do - expect(subject).to respond_to(:get_title).with(1).arguments - end - - it '#parse method that takes file to parse' do - expect(subject).to respond_to(:parse).with(1).arguments - end - - # http://purl.org/dc/terms/available - # http://dublincore.org/documents/dcmi-terms/#terms-available - # method will parse out the year from the YYYY-MM-DD format - # so returns YYYY - it 'date_available_year' do - expect(subject).to respond_to(:date_available_year) + expect(subject.subjects).to be_an_instance_of(Array) + expect(subject.subjects.empty?).to be(true) end end end ########################################## #parse_bibliographic_citation describe '#parse_bibliographic_citation' do - let(:actual_citation) { epdcx_parser.bibliographic_citation } - before { epdcx_parser.parse_bibliographic_citation nokogiri_xml } - context "with bibliographic citation title set to 'Conflict and Health'" do - let(:xml_file) { Rails.root.join "spec/fixtures/mets_files/springer-nature-bibcitation-1-xmlData.xml" } - let(:expected_citation) do - bib_citation = Sword::Metadata::EpdcxBibliographicCitation.new - bib_citation.issue = '1' - bib_citation.publish_year = '2018' - bib_citation.start_page = '37' - bib_citation.title = 'Conflict and Health' - bib_citation.volume = '12' - bib_citation - end + xml_file = Rails.root.join "spec/fixtures/mets_files/springer-nature-bibcitation-1-xmlData.xml" + nokogiri_xml = Nokogiri::XML(xml_file) + parser = Sword::Parsers::EprintsDcXmlParser.new + parser.parse_bibliographic_citation nokogiri_xml + actual_citation = parser.bibliographic_citation + expected_citation = Sword::Metadata::EpdcxBibliographicCitation.new + expected_citation.issue = '1' + expected_citation.publish_year = '2018' + expected_citation.start_page = '37' + expected_citation.title = 'Conflict and Health' + expected_citation.volume = '12' it "parses the bibligraphic citation issue correctly" do expect(actual_citation.issue).to eq expected_citation.issue @@ -170,16 +58,19 @@ end context "with bibliographic citation title set to 'Stem Cell Research & Therapy' (note the '&', coded as '&' in the incoming xml" do - let(:xml_file) { Rails.root.join "spec/fixtures/mets_files/springer-nature-bibcitation-2-xmlData.xml" } - let(:expected_citation) do - bib_citation = Sword::Metadata::EpdcxBibliographicCitation.new - bib_citation.issue = '1' - bib_citation.publish_year = '2018' - bib_citation.start_page = '229' - bib_citation.title = 'Stem Cell Research & Therapy' - bib_citation.volume = '9' - bib_citation - end + xml_file = Rails.root.join "spec/fixtures/mets_files/springer-nature-bibcitation-2-xmlData.xml" + nokogiri_xml = Nokogiri::XML(xml_file) + parser = Sword::Parsers::EprintsDcXmlParser.new + parser.parse_bibliographic_citation nokogiri_xml + actual_citation = parser.bibliographic_citation + expected_citation = Sword::Metadata::EpdcxBibliographicCitation.new + expected_citation.issue = '1' + expected_citation.publish_year = '2018' + expected_citation.start_page = '229' + expected_citation.title = 'Stem Cell Research & Therapy' + expected_citation.volume = '9' + expected_citation + it "parses the bibligraphic citation issue correctly" do expect(actual_citation.issue).to eq expected_citation.issue end @@ -204,51 +95,51 @@ ########################################## #parse describe '#parse' do - before { epdcx_parser.parse nokogiri_xml } + before { subject.parse nokogiri_xml } context "In mets file containing expected elements" do let(:xml_file) { Rails.root.join "spec/fixtures/mets_files/eprint_xmlData.xml" } it "parses the abstract correctly" do - expect(epdcx_parser.abstract).to eq "This is the abstract" + expect(subject.abstract).to eq "This is the abstract" end it "parses the date available correctly" do - expect(epdcx_parser.date_available).to eq "2018-08-06" + expect(subject.date_available).to eq "2018-08-06" end it "parses the date available (year) correctly" do - expect(epdcx_parser.date_available_year).to eq "2018" + expect(subject.date_available_year).to eq "2018" end context 'in creators arrays' do let(:expected_names) { ['Muhanguzi, Florence K','Mootz, Jennifer J','Panko, Pavel'] } it "parses names correctly" do - expect(epdcx_parser.creators).to contain_exactly(*expected_names) + expect(subject.creators).to contain_exactly(*expected_names) end end it "parses the identfier correctly" do - expect(epdcx_parser.identifier).to eq "https://doi.org/10.1186/s13031-018-0173-x" + expect(subject.identifier).to eq "https://doi.org/10.1186/s13031-018-0173-x" end it "parses the identfier URI correctly" do - expect(epdcx_parser.identifier_uri).to eq "https://doi.org/10.1186/s13031-018-0173-x" + expect(subject.identifier_uri).to eq "https://doi.org/10.1186/s13031-018-0173-x" end it "parses the publisher correctly" do - expect(epdcx_parser.publisher).to eq "BioMed Central" + expect(subject.publisher).to eq "BioMed Central" end context 'in subjects arrays' do let(:expected_subjects) { ['Alcohol use','Armed conflict','Uganda'] } it "parses subjects correctly" do - expect(epdcx_parser.subjects).to contain_exactly(*expected_subjects) + expect(subject.subjects).to contain_exactly(*expected_subjects) end end it "parses the title correctly" do - expect(epdcx_parser.title).to eq "Armed conflict in Northeastern Uganda: a population level study" + expect(subject.title).to eq "Armed conflict in Northeastern Uganda: a population level study" end end @@ -257,45 +148,45 @@ let(:xml_file) { Rails.root.join "spec/fixtures/mets_files/eprint_xmlData_no_biblio_citation.xml" } it "parses the abstract correctly" do - expect(epdcx_parser.abstract).to eq "This is the abstract" + expect(subject.abstract).to eq "This is the abstract" end it "parses the date available correctly" do - expect(epdcx_parser.date_available).to eq "2018-08-06" + expect(subject.date_available).to eq "2018-08-06" end it "parses the date available (year) correctly" do - expect(epdcx_parser.date_available_year).to eq "2018" + expect(subject.date_available_year).to eq "2018" end context 'in creators arrays' do let(:expected_names) { ['Muhanguzi, Florence K','Mootz, Jennifer J','Panko, Pavel'] } it "parses names correctly" do - expect(epdcx_parser.creators).to contain_exactly(*expected_names) + expect(subject.creators).to contain_exactly(*expected_names) end end it "parses the identfier correctly" do - expect(epdcx_parser.identifier).to eq "https://doi.org/10.1186/s13031-018-0173-x" + expect(subject.identifier).to eq "https://doi.org/10.1186/s13031-018-0173-x" end it "parses the identfier URI correctply" do - expect(epdcx_parser.identifier_uri).to eq "https://doi.org/10.1186/s13031-018-0173-x" + expect(subject.identifier_uri).to eq "https://doi.org/10.1186/s13031-018-0173-x" end it "parses the publisher correctly" do - expect(epdcx_parser.publisher).to eq "BioMed Central" + expect(subject.publisher).to eq "BioMed Central" end context 'in subjects arrays' do let(:expected_subjects) { ['Alcohol use','Armed conflict','Uganda'] } it "parses subjects correctly" do - expect(epdcx_parser.subjects).to contain_exactly(*expected_subjects) + expect(subject.subjects).to contain_exactly(*expected_subjects) end end it "parses the title correctly" do - expect(epdcx_parser.title).to eq "Armed conflict in Northeastern Uganda: a population level study" + expect(subject.title).to eq "Armed conflict in Northeastern Uganda: a population level study" end end end diff --git a/spec/sword/parsers/mets_parser_spec.rb b/spec/sword/parsers/mets_parser_spec.rb index 07d063c..974f304 100644 --- a/spec/sword/parsers/mets_parser_spec.rb +++ b/spec/sword/parsers/mets_parser_spec.rb @@ -3,26 +3,7 @@ require 'sword/parsers/mets_parser.rb' RSpec.describe Sword::Parsers::MetsParser do - context "API/interface" do - it 'has #parse method that takes file to parse' do - expect(subject).to respond_to(:parse).with(1).arguments - end - - it 'has #flocat_xlink_href attr_reader' do - expect(subject).to respond_to(:flocat_xlink_href) - end - - it 'has #agent_name attr_reader' do - expect(subject).to respond_to(:agent_name) - end - - it 'has #xmlData_as_nokogiri_xml_element attr_reader' do - expect(subject).to respond_to(:xmlData_as_nokogiri_xml_element) - end - end - context "In mets file containing expected elements" do - mets_file = Rails.root.join "spec/fixtures/mets_files/mets_with_expected_elements.xml" mets_parser = Sword::Parsers::MetsParser.new mets_parser.parse(mets_file) @@ -44,7 +25,6 @@ end context "In mets file containing only the element" do - mets_file = Rails.root.join "spec/fixtures/mets_files/empty_mets.xml" mets_parser = Sword::Parsers::MetsParser.new mets_parser.parse(mets_file) @@ -59,7 +39,6 @@ end context "In Proquest mets file containing only xmlData elements" do - mets_file = Rails.root.join "spec/fixtures/mets_files/proquest_etd_mets_actual_mets_file.xml" mets_parser = Sword::Parsers::MetsParser.new mets_parser.parse(mets_file) diff --git a/spec/sword/parsers/mods_parser_spec.rb b/spec/sword/parsers/mods_parser_spec.rb index c4834bb..72dccce 100644 --- a/spec/sword/parsers/mods_parser_spec.rb +++ b/spec/sword/parsers/mods_parser_spec.rb @@ -15,67 +15,6 @@ end end - ########################################## API/interface - describe 'API/interface' do - context 'has attr_accessor for instance var' do - it 'access_condition_use_and_reproduction_license' do - expect(subject).to respond_to(:access_condition_use_and_reproduction_license_uri) - expect(subject).to respond_to(:access_condition_use_and_reproduction_license_uri=) - end - - it 'access_condition_use_and_reproduction_rights' do - expect(subject).to respond_to(:access_condition_use_and_reproduction_rights_status_uri) - expect(subject).to respond_to(:access_condition_use_and_reproduction_rights_status_uri=) - end - - it 'abstract' do - expect(subject).to respond_to(:abstract) - expect(subject).to respond_to(:abstract=) - end - - it 'date_issued_start' do - expect(subject).to respond_to(:date_issued_start) - expect(subject).to respond_to(:date_issued_start=) - end - - it 'identifier_doi' do - expect(subject).to respond_to(:identifier_doi) - expect(subject).to respond_to(:identifier_doi=) - end - - it 'identifier_uri' do - expect(subject).to respond_to(:identifier_uri) - expect(subject).to respond_to(:identifier_uri=) - end - - it 'note_internal' do - expect(subject).to respond_to(:note_internal) - expect(subject).to respond_to(:note_internal=) - end - - it 'names' do - expect(subject).to respond_to(:names) - expect(subject).to respond_to(:names=) - end - - it 'record_info_note' do - expect(subject).to respond_to(:record_info_note) - expect(subject).to respond_to(:record_info_note=) - end - - it 'title' do - expect(subject).to respond_to(:title) - expect(subject).to respond_to(:title=) - end - end - - context ' has the following instance method:' do - it '#parse method that takes file to parse' do - expect(subject).to respond_to(:parse).with(1).arguments - end - end - end - context "In mets file containing expected elements" do mods_parser = Sword::Parsers::ModsParser.new mets_file = Rails.root.join "spec/fixtures/mets_files/mods_mets.xml" diff --git a/spec/sword/parsers/proquest_etd_parser_spec.rb b/spec/sword/parsers/proquest_etd_parser_spec.rb index 8428f4b..7ba8ccd 100644 --- a/spec/sword/parsers/proquest_etd_parser_spec.rb +++ b/spec/sword/parsers/proquest_etd_parser_spec.rb @@ -17,91 +17,6 @@ end end - ########################################## API/interface - describe 'API/interface' do - context 'has attr_accessor for instance var' do - it 'abstract' do - expect(subject).to respond_to(:abstract) - expect(subject).to respond_to(:abstract=) - end - - it 'date_conferred' do - expect(subject).to respond_to(:date_conferred) - expect(subject).to respond_to(:date_conferred=) - end - - # Conforms to ProQuest list of degree acronyms - it 'degree' do - expect(subject).to respond_to(:degree) - expect(subject).to respond_to(:degree=) - end - - # Code to figure out the embargo date - it 'embargo_code' do - expect(subject).to respond_to(:embargo_code) - expect(subject).to respond_to(:embargo_code=) - end - - # Embargo release date, which is when the dissertation can be released. This date is derived, - # depending on the embargo code, on various other dates in the ProQuest metadata. See the - # definition of the calculate_embargo_release_date instance method for details - it 'embargo_release_date' do - expect(subject).to respond_to(:embargo_release_date) - expect(subject).to respond_to(:embargo_release_date=) - end - - # Department name within the institution - it 'institution_department_name' do - expect(subject).to respond_to(:institution_department_name) - expect(subject).to respond_to(:institution_department_name=) - end - - # the name of the degree granting institution - it 'institution_name' do - expect(subject).to respond_to(:institution_name) - expect(subject).to respond_to(:institution_name=) - end - - # PQ-assigned school code (I assume PQ means ProQuest) - it 'institution_school_code' do - expect(subject).to respond_to(:institution_school_code) - expect(subject).to respond_to(:institution_school_code=) - end - - it 'names' do - expect(subject).to respond_to(:names) - expect(subject).to respond_to(:names=) - end - - it 'subjects' do - expect(subject).to respond_to(:subjects) - expect(subject).to respond_to(:subjects=) - end - - it 'title' do - expect(subject).to respond_to(:title) - expect(subject).to respond_to(:title=) - end - end - - context ' has the following instance method:' do - it '#parse method that takes file to parse' do - expect(subject).to respond_to(:parse).with(1).arguments - end - - it '#parse_subjects ' do - expect(subject).to respond_to(:parse_subjects).with(1).arguments - end - - # Following has info on calculating the embargo release date: - # https://support.proquest.com/#articledetail?id=kA0400000004JJCCA2&key=embargo&pcat=All__c&icat= - # The ETD mentioned at the top of this file also has info on the embargo date - it '#calculate_embargo_release_date ' do - expect(subject).to respond_to(:calculate_embargo_release_date).with(1).arguments - end - end - end - context "In mets file containing expected elements" do proquest_etd_parser = Sword::Parsers::ProquestEtdParser.new xml_file = Rails.root.join "spec/fixtures/mets_files/proquest_xmlData.xml"