diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/prawn-table.gemspec b/prawn-table.gemspec index d4cb79b..8e77014 100644 --- a/prawn-table.gemspec +++ b/prawn-table.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.add_dependency('prawn', '>= 1.3.0', '< 3.0.0') spec.add_development_dependency('pdf-inspector', '~> 1.1.0') spec.add_development_dependency('yard') - spec.add_development_dependency('rspec', '2.14.1') + spec.add_development_dependency('rspec', '~> 3.0') spec.add_development_dependency('mocha') spec.add_development_dependency('rake') spec.add_development_dependency('simplecov') diff --git a/spec/cell_spec.rb b/spec/cell_spec.rb index 99deed2..b3657be 100644 --- a/spec/cell_spec.rb +++ b/spec/cell_spec.rb @@ -27,19 +27,19 @@ def cell(options={}) end it "should return a Cell" do - @pdf.cell(:content => "text").should be_a_kind_of Prawn::Table::Cell + expect(@pdf.cell(:content => "text")).to be_a_kind_of Prawn::Table::Cell end it "accepts :content => nil in a hash" do - @pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text) - @pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text) + expect(@pdf.cell(:content => nil)).to be_a_kind_of(Prawn::Table::Cell::Text) + expect(@pdf.make_cell(:content => nil)).to be_a_kind_of(Prawn::Table::Cell::Text) end it "should convert nil, Numeric, and Date values to strings" do [nil, 123, 123.45, Date.today].each do |value| c = @pdf.cell(:content => value) - c.should be_a_kind_of Prawn::Table::Cell::Text - c.content.should == value.to_s + expect(c).to be_a_kind_of Prawn::Table::Cell::Text + expect(c.content).to eq value.to_s end end @@ -47,9 +47,9 @@ def cell(options={}) # used for table([[{:text => "...", :font_style => :bold, ...}, ...]]) c = Prawn::Table::Cell.make(@pdf, {:content => 'hello', :font_style => :bold}) - c.should be_a_kind_of Prawn::Table::Cell::Text - c.content.should == "hello" - c.font.name.should == 'Helvetica-Bold' + expect(c).to be_a_kind_of Prawn::Table::Cell::Text + expect(c.content).to eq "hello" + expect(c.font.name).to eq 'Helvetica-Bold' end it "should draw text at the given point plus padding, with the given " + @@ -73,7 +73,7 @@ def cell(options={}) end it "should return a Cell" do - @pdf.make_cell("text", :size => 7).should be_a_kind_of Prawn::Table::Cell + expect(@pdf.make_cell("text", :size => 7)).to be_a_kind_of Prawn::Table::Cell end end @@ -101,17 +101,17 @@ def cell(options={}) it "should be calculated for text" do c = cell(:content => "text") - c.width.should == @pdf.width_of("text") + c.padding[1] + c.padding[3] + expect(c.width).to eq @pdf.width_of("text") + c.padding[1] + c.padding[3] end it "should be overridden by manual :width" do c = cell(:content => "text", :width => 400) - c.width.should == 400 + expect(c.width).to eq 400 end it "should incorporate padding when specified" do c = cell(:content => "text", :padding => [1, 2, 3, 4]) - c.width.should be_within(0.01).of(@pdf.width_of("text") + 6) + expect(c.width).to be_within(0.01).of(@pdf.width_of("text") + 6) end it "should allow width to be reset after it has been calculated" do @@ -119,31 +119,30 @@ def cell(options={}) c = cell(:content => "text") c.width c.width = 400 - c.width.should == 400 + expect(c.width).to eq 400 end it "should return proper width with size set" do text = "text " * 4 c = cell(:content => text, :size => 7) - c.width.should == - @pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3] + expect(c.width).to eq @pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3] end it "content_width should exclude padding" do c = cell(:content => "text", :padding => 10) - c.content_width.should == @pdf.width_of("text") + expect(c.content_width).to eq @pdf.width_of("text") end it "content_width should exclude padding even with manual :width" do c = cell(:content => "text", :padding => 10, :width => 400) - c.content_width.should be_within(0.01).of(380) + expect(c.content_width).to be_within(0.01).of(380) end it "should have a reasonable minimum width that can fit @content" do c = cell(:content => "text", :padding => 10) min_content_width = c.min_width - c.padding[1] - c.padding[3] - @pdf.height_of("text", :width => min_content_width).should be < + expect(@pdf.height_of("text", :width => min_content_width)).to be < (5 * @pdf.height_of("text")) end @@ -152,14 +151,14 @@ def cell(options={}) c.padding = 0 # Make sure we use the new value of padding in calculating min_width - c.min_width.should be < 100 + expect(c.min_width).to be < 100 end it "should defer min_width's evaluation of size" do c = cell(:content => "text", :size => 50) c.size = 8 c.padding = 0 - c.min_width.should be < 10 + expect(c.min_width).to be < 10 end end @@ -169,19 +168,20 @@ def cell(options={}) it "should be calculated for text" do c = cell(:content => "text") - c.height.should == + expect(c.height).to eq( @pdf.height_of("text", :width => @pdf.width_of("text")) + c.padding[0] + c.padding[3] + ) end it "should be overridden by manual :height" do c = cell(:content => "text", :height => 400) - c.height.should == 400 + expect(c.height).to eq 400 end it "should incorporate :padding when specified" do c = cell(:content => "text", :padding => [1, 2, 3, 4]) - c.height.should be_within(0.01).of(1 + 3 + + expect(c.height).to be_within(0.01).of(1 + 3 + @pdf.height_of("text", :width => @pdf.width_of("text"))) end @@ -190,13 +190,13 @@ def cell(options={}) c = cell(:content => "text") c.height c.height = 400 - c.height.should == 400 + expect(c.height).to eq 400 end it "should return proper height for blocks of text" do content = "words " * 10 c = cell(:content => content, :width => 100) - c.height.should == @pdf.height_of(content, :width => 100) + + expect(c.height).to eq @pdf.height_of(content, :width => 100) + c.padding[0] + c.padding[2] end @@ -209,17 +209,17 @@ def cell(options={}) correct_content_height = @pdf.height_of(content, :width => 100) end - c.height.should == correct_content_height + c.padding[0] + c.padding[2] + expect(c.height).to eq correct_content_height + c.padding[0] + c.padding[2] end it "content_height should exclude padding" do c = cell(:content => "text", :padding => 10) - c.content_height.should == @pdf.height_of("text") + expect(c.content_height).to eq @pdf.height_of("text") end it "content_height should exclude padding even with manual :height" do c = cell(:content => "text", :padding => 10, :height => 400) - c.content_height.should be_within(0.01).of(380) + expect(c.content_height).to be_within(0.01).of(380) end end @@ -228,33 +228,33 @@ def cell(options={}) it "should default to zero" do c = cell(:content => "text") - c.padding.should == [5, 5, 5, 5] + expect(c.padding).to eq [5, 5, 5, 5] end it "should accept a numeric value, setting all padding" do c = cell(:content => "text", :padding => 10) - c.padding.should == [10, 10, 10, 10] + expect(c.padding).to eq [10, 10, 10, 10] end it "should accept [v,h]" do c = cell(:content => "text", :padding => [20, 30]) - c.padding.should == [20, 30, 20, 30] + expect(c.padding).to eq [20, 30, 20, 30] end it "should accept [t,h,b]" do c = cell(:content => "text", :padding => [10, 20, 30]) - c.padding.should == [10, 20, 30, 20] + expect(c.padding).to eq [10, 20, 30, 20] end it "should accept [t,l,b,r]" do c = cell(:content => "text", :padding => [10, 20, 30, 40]) - c.padding.should == [10, 20, 30, 40] + expect(c.padding).to eq [10, 20, 30, 40] end it "should reject other formats" do - lambda{ + expect { cell(:content => "text", :padding => [10]) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -268,10 +268,10 @@ def cell(options={}) @pdf.stubs(:fill_color) @pdf.expects(:fill_color).with('123456') @pdf.expects(:fill_rectangle).checking do |(x, y), w, h| - x.should be_within(0.01).of(0) - y.should be_within(0.01).of(@pdf.cursor) - w.should be_within(0.01).of(29.344) - h.should be_within(0.01).of(23.872) + expect(x).to be_within(0.01).of(0) + expect(y).to be_within(0.01).of(@pdf.cursor) + expect(w).to be_within(0.01).of(29.344) + expect(h).to be_within(0.01).of(23.872) end @pdf.cell(:content => "text", :background_color => '123456') end @@ -284,10 +284,10 @@ def cell(options={}) @pdf.stubs(:fill_color) @pdf.expects(:fill_color).with('123456') @pdf.expects(:fill_rectangle).checking do |(x, y), w, h| - x.should be_within(0.01).of(12.0) - y.should be_within(0.01).of(34.0) - w.should be_within(0.01).of(29.344) - h.should be_within(0.01).of(23.872) + expect(x).to be_within(0.01).of(12.0) + expect(y).to be_within(0.01).of(34.0) + expect(w).to be_within(0.01).of(29.344) + expect(h).to be_within(0.01).of(23.872) end c = @pdf.make_cell(:content => "text", :background_color => '123456') c.draw([12.0, 34.0]) @@ -306,7 +306,7 @@ def cell(options={}) pdf = Prawn::Document.new pdf.fill_color = '333333' pdf.cell :content => 'foo', :text_color => '555555' - pdf.fill_color.should == '333333' + expect(pdf.fill_color).to eq '333333' end end @@ -326,40 +326,40 @@ def cell(options={}) # wrong. it "should draw top border when requested" do @pdf.expects(:stroke_line).checking do |from, to| - @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756] - @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756] + expect(@pdf.map_to_absolute(from).map{|x| x.round}).to eq [36, 756] + expect(@pdf.map_to_absolute(to).map{|x| x.round}).to eq [65, 756] end @pdf.cell(:content => "text", :borders => [:top]) end it "should draw bottom border when requested" do @pdf.expects(:stroke_line).checking do |from, to| - @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 732] - @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732] + expect(@pdf.map_to_absolute(from).map{|x| x.round}).to eq [36, 732] + expect(@pdf.map_to_absolute(to).map{|x| x.round}).to eq [65, 732] end @pdf.cell(:content => "text", :borders => [:bottom]) end it "should draw left border when requested" do @pdf.expects(:stroke_line).checking do |from, to| - @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756] - @pdf.map_to_absolute(to).map{|x| x.round}.should == [36, 732] + expect(@pdf.map_to_absolute(from).map{|x| x.round}).to eq [36, 756] + expect(@pdf.map_to_absolute(to).map{|x| x.round}).to eq [36, 732] end @pdf.cell(:content => "text", :borders => [:left]) end it "should draw right border when requested" do @pdf.expects(:stroke_line).checking do |from, to| - @pdf.map_to_absolute(from).map{|x| x.round}.should == [65, 756] - @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732] + expect(@pdf.map_to_absolute(from).map{|x| x.round}).to eq [65, 756] + expect(@pdf.map_to_absolute(to).map{|x| x.round}).to eq [65, 732] end @pdf.cell(:content => "text", :borders => [:right]) end it "should draw borders at the same location when in or out of bbox" do @pdf.expects(:stroke_line).checking do |from, to| - @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756] - @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756] + expect(@pdf.map_to_absolute(from).map{|x| x.round}).to eq [36, 756] + expect(@pdf.map_to_absolute(to).map{|x| x.round}).to eq [65, 756] end @pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do @pdf.cell(:content => "text", :borders => [:top]) @@ -371,8 +371,8 @@ def cell(options={}) @pdf.expects(:stroke_color=).with("ff0000") c = @pdf.cell(:content => "text", :border_top_color => "ff0000") - c.border_top_color.should == "ff0000" - c.border_colors[0].should == "ff0000" + expect(c.border_top_color).to eq "ff0000" + expect(c.border_colors[0]).to eq "ff0000" end it "should set border colors with :border_color" do @@ -385,12 +385,12 @@ def cell(options={}) c = @pdf.cell(:content => "text", :border_color => %w[ff0000 00ff00 0000ff ff00ff]) - c.border_colors.should == %w[ff0000 00ff00 0000ff ff00ff] + expect(c.border_colors).to eq %w[ff0000 00ff00 0000ff ff00ff] end it "border_..._width should return 0 if border not selected" do c = @pdf.cell(:content => "text", :borders => [:top]) - c.border_bottom_width.should == 0 + expect(c.border_bottom_width).to eq 0 end it "should set border width with :border_..._width" do @@ -398,8 +398,8 @@ def cell(options={}) @pdf.expects(:line_width=).with(2) c = @pdf.cell(:content => "text", :border_bottom_width => 2) - c.border_bottom_width.should == 2 - c.border_widths[2].should == 2 + expect(c.border_bottom_width).to eq 2 + expect(c.border_widths[2]).to eq 2 end it "should set border widths with :border_width" do @@ -411,28 +411,28 @@ def cell(options={}) c = @pdf.cell(:content => "text", :border_width => [2, 3, 4, 5]) - c.border_widths.should == [2, 3, 4, 5] + expect(c.border_widths).to eq [2, 3, 4, 5] end it "should set default border lines to :solid" do c = @pdf.cell(:content => "text") - c.border_top_line.should == :solid - c.border_right_line.should == :solid - c.border_bottom_line.should == :solid - c.border_left_line.should == :solid - c.border_lines.should == [:solid] * 4 + expect(c.border_top_line).to eq :solid + expect(c.border_right_line).to eq :solid + expect(c.border_bottom_line).to eq :solid + expect(c.border_left_line).to eq :solid + expect(c.border_lines).to eq [:solid] * 4 end it "should set border line with :border_..._line" do c = @pdf.cell(:content => "text", :border_bottom_line => :dotted) - c.border_bottom_line.should == :dotted - c.border_lines[2].should == :dotted + expect(c.border_bottom_line).to eq :dotted + expect(c.border_lines[2]).to eq :dotted end it "should set border lines with :border_lines" do c = @pdf.cell(:content => "text", :border_lines => [:solid, :dotted, :dashed, :solid]) - c.border_lines.should == [:solid, :dotted, :dashed, :solid] + expect(c.border_lines).to eq [:solid, :dotted, :dashed, :solid] end end @@ -450,8 +450,8 @@ def cell(options={}) box = Prawn::Text::Box.new("text", :document => @pdf) Prawn::Text::Box.expects(:new).checking do |text, options| - text.should == "text" - options[:align].should == :right + expect(text).to eq "text" + expect(options[:align]).to eq :right end.at_least_once.returns(box) c.draw @@ -463,8 +463,8 @@ def cell(options={}) box = Prawn::Text::Box.new("text", :document => @pdf) Prawn::Text::Box.expects(:new).checking do |text, options| - text.should == "text" - options[:style].should == :bold + expect(text).to eq "text" + expect(options[:style]).to eq :bold end.at_least_once.returns(box) c.draw @@ -477,9 +477,9 @@ def cell(options={}) box = Prawn::Text::Box.new("text", :document => @pdf) Prawn::Text::Box.expects(:new).checking do |text, options| - text.should == "text" - options[:style].should == :bold - @pdf.font.family.should == 'Courier' + expect(text).to eq "text" + expect(options[:style]).to eq :bold + expect(@pdf.font.family).to eq 'Courier' end.at_least_once.returns(box) c.draw @@ -493,9 +493,9 @@ def cell(options={}) box = Prawn::Text::Box.new("text", :document => @pdf) Prawn::Text::Box.expects(:new).checking do |text, options| - text.should == "text" - @pdf.font.family.should == 'Courier' - @pdf.font.options[:style].should == :bold + expect(text).to eq "text" + expect(@pdf.font.family).to eq 'Courier' + expect(@pdf.font.options[:style]).to eq :bold end.at_least_once.returns(box) c.draw @@ -507,14 +507,14 @@ def cell(options={}) box = Prawn::Text::Formatted::Box.new([], :document => @pdf) Prawn::Text::Formatted::Box.expects(:new).checking do |array, options| - array[0][:text].should == "foo " - array[0][:styles].should == [] + expect(array[0][:text]).to eq "foo " + expect(array[0][:styles]).to eq [] - array[1][:text].should == "bar" - array[1][:styles].should == [:bold] + expect(array[1][:text]).to eq "bar" + expect(array[1][:styles]).to eq [:bold] - array[2][:text].should == " baz" - array[2][:styles].should == [] + expect(array[2][:text]).to eq " baz" + expect(array[2][:styles]).to eq [] end.at_least_once.returns(box) c.draw @@ -528,42 +528,42 @@ def cell(options={}) it "should allow only :font_style to be specified, defaulting to the " + "document's font" do c = cell(:content => "text", :font_style => :bold) - c.font.name.should == 'Helvetica-Bold' + expect(c.font.name).to eq 'Helvetica-Bold' end it "should accept a font name for :font" do c = cell(:content => "text", :font => 'Helvetica-Bold') - c.font.name.should == 'Helvetica-Bold' + expect(c.font.name).to eq 'Helvetica-Bold' end it "should use the specified font to determine font metrics" do c = cell(:content => 'text', :font => 'Courier', :font_style => :bold) font = @pdf.find_font('Courier-Bold') - c.content_width.should == font.compute_width_of("text") + expect(c.content_width).to eq font.compute_width_of("text") end it "should allow style to be changed after initialize" do c = cell(:content => "text") c.font_style = :bold - c.font.name.should == 'Helvetica-Bold' + expect(c.font.name).to eq 'Helvetica-Bold' end it "should default to the document's font, if none is specified" do c = cell(:content => "text") - c.font.should == @pdf.font + expect(c.font).to eq @pdf.font end it "should use the metrics of the selected font (even if it is a variant " + "of the document's font) to calculate width" do c = cell(:content => "text", :font_style => :bold) font = @pdf.find_font('Helvetica-Bold') - c.content_width.should == font.compute_width_of("text") + expect(c.content_width).to eq font.compute_width_of("text") end it "should properly calculate inline-formatted text" do c = cell(:content => "text", :inline_format => true) font = @pdf.find_font('Helvetica-Bold') - c.content_width.should == font.compute_width_of("text") + expect(c.content_width).to eq font.compute_width_of("text") end end end @@ -580,12 +580,12 @@ def cell(options={}) end it "should create a Cell::Image" do - @cell.should be_a_kind_of(Prawn::Table::Cell::Image) + expect(@cell).to be_a_kind_of(Prawn::Table::Cell::Image) end it "should pull the natural width and height from the image" do - @cell.natural_content_width.should == 141 - @cell.natural_content_height.should == 142 + expect(@cell.natural_content_width).to eq 141 + expect(@cell.natural_content_height).to eq 142 end end @@ -605,17 +605,17 @@ def cell(options={}) it "should create a Cell::Image" do - @cell.should be_a_kind_of(Prawn::Table::Cell::Image) + expect(@cell).to be_a_kind_of(Prawn::Table::Cell::Image) end it "should pass through image options" do @pdf.expects(:embed_image).checking do |_, _, options| - options[:scale].should == 2 - options[:fit].should == [100, 200] - options[:width].should == 123 - options[:height].should == 456 - options[:position].should == :center - options[:vposition].should == :center + expect(options[:scale]).to eq 2 + expect(options[:fit]).to eq [100, 200] + expect(options[:width]).to eq 123 + expect(options[:height]).to eq 456 + expect(options[:position]).to eq :center + expect(options[:vposition]).to eq :center end @table.draw diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d14fc5..64ace14 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,6 @@ RSpec.configure do |config| config.mock_framework = :mocha config.include EncodingHelpers - config.treat_symbols_as_metadata_keys_with_true_values = true end def create_pdf(klass=Prawn::Document) diff --git a/spec/table/span_dummy_spec.rb b/spec/table/span_dummy_spec.rb index dd93b42..895d282 100644 --- a/spec/table/span_dummy_spec.rb +++ b/spec/table/span_dummy_spec.rb @@ -17,10 +17,10 @@ end it "colspan dummy delegates background_color to the master cell" do - @colspan_dummy.background_color.should == @colspan_master.background_color + expect(@colspan_dummy.background_color).to eq @colspan_master.background_color end it "rowspan dummy delegates background_color to the master cell" do - @rowspan_dummy.background_color.should == @rowspan_master.background_color + expect(@rowspan_dummy.background_color).to eq @rowspan_master.background_color end end diff --git a/spec/table_spec.rb b/spec/table_spec.rb index d33c245..9f233ed 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -18,28 +18,28 @@ end it "should return a Prawn::Table" do - @table.should be_a_kind_of Prawn::Table + expect(@table).to be_a_kind_of Prawn::Table end it "should flatten the data into the @cells array in row-major order" do - @table.cells.map { |c| c.content }.should == %w[R0C0 R0C1 R1C0 R1C1] + expect(@table.cells.map { |c| c.content }).to eq %w[R0C0 R0C1 R1C0 R1C1] end it "should add row and column numbers to each cell" do c = @table.cells.to_a.first - c.row.should == 0 - c.column.should == 0 + expect(c.row).to eq 0 + expect(c.column).to eq 0 end it "should allow empty fields" do - lambda { + expect { data = [["foo","bar"],["baz",""]] @pdf.table(data) - }.should_not raise_error + }.to_not raise_error end it "should allow a table with a header but no body" do - lambda { @pdf.table([["Header"]], :header => true) }.should_not raise_error + expect { @pdf.table([["Header"]], :header => true) }.to_not raise_error end it "should accurately count columns from data" do @@ -47,7 +47,7 @@ data = [["Name:", {:content => "Some very long name", :colspan => 5}]] pdf = Prawn::Document.new table = Prawn::Table.new data, pdf - table.column_widths.length.should == 6 + expect(table.column_widths.length).to eq 6 end end @@ -67,7 +67,7 @@ #ensure that the header on page 1 is identical to the header on page 0 output = PDF::Inspector::Page.analyze(pdf.render) - output.pages[0][:strings][0..4].should == output.pages[1][:strings][0..4] + expect(output.pages[0][:strings][0..4]).to eq output.pages[1][:strings][0..4] end it "should respect an explicit set table with", :issue => 6 do @@ -75,7 +75,7 @@ ["Current Supplier: BLINKY LIGHTS COMPANY", "611 kWh X $.090041", "$", "55.02"]] pdf = Prawn::Document.new table = Prawn::Table.new data, pdf, :width => pdf.bounds.width - table.column_widths.inject{|sum,x| sum + x }.should == pdf.bounds.width + expect(table.column_widths.inject{|sum,x| sum + x }).to eq pdf.bounds.width end end @@ -97,7 +97,7 @@ #expected behavior would be for the long text to be cut off or an exception to be raised #thus we only expect a single page - pdf.page_count.should == 1 + expect(pdf.page_count).to eq 1 end end @@ -116,7 +116,7 @@ pdf = Prawn::Document.new({:page_size => 'A4', :page_layout => :landscape}) table = Prawn::Table.new data, pdf, :column_widths => column_widths - table.column_widths.should == column_widths + expect(table.column_widths).to eq column_widths end it "should work with two different given colspans", :issue => 628 do @@ -129,7 +129,7 @@ pdf = Prawn::Document.new #the next line raised an Prawn::Errors::CannotFit exception before issue 628 was fixed table = Prawn::Table.new data, pdf, :column_widths => column_widths - table.column_widths.should == column_widths + expect(table.column_widths).to eq column_widths end it "should work with a colspan > 1 with given column_widths (issue #407)" do @@ -182,7 +182,7 @@ ]] table = Prawn::Table.new table_content, pdf - table.column_widths.should == [50.0, 70.0] + expect(table.column_widths).to eq [50.0, 70.0] end it "illustrates issue #710", :issue => 710 do @@ -243,7 +243,7 @@ pdf = Prawn::Document.new table = Prawn::Table.new data, pdf, :column_widths => [50, 200] - table.column_widths.should == [50.0, 200.0] + expect(table.column_widths).to eq [50.0, 200.0] end it "illustrates a variant of problem in issue #407 - comment 28556698" do @@ -259,9 +259,9 @@ pdf = Prawn::Document.new child_1 = pdf.make_table([['foo'*100]]) child_2 = pdf.make_table([['foo']]) - lambda do + expect { pdf.table([[child_1], [child_2]], column_widths: [pdf.bounds.width/2] * 2) - end.should raise_error(Prawn::Errors::CannotFit) + }.to raise_error(Prawn::Errors::CannotFit) end end @@ -284,29 +284,29 @@ initializer.expects(:kick).once @pdf.table([["a"]]){ |doc| - doc.should be_a_kind_of(Prawn::Table); initializer.kick } + expect(doc).to be_a_kind_of(Prawn::Table); initializer.kick } end it "should proxy cell methods to #cells" do table = @pdf.table([["a"]], :cell_style => { :padding => 11 }) - table.cells[0, 0].padding.should == [11, 11, 11, 11] + expect(table.cells[0, 0].padding).to eq [11, 11, 11, 11] end it "should set row and column length" do table = @pdf.table([["a", "b", "c"], ["d", "e", "f"]]) - table.row_length.should == 2 - table.column_length.should == 3 + expect(table.row_length).to eq 2 + expect(table.column_length).to eq 3 end it "should generate a text cell based on a String" do t = @pdf.table([["foo"]]) - t.cells[0,0].should be_a_kind_of(Prawn::Table::Cell::Text) + expect(t.cells[0,0]).to be_a_kind_of(Prawn::Table::Cell::Text) end it "should pass through a text cell" do c = Prawn::Table::Cell::Text.new(@pdf, [0,0], :content => "foo") t = @pdf.table([[c]]) - t.cells[0,0].should == c + expect(t.cells[0,0]).to eq c end end @@ -317,117 +317,105 @@ end it "should select rows by number or range" do - Set.new(@table.row(0).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1]) - Set.new(@table.rows(0..1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.row(0).map(&:content)).to match_array %w[R0C0 R0C1] + expect(@table.rows(0..1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should select rows by array" do - Set.new(@table.rows([0, 1]).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.rows([0, 1]).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should allow negative row selectors" do - Set.new(@table.row(-1).map { |c| c.content }).should == - Set.new(%w[R1C0 R1C1]) - Set.new(@table.rows(-2..-1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) - Set.new(@table.rows(0..-1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.row(-1).map(&:content)).to match_array %w[R1C0 R1C1] + expect(@table.rows(-2..-1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] + expect(@table.rows(0..-1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should select columns by number or range" do - Set.new(@table.column(0).map { |c| c.content }).should == - Set.new(%w[R0C0 R1C0]) - Set.new(@table.columns(0..1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.column(0).map(&:content)).to match_array %w[R0C0 R1C0] + expect(@table.columns(0..1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should select columns by array" do - Set.new(@table.columns([0, 1]).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.columns([0, 1]).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should allow negative column selectors" do - Set.new(@table.column(-1).map { |c| c.content }).should == - Set.new(%w[R0C1 R1C1]) - Set.new(@table.columns(-2..-1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) - Set.new(@table.columns(0..-1).map { |c| c.content }).should == - Set.new(%w[R0C0 R0C1 R1C0 R1C1]) + expect(@table.column(-1).map(&:content)).to match_array %w[R0C1 R1C1] + expect(@table.columns(-2..-1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] + expect(@table.columns(0..-1).map(&:content)).to match_array %w[R0C0 R0C1 R1C0 R1C1] end it "should allow rows and columns to be combined" do - @table.row(0).column(1).map { |c| c.content }.should == ["R0C1"] + expect(@table.row(0).column(1).map { |c| c.content }).to eq ["R0C1"] end it "should accept a filter block, returning a cell proxy" do - @table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c| - c.content }.should == ["R0C1"] + expect(@table.cells.filter { |c| c.content =~ /R0/ }.column(1).map{ |c| + c.content }).to eq ["R0C1"] end it "should accept the [] method, returning a Cell or nil" do - @table.cells[0, 0].content.should == "R0C0" - @table.cells[12, 12].should be_nil + expect(@table.cells[0, 0].content).to eq "R0C0" + expect(@table.cells[12, 12]).to be_nil end it "should proxy unknown methods to the cells" do @table.cells.height = 200 @table.row(1).height = 100 - @table.cells[0, 0].height.should == 200 - @table.cells[1, 0].height.should == 100 + expect(@table.cells[0, 0].height).to eq 200 + expect(@table.cells[1, 0].height).to eq 100 end it "should ignore non-setter methods" do - lambda { + expect { @table.cells.content_width - }.should raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "skips cells that don't respond to the given method" do table = @pdf.make_table([[{:content => "R0", :colspan => 2}], %w[R1C0 R1C1]]) - lambda { + expect { table.row(0).font_style = :bold - }.should_not raise_error + }.to_not raise_error end it "should accept the style method, proxying its calls to the cells" do @table.cells.style(:height => 200, :width => 200) @table.column(0).style(:width => 100) - @table.cells[0, 1].width.should == 200 - @table.cells[1, 0].height.should == 200 - @table.cells[1, 0].width.should == 100 + expect(@table.cells[0, 1].width).to eq 200 + expect(@table.cells[1, 0].height).to eq 200 + expect(@table.cells[1, 0].width).to eq 100 end it "style method should accept a block, passing each cell to be styled" do @table.cells.style { |c| c.height = 200 } - @table.cells[0, 1].height.should == 200 + expect(@table.cells[0, 1].height).to eq 200 end it "should return the width of selected columns for #width" do c0_width = @table.column(0).map{ |c| c.width }.max c1_width = @table.column(1).map{ |c| c.width }.max - @table.column(0).width.should == c0_width - @table.column(1).width.should == c1_width + expect(@table.column(0).width).to eq c0_width + expect(@table.column(1).width).to eq c1_width - @table.columns(0..1).width.should == c0_width + c1_width - @table.cells.width.should == c0_width + c1_width + expect(@table.columns(0..1).width).to eq c0_width + c1_width + expect(@table.cells.width).to eq c0_width + c1_width end it "should return the height of selected rows for #height" do r0_height = @table.row(0).map{ |c| c.height }.max r1_height = @table.row(1).map{ |c| c.height }.max - @table.row(0).height.should == r0_height - @table.row(1).height.should == r1_height + expect(@table.row(0).height).to eq r0_height + expect(@table.row(1).height).to eq r1_height - @table.rows(0..1).height.should == r0_height + r1_height - @table.cells.height.should == r0_height + r1_height + expect(@table.rows(0..1).height).to eq r0_height + r1_height + expect(@table.cells.height).to eq r0_height + r1_height end end @@ -439,19 +427,19 @@ describe "width" do it "should raise_error an error if the given width is outside of range" do - lambda do + expect { @pdf.table([["foo"]], :width => 1) - end.should raise_error(Prawn::Errors::CannotFit) + }.to raise_error(Prawn::Errors::CannotFit) - lambda do + expect { @pdf.table([[@long_text]], :width => @pdf.bounds.width + 100) - end.should raise_error(Prawn::Errors::CannotFit) + }.to raise_error(Prawn::Errors::CannotFit) end it "should accept the natural width for small tables" do pad = 10 # default padding @table = @pdf.table([["a"]]) - @table.width.should == @table.cells[0, 0].natural_content_width + pad + expect(@table.width).to eq @table.cells[0, 0].natural_content_width + pad end it "width should == sum(column_widths)" do @@ -460,14 +448,14 @@ column(1).width = 100 column(2).width = 150 end - table.width.should == 300 + expect(table.width).to eq 300 end it "should accept Numeric for column_widths" do table = Prawn::Table.new([%w[ a b c ], %w[d e f]], @pdf) do |t| t.column_widths = 50 end - table.width.should == 150 + expect(table.width).to eq 150 end it "should calculate unspecified column widths as "+ @@ -480,7 +468,7 @@ col0_width = @pdf.width_of("foo", :size => fs) col1_width = @pdf.width_of("foobar", :size => fs) - table.width.should == col0_width + col1_width + 2*columns*hpad + expect(table.width).to eq col0_width + col1_width + 2*columns*hpad end it "should allow mixing autocalculated and preset"+ @@ -501,7 +489,7 @@ column(3).width = col3_width end - table.width.should == col1_width + col2_width + + expect(table.width).to eq col1_width + col2_width + 2*stretchy_columns*hpad + col0_width + col3_width end @@ -523,9 +511,9 @@ table.draw - table.column(0).width.should == col0_width - table.column(1).width.should == col1_width - table.column(3).width.should == col3_width + expect(table.column(0).width).to eq col0_width + expect(table.column(1).width).to eq col1_width + expect(table.column(3).width).to eq col3_width end it "should_not exceed the maximum width of the margin_box" do @@ -537,7 +525,7 @@ ] table = Prawn::Table.new(data, @pdf) - table.width.should == expected_width + expect(table.width).to eq expected_width end it "should_not exceed the maximum width of the margin_box even with" + @@ -550,7 +538,7 @@ ] table = Prawn::Table.new(data, @pdf) { column(1).width = 100 } - table.width.should == expected_width + expect(table.width).to eq expected_width end it "scales down only the non-preset column widths when the natural width" + @@ -563,34 +551,34 @@ ] table = Prawn::Table.new(data, @pdf) { column(1).width = 100; column(3).width = 50 } - table.width.should == expected_width - table.column_widths[1].should == 100 - table.column_widths[3].should == 50 + expect(table.width).to eq expected_width + expect(table.column_widths[1]).to eq 100 + expect(table.column_widths[3]).to eq 50 end it "should allow width to be reset even after it has been calculated" do @table = @pdf.table([[@long_text]]) @table.width @table.width = 100 - @table.width.should == 100 + expect(@table.width).to eq 100 end it "should shrink columns evenly when two equal columns compete" do @table = @pdf.table([["foo", @long_text], [@long_text, "foo"]]) - @table.cells[0, 0].width.should == @table.cells[0, 1].width + expect(@table.cells[0, 0].width).to eq @table.cells[0, 1].width end it "should grow columns evenly when equal deficient columns compete" do @table = @pdf.table([["foo", "foobar"], ["foobar", "foo"]], :width => 500) - @table.cells[0, 0].width.should == @table.cells[0, 1].width + expect(@table.cells[0, 0].width).to eq @table.cells[0, 1].width end it "should respect manual widths" do @table = @pdf.table([%w[foo bar baz], %w[baz bar foo]], :width => 500) do column(1).width = 60 end - @table.column(1).width.should == 60 - @table.column(0).width.should == @table.column(2).width + expect(@table.column(1).width).to eq 60 + expect(@table.column(0).width).to eq @table.column(2).width end it "should allow table cells to be resized in block" do @@ -609,7 +597,7 @@ %w[kitten d foobar banana]], @pdf, :width => expected_width) - table.width.should == expected_width + expect(table.width).to eq expected_width end it "should_not exceed the :width option" do @@ -621,7 +609,7 @@ ] table = Prawn::Table.new(data, @pdf, :width => expected_width) - table.width.should == expected_width + expect(table.width).to eq expected_width end it "should_not exceed the :width option even with manual widths specified" do @@ -635,7 +623,7 @@ column(1).width = 100 end - table.width.should == expected_width + expect(table.width).to eq expected_width end it "should calculate unspecified column widths even " + @@ -656,7 +644,7 @@ col1_width = pdf.width_of("foo", :size => fs) # cell 1, 1 col2_width = pdf.width_of("foobar", :size => fs) # cell 0, 1 (at col 2) - table.width.should == col0_width + col1_width + + expect(table.width).to eq col0_width + col1_width + col2_width + 2*columns*hpad end end @@ -664,20 +652,20 @@ describe "height" do it "should set all cells in a row to the same height" do @table = @pdf.table([["foo", @long_text]]) - @table.cells[0, 0].height.should == @table.cells[0, 1].height + expect(@table.cells[0, 0].height).to eq @table.cells[0, 1].height end it "should move y-position to the bottom of the table after drawing" do old_y = @pdf.y table = @pdf.table([["foo"]]) - @pdf.y.should == old_y - table.height + expect(@pdf.y).to eq old_y - table.height end it "should_not wrap unnecessarily" do # Test for FP errors and glitches t = @pdf.table([["Bender Bending Rodriguez"]]) h = @pdf.height_of("one line") - (t.height - 10).should be < h*1.5 + expect(t.height - 10).to be < h*1.5 end it "should have a height of n rows" do @@ -692,7 +680,7 @@ line_gap = @pdf.font.line_gap num_rows = data.length - table_height.should be_within(0.001).of( + expect(table_height).to be_within(0.001).of( num_rows * font_height + 2*vpad*num_rows ) end @@ -727,9 +715,9 @@ end it "should raise_error an ArgumentError on unknown :position" do - lambda do + expect { @pdf.table([["foo"]], :position => :bratwurst) - end.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -737,50 +725,61 @@ describe "Multi-page tables" do it "should flow to the next page when hitting the bottom of the bounds" do - Prawn::Document.new { table([["foo"]] * 30) }.page_count.should == 1 - Prawn::Document.new { table([["foo"]] * 31) }.page_count.should == 2 - Prawn::Document.new { table([["foo"]] * 31); table([["foo"]] * 35) }. - page_count.should == 3 + expect(Prawn::Document.new { table([["foo"]] * 30) }.page_count).to eq 1 + expect(Prawn::Document.new { table([["foo"]] * 31) }.page_count).to eq 2 + expect( + Prawn::Document.new { table([["foo"]] * 31); table([["foo"]] * 35) }.page_count + ).to eq 3 end it "should respect the containing bounds" do - Prawn::Document.new do - bounding_box([0, cursor], :width => bounds.width, :height => 72) do - table([["foo"]] * 4) - end - end.page_count.should == 2 + expect( + Prawn::Document.new do + bounding_box([0, cursor], :width => bounds.width, :height => 72) do + table([["foo"]] * 4) + end + end.page_count + ).to eq 2 end it "should_not start a new page before finishing out a row" do - Prawn::Document.new do - table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) - end.page_count.should == 1 + expect( + Prawn::Document.new do + table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) + end.page_count + ).to eq 1 end it "should only start new page on long cells if it would gain us height" do - Prawn::Document.new do - text "Hello" - table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) - end.page_count.should == 2 + expect( + Prawn::Document.new do + text "Hello" + table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) + end.page_count + ).to eq 2 end it "should_not start a new page to gain height when at the top of " + "a bounding box, even if stretchy" do - Prawn::Document.new do - bounding_box([bounds.left, bounds.top - 20], :width => 400) do - table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) - end - end.page_count.should == 1 + expect( + Prawn::Document.new do + bounding_box([bounds.left, bounds.top - 20], :width => 400) do + table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) + end + end.page_count + ).to eq 1 end it "should still break to the next page if in a stretchy bounding box " + "but not at the top" do - Prawn::Document.new do - bounding_box([bounds.left, bounds.top - 20], :width => 400) do - text "Hello" - table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) - end - end.page_count.should == 2 + expect( + Prawn::Document.new do + bounding_box([bounds.left, bounds.top - 20], :width => 400) do + text "Hello" + table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]]) + end + end.page_count + ).to eq 2 end it "should only draw first-page header if the first body row fits" do @@ -791,8 +790,8 @@ output = PDF::Inspector::Page.analyze(pdf.render) # Ensure we only drew the header once, on the second page - output.pages[0][:strings].should be_empty - output.pages[1][:strings].should == ["Header", "Body"] + expect(output.pages[0][:strings]).to be_empty + expect(output.pages[1][:strings]).to eq ["Header", "Body"] end it 'should only draw first-page header if the first multi-row fits', @@ -807,8 +806,8 @@ output = PDF::Inspector::Page.analyze(pdf.render) # Ensure we only drew the header once, on the second page - output.pages[0][:strings].should == [] - output.pages[1][:strings].should == ['Header', 'Multirow cell', 'Line 1', + expect(output.pages[0][:strings]).to eq [] + expect(output.pages[1][:strings]).to eq ['Header', 'Multirow cell', 'Line 1', 'Line 2', 'Line 3'] end @@ -825,8 +824,8 @@ output = PDF::Inspector::Page.analyze(pdf.render) # Ensure we output the cells of row 2 on the new page only - output.pages[0][:strings].should == ['R0C0', 'R0C1', 'R0C2'] - output.pages[1][:strings].should == ['R1C0', 'R1C1', 'R1C2', 'R2C0', 'R2C2'] + expect(output.pages[0][:strings]).to eq ['R0C0', 'R0C1', 'R0C2'] + expect(output.pages[1][:strings]).to eq ['R1C0', 'R1C1', 'R1C2', 'R2C0', 'R2C2'] end end @@ -869,21 +868,21 @@ @pdf.table([["foo"]] * 100) do |t| t.before_rendering_page do |page| - page.row_count.should == ((kicked < 3) ? 30 : 10) - page.column_count.should == 1 - page.row(0).first.content.should == "foo" - page.row(-1).first.content.should == "foo" + expect(page.row_count).to eq ((kicked < 3) ? 30 : 10) + expect(page.column_count).to eq 1 + expect(page.row(0).first.content).to eq "foo" + expect(page.row(-1).first.content).to eq "foo" kicked += 1 end end - kicked.should == 4 + expect(kicked).to eq 4 end it "numbers cells relative to their position on page" do @pdf.table([["foo"]] * 100) do |t| t.before_rendering_page do |page| - page[0, 0].content.should == "foo" + expect(page[0, 0].content).to eq "foo" end end end @@ -898,10 +897,10 @@ end t.cells[30, 0].stubs(:draw_background).checking do |xy| - t.cells[30, 0].background_color.should == 'ff0000' + expect(t.cells[30, 0].background_color).to eq 'ff0000' end t.cells[31, 0].stubs(:draw_background).checking do |xy| - t.cells[31, 0].background_color.should == nil + expect(t.cells[31, 0].background_color).to eq nil end t.draw @@ -910,7 +909,7 @@ it "passes headers on page 2+" do @pdf.table([["header"]] + [["foo"]] * 100, :header => true) do |t| t.before_rendering_page do |page| - page[0, 0].content.should == "header" + expect(page[0, 0].content).to eq "header" end end end @@ -921,7 +920,7 @@ @pdf.table(header + data, :header => true) do |t| t.before_rendering_page do |page| cell = page[0, 0] - cell.dummy_cells.each {|dc| dc.row.should == cell.row } + cell.dummy_cells.each {|dc| expect(dc.row).to eq cell.row } end end end @@ -982,7 +981,7 @@ data = [["foo"], ["bar"], ["baz"]] pdf = Prawn::Document.new t = pdf.table(data, :row_colors => ['cccccc', 'ffffff']) - t.cells.map{|x| x.background_color}.should == %w[cccccc ffffff cccccc] + expect(t.cells.map{|x| x.background_color}).to eq %w[cccccc ffffff cccccc] end it "should ignore headers" do @@ -993,8 +992,7 @@ row(0).background_color = '333333' end - t.cells.map{|x| x.background_color}.should == - %w[333333 cccccc ffffff cccccc] + expect(t.cells.map{|x| x.background_color}).to eq %w[333333 cccccc ffffff cccccc] end it "stripes rows consistently from page to page, skipping header rows" do @@ -1028,7 +1026,7 @@ table = pdf.table(data, :row_colors => ['cccccc', 'ffffff']) { |t| t.cells[0, 0].background_color = 'dddddd' } - table.cells.map{|x| x.background_color}.should == %w[dddddd ffffff cccccc] + expect(table.cells.map{|x| x.background_color}).to eq %w[dddddd ffffff cccccc] end end @@ -1043,7 +1041,7 @@ x = 0 (0..2).each do |col| cell = @table.cells[0, col] - cell.x.should == x + expect(cell.x).to eq x x += cell.width end end @@ -1054,7 +1052,7 @@ (0..2).each do |row| cell = @table.cells[row, 0] - cell.y.should be_within(0.01).of(y) + expect(cell.y).to be_within(0.01).of(y) y -= cell.height end end @@ -1064,7 +1062,7 @@ @pdf = Prawn::Document.new @pdf.table(data) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == data.flatten + expect(output.strings).to eq data.flatten end it "should_not cause an error if rendering the very first row causes a " + @@ -1074,9 +1072,9 @@ pdf.move_down( pdf.y - (pdf.bounds.absolute_bottom + 3) ) - lambda { + expect { pdf.table(arr) - }.should_not raise_error + }.to_not raise_error end end @@ -1124,7 +1122,7 @@ pdf.bounding_box([0, pdf.cursor], :width => pdf.bounds.width) do pdf.expects(:draw_text!).checking { |text, options| - pdf.bounds.absolute_top.should == text_y + expect(pdf.bounds.absolute_top).to eq text_y }.times(3) pdf.table([%w[a b c]]) @@ -1140,7 +1138,7 @@ @pdf = Prawn::Document.new @pdf.table(data, :header => true) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == data.flatten + expect(output.strings).to eq data.flatten end it "should repeat headers across pages" do @@ -1149,7 +1147,7 @@ @pdf = Prawn::Document.new @pdf.table([headers] + data, :header => true) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == headers + data.flatten[0..-3] + headers + + expect(output.strings).to eq headers + data.flatten[0..-3] + headers + data.flatten[-2..-1] end @@ -1161,7 +1159,7 @@ if cell.content == "header" # Assert that header text is drawn at the same location on each page if @header_location - pt.should == @header_location + expect(pt).to eq @header_location else @header_location = pt end @@ -1178,7 +1176,7 @@ Prawn::Table::Cell.expects(:draw_cells).times(2).checking do |cells| cells.each do |cell, pt| if cell.content == "header" - pt[0].should == @pdf.bounds.left + expect(pt[0]).to eq @pdf.bounds.left end end end @@ -1193,7 +1191,7 @@ @pdf.y = 0 @pdf.table([["Header"], ["Body"]], :header => true) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == ["Header", "Body"] + expect(output.strings).to eq ["Header", "Body"] end end @@ -1203,7 +1201,7 @@ @pdf = Prawn::Document.new @pdf.table(data, :header => 2) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == data.flatten + expect(output.strings).to eq data.flatten end it "should repeat headers across pages" do @@ -1212,7 +1210,7 @@ @pdf = Prawn::Document.new @pdf.table([headers] + data, :header => 2) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == headers + data.flatten[0..-3] + headers + + expect(output.strings).to eq headers + data.flatten[0..-3] + headers + data.flatten[-4..-1] end @@ -1224,7 +1222,7 @@ if cell.content == "header" # Assert that header text is drawn at the same location on each page if @header_location - pt.should == @header_location + expect(pt).to eq @header_location else @header_location = pt end @@ -1233,7 +1231,7 @@ if cell.content == "header2" # Assert that header text is drawn at the same location on each page if @header2_location - pt.should == @header2_location + expect(pt).to eq @header2_location else @header2_location = pt end @@ -1249,7 +1247,7 @@ @pdf.y = 0 @pdf.table([["Header"], ["Header2"], ["Body"]], :header => 2) output = PDF::Inspector::Text.analyze(@pdf.render) - output.strings.should == ["Header", "Header2", "Body"] + expect(output.strings).to eq ["Header", "Header2", "Body"] end end end @@ -1263,25 +1261,25 @@ it "can be created from an Array" do cell = Prawn::Table::Cell.make(@pdf, [["foo"]]) - cell.should be_a_kind_of(Prawn::Table::Cell::Subtable) - cell.subtable.should be_a_kind_of(Prawn::Table) + expect(cell).to be_a_kind_of(Prawn::Table::Cell::Subtable) + expect(cell.subtable).to be_a_kind_of(Prawn::Table) end it "defaults its padding to zero" do - @table.cells[0, 0].padding.should == [0, 0, 0, 0] + expect(@table.cells[0, 0].padding).to eq [0, 0, 0, 0] end it "has a subtable accessor" do - @table.cells[0, 0].subtable.should == @subtable + expect(@table.cells[0, 0].subtable).to eq @subtable end it "determines its dimensions from the subtable" do - @table.cells[0, 0].width.should == @subtable.width - @table.cells[0, 0].height.should == @subtable.height + expect(@table.cells[0, 0].width).to eq @subtable.width + expect(@table.cells[0, 0].height).to eq @subtable.height end it "pads the holding cell with padding options" do - @table.cells[1, 1].padding.should == [10, 10, 10, 10] + expect(@table.cells[1, 1].padding).to eq [10, 10, 10, 10] end end @@ -1308,7 +1306,7 @@ ]], width: 515, cell_style: { border_width: 1, border_color: 'ff0000' } pdf.render - pdf.page_count.should == 1 + expect(pdf.page_count).to eq 1 end describe "An invalid table" do @@ -1319,25 +1317,25 @@ end it "should raise_error error when invalid table data is given" do - lambda { + expect { @pdf.table(@bad_data) - }.should raise_error(Prawn::Errors::InvalidTableData) + }.to raise_error(Prawn::Errors::InvalidTableData) end it "should raise_error an EmptyTableError with empty table data" do - lambda { + expect { data = [] @pdf = Prawn::Document.new @pdf.table(data) - }.should raise_error( Prawn::Errors::EmptyTable ) + }.to raise_error( Prawn::Errors::EmptyTable ) end it "should raise_error an EmptyTableError with nil table data" do - lambda { + expect { data = nil @pdf = Prawn::Document.new @pdf.table(data) - }.should raise_error( Prawn::Errors::EmptyTable ) + }.to raise_error( Prawn::Errors::EmptyTable ) end end @@ -1348,47 +1346,47 @@ before(:each) { create_pdf } it "doesn't raise an error" do - lambda { + expect { @pdf.table([[{:content => "foo", :colspan => 2, :rowspan => 2}]]) - }.should_not raise_error + }.to_not raise_error end it "colspan is properly counted" do t = @pdf.make_table([[{:content => "foo", :colspan => 2}]]) - t.column_length.should == 2 + expect(t.column_length).to eq 2 end it "rowspan is properly counted" do t = @pdf.make_table([[{:content => "foo", :rowspan => 2}]]) - t.row_length.should == 2 + expect(t.row_length).to eq 2 end it "raises if colspan or rowspan are called after layout" do - lambda { + expect { @pdf.table([["foo"]]) { cells[0, 0].colspan = 2 } - }.should raise_error(Prawn::Errors::InvalidTableSpan) + }.to raise_error(Prawn::Errors::InvalidTableSpan) - lambda { + expect { @pdf.table([["foo"]]) { cells[0, 0].rowspan = 2 } - }.should raise_error(Prawn::Errors::InvalidTableSpan) + }.to raise_error(Prawn::Errors::InvalidTableSpan) end it "raises when spans overlap" do - lambda { + expect { @pdf.table([["foo", {:content => "bar", :rowspan => 2}], [{:content => "baz", :colspan => 2}]]) - }.should raise_error(Prawn::Errors::InvalidTableSpan) + }.to raise_error(Prawn::Errors::InvalidTableSpan) end it "table and cell width account for colspan" do t = @pdf.table([["a", {:content => "b", :colspan => 2}]], :column_widths => [100, 100, 100]) spanned = t.cells[0, 1] - spanned.colspan.should == 2 - t.width.should == 300 - t.cells.min_width.should == 300 - t.cells.max_width.should == 300 - spanned.width.should == 200 + expect(spanned.colspan).to eq 2 + expect(t.width).to eq 300 + expect(t.cells.min_width).to eq 300 + expect(t.cells.max_width).to eq 300 + expect(spanned.width).to eq 200 end it "table and cell height account for rowspan" do @@ -1396,16 +1394,16 @@ row(0..2).height = 100 end spanned = t.cells[1, 0] - spanned.rowspan.should == 2 - t.height.should == 300 - spanned.height.should == 200 + expect(spanned.rowspan).to eq 2 + expect(t.height).to eq 300 + expect(spanned.height).to eq 200 end it "provides the full content_width as drawing space" do w = @pdf.make_table([["foo"]]).cells[0, 0].content_width t = @pdf.make_table([[{:content => "foo", :colspan => 2}]]) - t.cells[0, 0].spanned_content_width.should == w + expect(t.cells[0, 0].spanned_content_width).to eq w end it "dummy cells are not drawn" do @@ -1422,16 +1420,16 @@ t1 = @pdf.table([["foo"]]) t2 = @pdf.table([[{:content => "foo", :colspan => 2}]]) - t2.width.should == t1.width + expect(t2.width).to eq t1.width t3 = @pdf.table([[{:content => "foo", :rowspan => 2}]]) - t3.height.should == t1.height + expect(t3.height).to eq t1.height end it "dummy cells ignored by #style" do t = @pdf.table([[{:content => "blah", :colspan => 2}]], :cell_style => { :size => 9 }) - t.cells[0, 0].size.should == 9 + expect(t.cells[0, 0].size).to eq 9 end context "inheriting master cell styles from dummy cell" do @@ -1450,7 +1448,7 @@ table.column(1).send("#{attribute_right}=", val) end - t.cells[0, 0].send(attribute_right).should == val + expect(t.cells[0, 0].send(attribute_right)).to eq val end specify "#{attribute_bottom} of bottom row is inherited" do @@ -1458,7 +1456,7 @@ table.row(1).send("#{attribute_bottom}=", val) end - t.cells[0, 0].send(attribute_bottom).should == val + expect(t.cells[0, 0].send(attribute_bottom)).to eq val end specify "#{attribute_left} of right column is not inherited" do @@ -1466,7 +1464,7 @@ table.column(1).send("#{attribute_left}=", val) end - t.cells[0, 0].send(attribute_left).should_not == val + expect(t.cells[0, 0].send(attribute_left)).to_not eq val end specify "#{attribute_right} of interior column is not inherited" do @@ -1474,7 +1472,7 @@ table.column(1).send("#{attribute_right}=", val) end - t.cells[0, 0].send(attribute_right).should_not == val + expect(t.cells[0, 0].send(attribute_right)).to_not eq val end specify "#{attribute_bottom} of interior row is not inherited" do @@ -1482,7 +1480,7 @@ table.row(1).send("#{attribute_bottom}=", val) end - t.cells[0, 0].send(attribute_bottom).should_not == val + expect(t.cells[0, 0].send(attribute_bottom)).to_not eq val end specify "#{attribute_top} of bottom row is not inherited" do @@ -1490,7 +1488,7 @@ table.row(1).send("#{attribute_top}=", val) end - t.cells[0, 0].send(attribute_top).should_not == val + expect(t.cells[0, 0].send(attribute_top)).to_not eq val end end end @@ -1498,14 +1496,14 @@ it "splits natural width between cols in the group" do t = @pdf.table([[{:content => "foo", :colspan => 2}]]) widths = t.column_widths - widths[0].should == widths[1] + expect(widths[0]).to eq widths[1] end it "splits natural width between cols when width is increased" do t = @pdf.table([[{:content => "foo", :colspan => 2}]], :width => @pdf.bounds.width) widths = t.column_widths - widths[0].should == widths[1] + expect(widths[0]).to eq widths[1] end it "splits min-width between cols in the group" do @@ -1516,14 +1514,14 @@ # cols when width is reduced".) t = @pdf.table([[{:content => "foo", :colspan => 2}]], :width => 20) - t.column(0).min_width.should == t.column(1).min_width + expect(t.column(0).min_width).to eq t.column(1).min_width end it "splits natural width between cols when width is reduced" do t = @pdf.table([[{:content => "foo", :colspan => 2}]], :width => 20) widths = t.column_widths - widths[0].should == widths[1] + expect(widths[0]).to eq widths[1] end it "honors a large, explicitly set table width" do @@ -1531,8 +1529,7 @@ ["A", "B", "C"]], :width => 400) - t.column_widths.inject(0) { |sum, w| sum + w }. - should be_within(0.01).of(400) + expect(t.column_widths.inject(0) { |sum, w| sum + w }).to be_within(0.01).of(400) end it "honors a small, explicitly set table width" do @@ -1540,44 +1537,43 @@ :colspan => 3}], ["A", "B", "C"]], :width => 200) - t.column_widths.inject(0) { |sum, w| sum + w }. - should be_within(0.01).of(200) + expect(t.column_widths.inject(0) { |sum, w| sum + w }).to be_within(0.01).of(200) end it "splits natural_content_height between rows in the group" do t = @pdf.table([[{:content => "foo", :rowspan => 2}]]) heights = t.row_heights - heights[0].should == heights[1] + expect(heights[0]).to eq heights[1] end it "skips column numbers that have been col-spanned" do t = @pdf.table([["a", "b", {:content => "c", :colspan => 3}, "d"]]) - t.cells[0, 0].content.should == "a" - t.cells[0, 1].content.should == "b" - t.cells[0, 2].content.should == "c" - t.cells[0, 3].should be_a_kind_of(Prawn::Table::Cell::SpanDummy) - t.cells[0, 4].should be_a_kind_of(Prawn::Table::Cell::SpanDummy) - t.cells[0, 5].content.should == "d" + expect(t.cells[0, 0].content).to eq "a" + expect(t.cells[0, 1].content).to eq "b" + expect(t.cells[0, 2].content).to eq "c" + expect(t.cells[0, 3]).to be_a_kind_of(Prawn::Table::Cell::SpanDummy) + expect(t.cells[0, 4]).to be_a_kind_of(Prawn::Table::Cell::SpanDummy) + expect(t.cells[0, 5].content).to eq "d" end it "skips row/col positions that have been row-spanned" do t = @pdf.table([["a", {:content => "b", :colspan => 2, :rowspan => 2}, "c"], ["d", "e"], ["f", "g", "h", "i"]]) - t.cells[0, 0].content.should == "a" - t.cells[0, 1].content.should == "b" - t.cells[0, 2].should be_a_kind_of(Prawn::Table::Cell::SpanDummy) - t.cells[0, 3].content.should == "c" - - t.cells[1, 0].content.should == "d" - t.cells[1, 1].should be_a_kind_of(Prawn::Table::Cell::SpanDummy) - t.cells[1, 2].should be_a_kind_of(Prawn::Table::Cell::SpanDummy) - t.cells[1, 3].content.should == "e" - - t.cells[2, 0].content.should == "f" - t.cells[2, 1].content.should == "g" - t.cells[2, 2].content.should == "h" - t.cells[2, 3].content.should == "i" + expect(t.cells[0, 0].content).to eq "a" + expect(t.cells[0, 1].content).to eq "b" + expect(t.cells[0, 2]).to be_a_kind_of(Prawn::Table::Cell::SpanDummy) + expect(t.cells[0, 3].content).to eq "c" + + expect(t.cells[1, 0].content).to eq "d" + expect(t.cells[1, 1]).to be_a_kind_of(Prawn::Table::Cell::SpanDummy) + expect(t.cells[1, 2]).to be_a_kind_of(Prawn::Table::Cell::SpanDummy) + expect(t.cells[1, 3].content).to eq "e" + + expect(t.cells[2, 0].content).to eq "f" + expect(t.cells[2, 1].content).to eq "g" + expect(t.cells[2, 2].content).to eq "h" + expect(t.cells[2, 3].content).to eq "i" end it 'illustrates issue #20', issue: 20 do @@ -1602,6 +1598,6 @@ pdf.table [['one', 'two']], position: :center pdf.table [['three', 'four']], position: :center pdf.render - pdf.page_count.should == 1 + expect(pdf.page_count).to eq 1 end end