/
extractor_spec.cr
56 lines (44 loc) · 1.56 KB
/
extractor_spec.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "./spec_helper"
require "yaml"
Spectator.describe Extractor do
it "should have a VERSION constant" do
expect(Extractor::VERSION).not_to be_empty
end
describe ".abort!" do
it "should raise MetadataProcessor::Abort" do
expect { subject.abort! }.to raise_error(Extractor::MetadataProcessor::Abort)
end
end
let(fixtures_dir) { File.expand_path("spec/fixtures") }
let(file) { File.join(fixtures_dir,"image.jpg") }
let(data) do
File.open(file,"rb") do |file|
String.build(file.size) do |io|
IO.copy(file,io)
end
end
end
alias ArgsTuple = Tuple(String, Extractor::MetaType, Extractor::MetaFormat, String, Extractor::MetaData)
let(metadata_file) { File.join(fixtures_dir,"image-metadata.yml") }
let(expected_metadata) do
Array(ArgsTuple).from_yaml(File.read(metadata_file))
end
describe ".extract" do
it "should extract metadata from a String" do
findings = [] of ArgsTuple
subject.extract(data) do |plugin_name,type,format,mime_type,data|
findings << {plugin_name, type, format, mime_type, data}
end
expect(findings & expected_metadata).to match_array(expected_metadata).in_any_order
end
end
describe ".extract_from" do
it "should extract metadata from a file" do
findings = [] of ArgsTuple
subject.extract(data) do |plugin_name,type,format,mime_type,data|
findings << {plugin_name, type, format, mime_type, data}
end
expect(findings & expected_metadata).to match_array(expected_metadata).in_any_order
end
end
end