spec/outline_spec.rb in prawn-1.0.0.rc1 vs spec/outline_spec.rb in prawn-1.0.0.rc2
- old
+ new
@@ -34,21 +34,21 @@
before(:each) do
render_and_find_objects
end
it "should create a root outline dictionary item" do
- assert_not_nil @outline_root
+ @outline_root.should_not be_nil
end
it "should set the first and last top items of the root outline dictionary item" do
referenced_object(@outline_root[:First]).should == @section_1
referenced_object(@outline_root[:Last]).should == @section_1
end
describe "#create_outline_item" do
it "should create outline items for each section and page" do
- [@section_1, @page_1, @page_2].each {|item| assert_not_nil item}
+ [@section_1, @page_1, @page_2].each {|item| item.should_not be_nil}
end
end
describe "#set_relations, #set_variables_for_block, and #reset_parent" do
it "should link sibling items" do
@@ -68,11 +68,11 @@
describe "#increase_count" do
it "should add the count of all descendant items" do
@outline_root[:Count].should == 3
- @section_1[:Count].should.abs == 2
+ @section_1[:Count].abs.should == 2
@page_1[:Count].should == 0
@page_2[:Count].should == 0
end
end
@@ -98,11 +98,11 @@
end
render_and_find_objects
end
it "should add new outline items to document" do
- [@section_2, @page_3].each { |item| assert_not_nil item}
+ [@section_2, @page_3].each { |item| item.should_not be_nil}
end
it "should reset the last items for root outline dictionary" do
referenced_object(@outline_root[:First]).should == @section_1
referenced_object(@outline_root[:Last]).should == @section_2
@@ -137,11 +137,11 @@
end
render_and_find_objects
end
it "should add new outline items to document" do
- [@subsection, @added_page_3].each { |item| assert_not_nil item}
+ [@subsection, @added_page_3].each { |item| item.should_not be_nil}
end
it "should reset the last item for parent item dictionary" do
referenced_object(@section_1[:First]).should == @page_1
referenced_object(@section_1[:Last]).should == @subsection
@@ -184,11 +184,11 @@
end
render_and_find_objects
end
it "should add new outline items to document" do
- [@subsection, @added_page_3].each { |item| assert_not_nil item}
+ [@subsection, @added_page_3].each { |item| item.should_not be_nil}
end
it "should reset the first item for parent item dictionary" do
referenced_object(@section_1[:First]).should == @subsection
referenced_object(@section_1[:Last]).should == @page_2
@@ -215,21 +215,21 @@
end
end
it "should require an existing title" do
- assert_raise Prawn::Errors::UnknownOutlineTitle do
+ lambda do
@pdf.go_to_page 1
@pdf.start_new_page
@pdf.text "Inserted Page"
@pdf.outline.update do
add_subsection_to 'Wrong page' do
page page_number, :title => "Inserted Page"
end
end
render_and_find_objects
- end
+ end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
end
end
describe "#outline.insert_section_after" do
describe "inserting in the middle of another section" do
@@ -244,17 +244,17 @@
end
end
it "should insert new outline items to document" do
render_and_find_objects
- assert_not_nil @inserted_page
+ @inserted_page.should_not be_nil
end
it "should adjust the count of all ancestors" do
render_and_find_objects
@outline_root[:Count].should == 4
- @section_1[:Count].should.abs == 3
+ @section_1[:Count].abs.should == 3
end
describe "#adjust_relations" do
it "should reset the sibling relations of adjoining items to inserted item" do
@@ -315,11 +315,11 @@
it "should reset the sibling relations of adjoining item to inserted item" do
referenced_object(@page_2[:Next]).should == @inserted_page
end
it "should set the sibling relation of added item to adjoining items" do
- assert_nil referenced_object(@inserted_page[:Next])
+ referenced_object(@inserted_page[:Next]).should be_nil
referenced_object(@inserted_page[:Prev]).should == @page_2
end
it "should adjust the last relation of parent item" do
referenced_object(@section_1[:Last]).should == @inserted_page
@@ -327,40 +327,40 @@
end
end
it "should require an existing title" do
- assert_raise Prawn::Errors::UnknownOutlineTitle do
+ lambda do
@pdf.go_to_page 1
@pdf.start_new_page
@pdf.text "Inserted Page"
@pdf.outline.update do
insert_section_after 'Wrong page' do
page :destination => page_number, :title => "Inserted Page"
end
end
render_and_find_objects
- end
+ end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
end
end
describe "#page" do
it "should require a title option to be set" do
- assert_raise Prawn::Errors::RequiredOption do
+ lambda do
@pdf = Prawn::Document.new() do
text "Page 1. This is the first Chapter. "
outline.define do
page :destination => 1, :title => nil
end
end
- end
+ end.should raise_error(Prawn::Errors::RequiredOption)
end
end
end
-context "foreign character encoding" do
+describe "foreign character encoding" do
before(:each) do
pdf = Prawn::Document.new() do
outline.define do
section 'La pomme croquée', :destination => 1, :closed => true
end
@@ -368,10 +368,28 @@
@hash = PDF::Reader::ObjectHash.new(StringIO.new(pdf.render, 'r+'))
end
it "should handle other encodings for the title" do
object = find_by_title('La pomme croquée')
- object.should.not == nil
+ object.should_not == nil
+ end
+end
+
+describe "with optimize_objects option" do
+ before(:each) do
+ @pdf = Prawn::Document.new(:optimize_objects => true) do
+ outline.define do
+ section 'Chapter 1', :destination => 1, :closed => true do
+ page :destination => 1, :title => 'Page 1'
+ end
+ end
+ end
+ render_and_find_objects
+ end
+
+ it "should generate an outline" do
+ @section_1.should_not be_nil
+ @page_1.should_not be_nil
end
end
def render_and_find_objects
output = StringIO.new(@pdf.render, 'r+')