require 'spec_helper' describe Bolognese::Metadata, vcr: true do let(:input) { "https://blog.datacite.org/eating-your-own-dog-food/" } let(:fixture_path) { "spec/fixtures/" } subject { Bolognese::Metadata.new(input: input) } context "get ris raw" do it "BlogPosting" do input = fixture_path + 'schema_org.json' subject = Bolognese::Metadata.new(input: input) expect(subject.raw).to eq(IO.read(input)) end end context "get schema_org metadata" do it "BlogPosting" do expect(subject.valid?).to be true expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg") expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food") expect(subject.type).to eq("BlogPosting") expect(subject.author).to eq("type"=>"Person", "id"=>"http://orcid.org/0000-0003-1419-2405", "name"=>"Martin Fenner", "givenName"=>"Martin", "familyName"=>"Fenner") expect(subject.title).to eq("Eating your own Dog Food") expect(subject.alternate_name).to eq("MS-49-3632-5083") expect(subject.description["text"]).to start_with("Eating your own dog food") expect(subject.keywords).to eq("datacite, doi, metadata, featured") expect(subject.date_published).to eq("2016-12-20") expect(subject.date_modified).to eq("2016-12-20") expect(subject.is_part_of).to eq("id"=>"https://doi.org/10.5438/0000-00ss", "type"=>"Blog", "title"=>"DataCite Blog") expect(subject.references).to eq([{"id"=>"https://doi.org/10.5438/0012", "type"=>"CreativeWork"}, {"id"=>"https://doi.org/10.5438/55e5-t5c0", "type"=>"CreativeWork"}]) expect(subject.publisher).to eq("DataCite") end it "not found error" do input = "https://doi.org/10.5438/4K3M-NYVGx" subject = Bolognese::Metadata.new(input: input, from: "schema_org") expect(subject.id).to be_nil expect(subject.exists?).to be false end end context "get schema_org metadata as string" do it "BlogPosting" do input = fixture_path + 'schema_org.json' subject = Bolognese::Metadata.new(input: input) expect(subject.id).to eq("https://doi.org/10.5438/4k3m-nyvg") expect(subject.url).to eq("https://blog.datacite.org/eating-your-own-dog-food") expect(subject.type).to eq("BlogPosting") expect(subject.author).to eq("type"=>"Person", "id"=>"http://orcid.org/0000-0003-1419-2405", "name"=>"Martin Fenner", "givenName"=>"Martin", "familyName"=>"Fenner") expect(subject.title).to eq("Eating your own Dog Food") expect(subject.alternate_name).to eq("MS-49-3632-5083") expect(subject.description["text"]).to start_with("Eating your own dog food") expect(subject.keywords).to eq("datacite, doi, metadata, featured") expect(subject.date_published).to eq("2016-12-20") expect(subject.date_modified).to eq("2016-12-20") expect(subject.is_part_of).to eq("id"=>"https://doi.org/10.5438/0000-00ss", "type"=>"Blog", "title"=>"DataCite Blog") expect(subject.references).to eq([{"id"=>"https://doi.org/10.5438/0012", "type"=>"CreativeWork"}, {"id"=>"https://doi.org/10.5438/55e5-t5c0", "type"=>"CreativeWork"}]) expect(subject.publisher).to eq("DataCite") end end end