specs/text_spec.rb in pdf-wrapper-0.3.1 vs specs/text_spec.rb in pdf-wrapper-0.3.2

- old
+ new

@@ -1,10 +1,10 @@ # coding: utf-8 require File.dirname(__FILE__) + '/spec_helper' -context "The PDF::Wrapper class" do +describe PDF::Wrapper do before(:each) { create_pdf } specify "should be able to permanantly change the font size" do @pdf.font_size 20 @@ -166,11 +166,12 @@ str = "James Healy" str2 = "James Healy is a Ruby dev that lives in Melbourne, Australia. His day job mostly involved Ruby on Rails." opts = {:font_size => 16, :font => "Sans Serif"} @pdf.text(str, opts) @pdf.text_width(str, opts).should eql(131) - @pdf.text_width(str2, opts).should eql(1106) + (@pdf.text_width(str2, opts) >= 1106).should be_true + (@pdf.text_width(str2, opts) <= 1107).should be_true end specify "should raise an exception if build_pango_layout is passed anything other than a string" do lambda { @pdf.build_pango_layout(10) }.should raise_error(ArgumentError) end @@ -242,8 +243,14 @@ end specify "should raise an error when an invalid wrapping technique is specified" do msg = "James Healy" lambda { @pdf.text msg, :wrap => :ponies }.should raise_error(ArgumentError) + end + + specify "should determine the largest font size possible that will fit some text in a cell" do + @pdf.__send__(:best_font_size, "Hello There", 34, 50, 5..9).should eql(9) + @pdf.__send__(:best_font_size, "<b>Hello There</b>", 34, 50, 5..9, :markup => :pango).should eql(8) + @pdf.__send__(:best_font_size, "Hello There", 5, 50, 5..9).should eql(5) end end