Skip to content

Commit

Permalink
Fix failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Novtopro committed Oct 29, 2024
1 parent db41db4 commit 0fce7f6
Show file tree
Hide file tree
Showing 38 changed files with 121 additions and 57 deletions.
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Metrics/MethodLength:
Metrics/AbcSize:
Enabled: false

Layout/LineLength:
Max: 120

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
SuggestExtensions: false
NewCops: enable
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "https://rubygems.org"
gemspec

gem "equivalent-xml"
gem "pry", "~> 0.12"
gem "pry"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.11"
gem "rubocop", "~> 1.58"
Expand Down
2 changes: 1 addition & 1 deletion lib/niso-jats.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require_relative "niso/jats"
require_relative "niso_jats"
10 changes: 0 additions & 10 deletions lib/niso/jats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,3 @@ module Jats
class Error < StandardError; end
end
end

require "zeitwerk"

loader = Zeitwerk::Loader.for_gem
loader.push_dir(__dir__, namespace: Niso)
loader.ignore("#{__dir__}/jats/module_includer.rb")
loader.setup
loader.eager_load

require_relative "jats/module_includer"
2 changes: 2 additions & 0 deletions lib/niso/jats/alt_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class AltTitle < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :alt_title_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/article_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class ArticleTitle < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :lang, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/attrib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Attrib < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/bold.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Bold < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Comment < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/def_head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class DefHead < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string

Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/fixed_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class FixedCase < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/italic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Italic < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/meta_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class MetaValue < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string

Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/monospace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Monospace < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/overline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Overline < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/roman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Roman < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/sc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Sc < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/see.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class See < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/see_also.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class SeeAlso < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/strike.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Strike < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/sub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Sub < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :arrange, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/subtitle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Subtitle < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/sup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Sup < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :arrange, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Term < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :rid, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/term_head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class TermHead < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string

Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Title < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/trans_subtitle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class TransSubtitle < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/trans_title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class TransTitle < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :content_type, :string
attribute :id, :string
Expand Down
2 changes: 2 additions & 0 deletions lib/niso/jats/underline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Niso
module Jats
class Underline < Lutaml::Model::Serializable
include BasicText

attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
Expand Down
5 changes: 5 additions & 0 deletions lib/niso_jats.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "zeitwerk"

loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
loader.ignore("#{__dir__}/niso-jats.rb")
loader.setup
1 change: 1 addition & 0 deletions niso-jats.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "lutaml-model"
spec.add_dependency "nokogiri"
spec.add_dependency "zeitwerk", "~> 2.6.18"
spec.metadata["rubygems_mfa_required"] = "true"
end
10 changes: 5 additions & 5 deletions spec/fixtures/bmj_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -906,16 +906,16 @@
<given-names>P</given-names>
</name>
</person-group>
<comment><ext-link ext-link-type="url" xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://www.sdo.lshtm.ac.uk/continuityofcare.htm"
>
www.sdo.lshtm.ac.uk/continuityofcare.htm</ext-link> (accessed 2 Jan 2002)</comment>
<source>Continuity of care: report of a scoping exercise for
the national co-ordinating centre for NHS Service Delivery and
Organisation R&#x0026;D (NCCSDO), Summer 2000</source>
<year iso-8601-date="2001">2001</year>
<publisher-loc>London</publisher-loc>
<publisher-name>NCCSDO</publisher-name>
<comment><ext-link ext-link-type="url" xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://www.sdo.lshtm.ac.uk/continuityofcare.htm"
>
www.sdo.lshtm.ac.uk/continuityofcare.htm</ext-link> (accessed 2 Jan 2002)</comment>
</element-citation>
</ref>

Expand Down Expand Up @@ -1065,4 +1065,4 @@
</fn>
</fn-group>
</back>
</article>
</article>
7 changes: 7 additions & 0 deletions spec/fixtures/element_citation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<element-citation publication-type="book" publication-format="web">
<comment>
<ext-link ext-link-type="url"
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sdo.lshtm.ac.uk/continuityofcare.htm">
www.sdo.lshtm.ac.uk/continuityofcare.htm
</ext-link> (accessed 2 Jan 2002)</comment>
</element-citation>
36 changes: 6 additions & 30 deletions spec/niso/jats/article_spec.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
# frozen_string_literal: true

RSpec.describe Niso::Jats::Article do
def file_contents(filename)
File.read(filename)
context "with bmj_sample.xml" do
let(:fixture) { file_fixture("bmj_sample.xml") }
it_behaves_like "a serializer"
end

glob_path = Pathname.new(__dir__)
.join("../../fixtures/*.xml")

Dir.glob(glob_path)[0..1].each do |filename|
fn = Pathname.new(filename).basename
xit "round-trips #{fn} with equivalent-xml" do
input = file_contents(Pathname.new(filename))
parsed = described_class.from_xml(input)
generated = parsed.to_xml(
pretty: true,
declaration: true,
encoding: "utf-8",
)

expect(generated).to be_equivalent_to(input)
end

it "round-trips #{fn} with xml-c14" do
input = file_contents(Pathname.new(filename))
parsed = described_class.from_xml(input)
generated = parsed.to_xml(
pretty: true,
declaration: true,
encoding: "utf-8",
)

expect(generated).to be_analogous_with(input)
end
context "with pnas_sample.xml" do
let(:fixture) { file_fixture("pnas_sample.xml") }
it_behaves_like "a serializer"
end
end
9 changes: 9 additions & 0 deletions spec/niso/jats/element_citation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

RSpec.describe Niso::Jats::ElementCitation do
context "with a element_citation.xml" do
let(:fixture) { file_fixture("element_citation.xml") }

it_behaves_like "a serializer"
end
end
13 changes: 4 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# frozen_string_literal: true

require "pry"
require "niso-jats"
require "xml-c14n"
require "equivalent-xml"
require "lutaml/model"
require "lutaml/model/xml_adapter/nokogiri_adapter"
require "lutaml/model/json_adapter/standard_json_adapter"

module TestHelper
def fixture(name)
Pathname.new(fixtures_path(name))
end

def fixtures_path(name)
File.join(__dir__, "fixtures", name)
end
Dir["spec/support/**/*.rb"].each do |it|
require File.expand_path(it)
end

RSpec.configure do |config|
config.include TestHelper
config.include Helper

# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
Expand Down
Loading

0 comments on commit 0fce7f6

Please sign in to comment.