diff --git a/README.md b/README.md index 01c44455..9c9e8718 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ Unless specified otherwise in this section the fixture files are MIT licensed an - NEF examples are downloaded from http://www.rawsamples.ch/ and are Creative Common Licensed. ### OGG -- `hi.ogg`, `vorbis.ogg`, `with_confusing_magic_string.ogg`, `with_garbage_at_the_end.ogg` have been generated by the project contributors +- `hi.ogg`, `vorbis.ogg`, `with_confusing_magic_string.ogg`, `invalid_with_garbage_at_the_end.ogg` have been generated by the project contributors ### PDF - PDF 2.0 files downloaded from the [PDF Association public Github repository](https://github.com/pdf-association/pdf20examples). These files are licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. diff --git a/spec/fixtures/JSON/lorem_ipsum.json b/spec/fixtures/JSON/invalid_lorem_ipsum.json similarity index 100% rename from spec/fixtures/JSON/lorem_ipsum.json rename to spec/fixtures/JSON/invalid_lorem_ipsum.json diff --git a/spec/fixtures/JSON/malformed.json b/spec/fixtures/JSON/invalid_malformed.json similarity index 100% rename from spec/fixtures/JSON/malformed.json rename to spec/fixtures/JSON/invalid_malformed.json diff --git a/spec/fixtures/M3U/plain_text.m3u b/spec/fixtures/M3U/invalid_plain_text.m3u similarity index 100% rename from spec/fixtures/M3U/plain_text.m3u rename to spec/fixtures/M3U/invalid_plain_text.m3u diff --git a/spec/fixtures/Ogg/with_garbage_at_the_end.ogg b/spec/fixtures/Ogg/invalid_with_garbage_at_the_end.ogg similarity index 100% rename from spec/fixtures/Ogg/with_garbage_at_the_end.ogg rename to spec/fixtures/Ogg/invalid_with_garbage_at_the_end.ogg diff --git a/spec/parsers/json_parser_spec.rb b/spec/parsers/json_parser_spec.rb index 7c32edcd..ab7c8a1a 100644 --- a/spec/parsers/json_parser_spec.rb +++ b/spec/parsers/json_parser_spec.rb @@ -99,7 +99,7 @@ def file_size(file_name) describe 'When reading objects invalid JSON files' do it "rejects files with corrupted JSON data" do - io = load_file 'malformed.json' + io = load_file 'invalid_malformed.json' parsed = subject.call(io) @@ -107,7 +107,7 @@ def file_size(file_name) end it "rejects invalid files early without reading the whole content" do - io = load_file 'lorem_ipsum.json' + io = load_file 'invalid_lorem_ipsum.json' parsed = subject.call(io) diff --git a/spec/parsers/m3u_parser_spec.rb b/spec/parsers/m3u_parser_spec.rb index 3614a2dc..40f7b81b 100644 --- a/spec/parsers/m3u_parser_spec.rb +++ b/spec/parsers/m3u_parser_spec.rb @@ -11,7 +11,7 @@ end describe 'an m3u file with missing header' do - let(:m3u_file) { 'plain_text.m3u' } + let(:m3u_file) { 'invalid_plain_text.m3u' } it 'does not parse the file successfully' do expect(parsed_m3u).to be_nil diff --git a/spec/parsers/ogg_parser_spec.rb b/spec/parsers/ogg_parser_spec.rb index 6bbe9fcf..1c9e9c7a 100644 --- a/spec/parsers/ogg_parser_spec.rb +++ b/spec/parsers/ogg_parser_spec.rb @@ -13,7 +13,7 @@ end it 'skips a file if it contains more than MAX_POSSIBLE_OGG_PAGE_SIZE bytes of garbage at the end' do - parse_result = subject.call(File.open(__dir__ + '/../fixtures/Ogg/with_garbage_at_the_end.ogg', 'rb')) + parse_result = subject.call(File.open(__dir__ + '/../fixtures/Ogg/invalid_with_garbage_at_the_end.ogg', 'rb')) expect(parse_result).to be_nil end diff --git a/spec/remote_fetching_spec.rb b/spec/remote_fetching_spec.rb index 86662a1e..ae827d61 100644 --- a/spec/remote_fetching_spec.rb +++ b/spec/remote_fetching_spec.rb @@ -116,33 +116,29 @@ end describe "correctly parses files over HTTP without filename hint" do - nature_fixture_dirs = { - document: ['PDF'], - audio: ['AAC', 'AIFF', 'FLAC', 'MP3', 'WAV'], - video: ['MOV', 'MP4'], - image: ['ARW', 'CR2', 'CR3', 'GIF', 'JPG', 'NEF', 'PNG', 'PSD', 'RW2', 'TIF', 'WEBP'] - } - nature_fixture_dirs.each { |nature, dirs| - dirs.each do |file_type_dir| - Dir.glob(fixtures_dir + "/#{file_type_dir}/*.*").each do |file_path| - file_name = File.basename(file_path) - next if file_name.include? "invalid" - - expected_format = file_type_dir.downcase.to_sym - if file_type_dir == 'HEIF' - expected_format = File.extname(file_name).delete('.').downcase.to_sym - end - - it "parses #{file_type_dir} file: #{file_name}" do - url = "http://localhost:9399/#{file_type_dir}/#{file_name}?some_param=test".gsub(' ', '%20') - file_information = FormatParser.parse_http(url) - expect(file_information).not_to be_nil - expect(file_information.nature).to eq(nature) - expect(file_information.format).to eq(expected_format) - end - end + Dir.glob(fixtures_dir + '/**/*.*').sort.each do |fixture_path| + file_name = File.basename(fixture_path) + next if file_name.include? "invalid" + + file_type_dir = fixture_path.delete_prefix(fixtures_dir).delete_suffix(file_name) + file_type_dir.delete_prefix!('/').delete_suffix!('/') + next if file_type_dir.empty? + + # skipping this one because it's a special case + next if file_name == "arch_many_entries.zip" + + it "parses #{file_type_dir} file: #{file_name}" do + url = "http://localhost:9399/#{file_type_dir}/#{file_name}?some_param=test".gsub(' ', '%20') + result_with_hint = FormatParser.parse_http(url, filename_hint: file_name) + result_no_hint = FormatParser.parse_http(url) + + expect(result_with_hint).not_to be_nil + expect(result_no_hint).not_to be_nil + + expect(result_no_hint.nature).to eq(result_with_hint.nature) + expect(result_no_hint.format).to eq(result_with_hint.format) end - } + end end describe 'when parsing remote fixtures' do