Skip to content

Commit

Permalink
harmonize error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Jun 18, 2024
1 parent 0e1e117 commit 04e1e0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/proformaxml/services/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(zip:, expected_version: nil)
@expected_version = expected_version

xml = filestring_from_zip('task.xml')
raise PreImportValidationError if xml.nil?
raise PreImportValidationError.new(['no task_xml found']) if xml.blank?

@doc = Nokogiri::XML(xml, &:noblanks)
@task = Task.new
Expand All @@ -28,8 +28,7 @@ def proforma_namespace

def perform
errors = validate

raise PreImportValidationError.new(errors) if errors.any?
raise PreImportValidationError.new(errors.map(&:message)) if errors.any?

@pro_ns = proforma_namespace
@task_node = @doc.xpath("/#{@pro_ns}:task")
Expand Down
13 changes: 12 additions & 1 deletion spec/proformaxml/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
expect(importer.instance_variable_get(:@expected_version)).to eql '2.0'
end
end

context 'when zip-file does not contain task.xml' do
before do
zip_file.write('Foobar')
zip_file.rewind
end

it 'raises correct error' do
expect { importer }.to raise_error(ProformaXML::PreImportValidationError, /no task_xml found/)
end
end
end

describe '#perform' do
Expand Down Expand Up @@ -242,7 +253,7 @@
let(:export_version) { '2.1' }

it 'raises an error' do
expect { perform }.to raise_error ProformaXML::PreImportValidationError
expect { perform }.to raise_error ProformaXML::PreImportValidationError, /No matching global declaration available for the validation root/
end
end
end
Expand Down

0 comments on commit 04e1e0b

Please sign in to comment.