diff --git a/lib/deepl/document_api.rb b/lib/deepl/document_api.rb index 5416329..738fde9 100644 --- a/lib/deepl/document_api.rb +++ b/lib/deepl/document_api.rb @@ -91,7 +91,7 @@ def download(document_handle, output_file) def translate_document(input_file, output_file, source_lang, target_lang, # rubocop:disable Metrics/MethodLength,Metrics/ParameterLists filename = nil, options = {}, additional_headers = {}) - raise IOError 'File already exists at output path' if File.exist?(output_file) + raise IOError.new('File already exists at output path') if File.exist?(output_file) begin handle = upload(input_file, source_lang, target_lang, filename, options, diff --git a/spec/integration_tests/document_api_spec.rb b/spec/integration_tests/document_api_spec.rb index 4773992..17882bb 100644 --- a/spec/integration_tests/document_api_spec.rb +++ b/spec/integration_tests/document_api_spec.rb @@ -32,6 +32,19 @@ expect(example_document_translation(target_lang)).to eq(output_file_contents) end + it 'raises an IOError when the output file already exists' do + source_lang = default_lang_args[:source_lang] + target_lang = default_lang_args[:target_lang] + example_doc_path = example_document_path(source_lang) + + FileUtils.touch(output_document_path) + + expect do + DeepL.document.translate_document(example_doc_path, output_document_path, + source_lang, target_lang, File.basename(example_doc_path), + {}) + end.to raise_error(IOError) + end it 'Translates a document from a filepath without a filename' do File.unlink(output_document_path)