Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinTanasoiu committed Aug 23, 2023
1 parent e63b546 commit 9d9df1a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions spec/parsers/json_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ 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)

expect(parsed).to be_nil
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)

Expand Down
2 changes: 1 addition & 1 deletion spec/parsers/m3u_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/parsers/ogg_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 22 additions & 26 deletions spec/remote_fetching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d9df1a

Please sign in to comment.