require 'spec_helper' describe Fontana::Font do def eot_md5 @eot_md5 ||= Digest::MD5.file(font_assets('Consola Mono/ConsolaMono.eot')) end def otf_md5 @otf_md5 ||= Digest::MD5.file(font_assets('Consola Mono/ConsolaMono.otf')) end def svg_md5 @svg_md5 ||= Digest::MD5.file(font_assets('Consola Mono/ConsolaMono.svg')) end def ttf_md5 @ttf_md5 ||= Digest::MD5.file(font_assets('Consola Mono/ConsolaMono.ttf')) end def woff_md5 @woff_md5 ||= Digest::MD5.file(font_assets('Consola Mono/ConsolaMono.woff')) end context '#initialize' do it 'should require the path to font file' do lambda { Fontana::Font.new() }.should raise_error(ArgumentError) end it 'will assume a string is a path to file and attempt to open it' do lambda { Fontana::Font.new('/bad/file/path') }.should raise_error(Errno::ENOENT) end end pending 'font conversions' do [ :eot, :otf, :svg, :ttf, :woff ].each do |file_extension| context "with a #{file_extension} as an original font #to_eot" do it 'will return a string representing the embedded open type font' do font = Fontana::Font.new(font_assets("Consola Mono/ConsolaMono.#{file_extension}")) Digest::MD5.hexdigest(font.to_eot).should == eot_md5.to_s end end context "with a #{file_extension} as an original font #to_otf" do it 'will return a string representing the open type font' do pending 'No utility found to convert from eot => otf' if file_extension == :eot font = Fontana::Font.new(font_assets("Consola Mono/ConsolaMono.#{file_extension}")) Digest::MD5.hexdigest(font.to_otf).should == otf_md5.to_s end end context "with a #{file_extension} as an original font #to_svg" do it 'will return a string representing the scalable vector graphic font' do pending 'No utility found to convert from eot => svg' if file_extension == :eot font = Fontana::Font.new(font_assets("Consola Mono/ConsolaMono.#{file_extension}")) Digest::MD5.hexdigest(font.to_svg).should == svg_md5.to_s end end context "with a #{file_extension} as an original font #to_ttf" do it 'will return a string representing the true type font' do pending 'No utility found to convert from eot => ttf' if file_extension == :eot font = Fontana::Font.new(font_assets("Consola Mono/ConsolaMono.#{file_extension}")) Digest::MD5.hexdigest(font.to_ttf).should == ttf_md5.to_s end end context "with a #{file_extension} as an original font #to_woff" do it 'will return a string representing the web open font format font' do pending 'No utility found to convert from eot => woff' if file_extension == :eot font = Fontana::Font.new(font_assets("Consola Mono/ConsolaMono.#{file_extension}")) Digest::MD5.hexdigest(font.to_woff).should == woff_md5.to_s end end end end end