X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=spec%2Fspec_helper.rb;h=bbfe1a5ff26739e6ad08d05af6c9be93c212ff0c;hb=9188f342f67f399dbb7857dd1970ab44a8c24138;hp=1ee0b39da6c1c7fedc964fe8b3527b67f7504c63;hpb=5c336b4f7017fb121fc2cbe2a02c1fa56986b560;p=swftools.git diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1ee0b39..bbfe1a5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -53,7 +53,8 @@ class Area @rgb.minmax != [@rgb[0],@rgb[0]] or raise AreaError.new(self,"is plain colored") end def should_contain_text(text) - @file.get_text(@x1,@y1,@x2,@y2) == text or raise AreaError.new(self, "doesn't contain text #{text}") + text2 = @file.get_text(@x1,@y1,@x2,@y2) + text2 == text or raise AreaError.new(self, "doesn't contain text \"#{text}\" (found: \"#{text2}\")") end def to_s "(#{@x1},#{@y1},#{@x2},#{@y2})" @@ -91,6 +92,14 @@ class Pixel "(#{@x},#{@y})" end end + +$tempfiles = [] +Kernel.at_exit do + $tempfiles.each do |file| + `rm -f #{file}` + end +end + class DocFile def initialize(filename, page) @filename = filename @@ -99,6 +108,7 @@ class DocFile def convert() return if @swfname @swfname = @filename.gsub(/.pdf$/i,"")+".swf" + $tempfiles += [@swfname] `pdfinfo #{@filename}` =~ /Page size:\s*([0-9]+) x ([0-9]+) pts/ width,height = $1,$2 dpi = (72.0 * 612 / width.to_i).to_i @@ -115,15 +125,14 @@ class DocFile raise ConversionFailed.new(output,@pngname) unless File.exists?(@pngname) @img = Magick::Image.read(@pngname).first ensure - `rm -f #{@swfname}` `rm -f #{@pngname}` end end def get_text(x1,y1,x2,y2) self.convert() - puts "swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}" - puts `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}` - `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}` + #puts "swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}" + #puts `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}` + `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`.chomp end def get_area(x1,y1,x2,y2) self.render()