diff --git a/prawn.gemspec b/prawn.gemspec index 56965eb9f..230be4f2f 100644 --- a/prawn.gemspec +++ b/prawn.gemspec @@ -30,7 +30,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency('pdf-inspector', '~> 1.2.1') spec.add_development_dependency('yard') spec.add_development_dependency('rspec', '~> 3.0') - spec.add_development_dependency('mocha') spec.add_development_dependency('rake') spec.add_development_dependency('simplecov') spec.add_development_dependency('prawn-manual_builder', ">= 0.2.0") diff --git a/spec/document_spec.rb b/spec/document_spec.rb index 71d557a4a..bb8865a69 100644 --- a/spec/document_spec.rb +++ b/spec/document_spec.rb @@ -190,8 +190,8 @@ def self.format(string) end it "should be invoked for each new page" do - trigger = mock - trigger.expects(:fire).times(5) + trigger = double("trigger") + expect(trigger).to receive(:fire).exactly(5).times @pdf.renderer.on_page_create { trigger.fire } @@ -199,11 +199,11 @@ def self.format(string) end it "should be replaceable" do - trigger1 = mock - trigger1.expects(:fire).times(1) + trigger1 = double("trigger 1") + expect(trigger1).to receive(:fire).once - trigger2 = mock - trigger2.expects(:fire).times(1) + trigger2 = double("trigger 2") + expect(trigger2).to receive(:fire).once @pdf.renderer.on_page_create { trigger1.fire } @@ -215,8 +215,8 @@ def self.format(string) end it "should be clearable by calling on_page_create without a block" do - trigger = mock - trigger.expects(:fire).times(1) + trigger = double("trigger") + expect(trigger).to receive(:fire).once @pdf.renderer.on_page_create { trigger.fire } @@ -231,8 +231,8 @@ def self.format(string) describe "Document compression" do it "should not compress the page content stream if compression is disabled" do pdf = Prawn::Document.new(:compress => false) - pdf.page.content.stream.stubs(:compress!).returns(true) - pdf.page.content.stream.expects(:compress!).never + allow(pdf.page.content.stream).to receive(:compress!).and_return(true) + expect(pdf.page.content.stream).to_not receive(:compress!) pdf.text "Hi There" * 20 pdf.render @@ -240,8 +240,8 @@ def self.format(string) it "should compress the page content stream if compression is enabled" do pdf = Prawn::Document.new(:compress => true) - pdf.page.content.stream.stubs(:compress!).returns(true) - pdf.page.content.stream.expects(:compress!).once + allow(pdf.page.content.stream).to receive(:compress!).and_return(true) + expect(pdf.page.content.stream).to receive(:compress!).once pdf.text "Hi There" * 20 pdf.render @@ -470,22 +470,17 @@ def self.format(string) it "should trigger before_render callbacks just before rendering" do pdf = Prawn::Document.new - seq = sequence("callback_order") - # Verify the order: finalize -> fire callbacks -> render body - pdf.renderer.expects(:finalize_all_page_contents).in_sequence(seq) - trigger = mock - trigger.expects(:fire).in_sequence(seq) + expect(pdf.renderer).to receive(:finalize_all_page_contents).and_call_original.ordered - # Store away the render_body method to be called below - render_body = pdf.renderer.method(:render_body) - pdf.renderer.expects(:render_body).in_sequence(seq) + trigger = double("trigger") + expect(trigger).to receive(:fire).ordered pdf.renderer.before_render{ trigger.fire } - # Render the body to set up object offsets - render_body.call(StringIO.new) - pdf.render + expect(pdf.renderer).to receive(:render_body).and_call_original.ordered + + pdf.render(StringIO.new) end it "should be idempotent" do @@ -575,31 +570,31 @@ def self.format(string) it "replaces the '' string with the proper page number" do @pdf.start_new_page - @pdf.expects(:text_box).with("1, test", :height => 50) + expect(@pdf).to receive(:text_box).with("1, test", :height => 50) @pdf.number_pages ", test", :page_filter => :all end it "replaces the '' string with the total page count" do @pdf.start_new_page - @pdf.expects(:text_box).with("test, 1", :height => 50) + expect(@pdf).to receive(:text_box).with("test, 1", :height => 50) @pdf.number_pages "test, ", :page_filter => :all end it "must print each page if given the :all page_filter" do 10.times { @pdf.start_new_page } - @pdf.expects(:text_box).times(10) + expect(@pdf).to receive(:text_box).exactly(10).times @pdf.number_pages "test", :page_filter => :all end it "must print each page if no :page_filter is specified" do 10.times { @pdf.start_new_page } - @pdf.expects(:text_box).times(10) + expect(@pdf).to receive(:text_box).exactly(10).times @pdf.number_pages "test" end it "must not print the page number if given a nil filter" do 10.times { @pdf.start_new_page } - @pdf.expects(:text_box).never + expect(@pdf).to_not receive(:text_box) @pdf.number_pages "test", :page_filter => nil end @@ -609,8 +604,8 @@ def self.format(string) it "increments the pages" do 2.times { @pdf.start_new_page } options = { :page_filter => :all, :start_count_at => startat } - @pdf.expects(:text_box).with("#{startat} 2", :height => 50) - @pdf.expects(:text_box).with("#{startat + 1} 2", :height => 50) + expect(@pdf).to receive(:text_box).with("#{startat} 2", :height => 50) + expect(@pdf).to receive(:text_box).with("#{startat + 1} 2", :height => 50) @pdf.number_pages " ", options end end @@ -621,9 +616,9 @@ def self.format(string) it "defaults to start at page 1" do 3.times { @pdf.start_new_page } options = { :page_filter => :all, :start_count_at => val } - @pdf.expects(:text_box).with("1 3", :height => 50) - @pdf.expects(:text_box).with("2 3", :height => 50) - @pdf.expects(:text_box).with("3 3", :height => 50) + expect(@pdf).to receive(:text_box).with("1 3", :height => 50) + expect(@pdf).to receive(:text_box).with("2 3", :height => 50) + expect(@pdf).to receive(:text_box).with("3 3", :height => 50) @pdf.number_pages " ", options end end @@ -633,8 +628,8 @@ def self.format(string) context "total_pages option" do it "allows the total pages count to be overridden" do 2.times { @pdf.start_new_page } - @pdf.expects(:text_box).with("1 10", :height => 50) - @pdf.expects(:text_box).with("2 10", :height => 50) + expect(@pdf).to receive(:text_box).with("1 10", :height => 50) + expect(@pdf).to receive(:text_box).with("2 10", :height => 50) @pdf.number_pages " ", :page_filter => :all, :total_pages => 10 end end @@ -643,16 +638,16 @@ def self.format(string) context "such as :odd" do it "increments the pages" do 3.times { @pdf.start_new_page } - @pdf.expects(:text_box).with("1 3", :height => 50) - @pdf.expects(:text_box).with("3 3", :height => 50) - @pdf.expects(:text_box).with("2 3", :height => 50).never + expect(@pdf).to receive(:text_box).with("1 3", :height => 50) + expect(@pdf).to receive(:text_box).with("3 3", :height => 50) + expect(@pdf).to_not receive(:text_box).with("2 3", :height => 50) @pdf.number_pages " ", :page_filter => :odd end end context "missing" do it "does not print any page numbers" do 3.times { @pdf.start_new_page } - @pdf.expects(:text_box).never + expect(@pdf).to_not receive(:text_box) @pdf.number_pages " ", :page_filter => nil end end @@ -662,10 +657,10 @@ def self.format(string) context "such as :odd and 7" do it "increments the pages" do 3.times { @pdf.start_new_page } - @pdf.expects(:text_box).with("1 3", :height => 50).never - @pdf.expects(:text_box).with("5 3", :height => 50) # page 1 - @pdf.expects(:text_box).with("6 3", :height => 50).never # page 2 - @pdf.expects(:text_box).with("7 3", :height => 50) # page 3 + expect(@pdf).to_not receive(:text_box).with("1 3", :height => 50) + expect(@pdf).to receive(:text_box).with("5 3", :height => 50) # page 1 + expect(@pdf).to_not receive(:text_box).with("6 3", :height => 50) # page 2 + expect(@pdf).to receive(:text_box).with("7 3", :height => 50) # page 3 @pdf.number_pages " ", :page_filter => :odd, :start_count_at => 5 end end @@ -673,12 +668,12 @@ def self.format(string) it "increments the pages" do 6.times { @pdf.start_new_page } options = { :page_filter => lambda { |p| p != 2 && p != 5 }, :start_count_at => 4 } - @pdf.expects(:text_box).with("4 6", :height => 50) # page 1 - @pdf.expects(:text_box).with("5 6", :height => 50).never # page 2 - @pdf.expects(:text_box).with("6 6", :height => 50) # page 3 - @pdf.expects(:text_box).with("7 6", :height => 50) # page 4 - @pdf.expects(:text_box).with("8 6", :height => 50).never # page 5 - @pdf.expects(:text_box).with("9 6", :height => 50) # page 6 + expect(@pdf).to receive(:text_box).with("4 6", :height => 50) # page 1 + expect(@pdf).to_not receive(:text_box).with("5 6", :height => 50) # page 2 + expect(@pdf).to receive(:text_box).with("6 6", :height => 50) # page 3 + expect(@pdf).to receive(:text_box).with("7 6", :height => 50) # page 4 + expect(@pdf).to_not receive(:text_box).with("8 6", :height => 50) # page 5 + expect(@pdf).to receive(:text_box).with("9 6", :height => 50) # page 6 @pdf.number_pages " ", options end end @@ -690,17 +685,17 @@ def self.format(string) end it "with 10 height" do - @pdf.expects(:text_box).with("1 1", :height => 10) + expect(@pdf).to receive(:text_box).with("1 1", :height => 10) @pdf.number_pages " ", :height => 10 end it "with nil height" do - @pdf.expects(:text_box).with("1 1", :height => nil) + expect(@pdf).to receive(:text_box).with("1 1", :height => nil) @pdf.number_pages " ", :height => nil end it "with no height" do - @pdf.expects(:text_box).with("1 1", :height => 50) + expect(@pdf).to receive(:text_box).with("1 1", height: 50) @pdf.number_pages " " end end diff --git a/spec/extensions/mocha.rb b/spec/extensions/mocha.rb deleted file mode 100644 index 2bda4f78f..000000000 --- a/spec/extensions/mocha.rb +++ /dev/null @@ -1,45 +0,0 @@ -# encoding: utf-8 - -# Allow speccing things when an expectation matcher runs. Similar to #with, but -# always succeeds. -# -# @pdf.expects(:stroke_line).checking do |from, to| -# @pdf.map_to_absolute(from).should == [0, 0] -# end -# -# Note that the outer expectation does *not* fail only because the inner one -# does; in the above example, the outer expectation would only fail if -# stroke_line were not called. - -class ParameterChecker < Mocha::ParametersMatcher - def initialize(&matching_block) - @expected_parameters = [Mocha::ParameterMatchers::AnyParameters.new] - @matching_block = matching_block - end - - def match?(actual_parameters = []) - @matching_block.call(*actual_parameters) - - true # always succeed - end -end - -class Mocha::Expectation - def checking(&block) - @parameters_matcher = ParameterChecker.new(&block) - self - end -end - -# Equivalent to expects(method_name).at_least(0). More useful when combined -# with parameter matchers to ignore certain calls for the sake of parameter -# matching. -# -# @pdf.ignores(:stroke_color=).with("000000") -# @pdf.expects(:stroke_color=).with("ff0000") -# -module Mocha::ObjectMethods - def ignores(method_name) - expects(method_name).at_least(0) - end -end diff --git a/spec/formatted_text_box_spec.rb b/spec/formatted_text_box_spec.rb index c72c2956d..051208ad3 100644 --- a/spec/formatted_text_box_spec.rb +++ b/spec/formatted_text_box_spec.rb @@ -225,7 +225,7 @@ :document => @pdf, :fallback_fonts => []) - box.expects(:process_fallback_fonts).never + expect(box).to_not receive(:process_fallback_fonts) box.render end @@ -236,7 +236,7 @@ @pdf.font("Kai") - box.expects(:process_fallback_fonts).never + expect(box).to_not receive(:process_fallback_fonts) box.render end end @@ -339,10 +339,10 @@ it "should be able to perform fragment callbacks" do create_pdf callback_object = TestFragmentCallback.new("something", 7, :document => @pdf) - callback_object.expects(:render_behind).with( + expect(callback_object).to receive(:render_behind).with( kind_of(Prawn::Text::Formatted::Fragment) ) - callback_object.expects(:render_in_front).with( + expect(callback_object).to receive(:render_in_front).with( kind_of(Prawn::Text::Formatted::Fragment) ) array = [{ :text => "hello world " }, @@ -355,18 +355,18 @@ create_pdf callback_object = TestFragmentCallback.new("something", 7, :document => @pdf) - callback_object.expects(:render_behind).with( + expect(callback_object).to receive(:render_behind).with( kind_of(Prawn::Text::Formatted::Fragment) ) - callback_object.expects(:render_in_front).with( + expect(callback_object).to receive(:render_in_front).with( kind_of(Prawn::Text::Formatted::Fragment) ) callback_object2 = TestFragmentCallback.new("something else", 14, :document => @pdf) - callback_object2.expects(:render_behind).with( + expect(callback_object2).to receive(:render_behind).with( kind_of(Prawn::Text::Formatted::Fragment) ) - callback_object2.expects(:render_in_front).with( + expect(callback_object2).to receive(:render_in_front).with( kind_of(Prawn::Text::Formatted::Fragment) ) @@ -485,12 +485,12 @@ end it "should be able to add URL links" do create_pdf - @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], - :A => { - :Type => :Action, - :S => :URI, - :URI => "http://example.com" - }) + expect(@pdf).to receive(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], + :A => { + :Type => :Action, + :S => :URI, + :URI => "http://example.com" + }) array = [{ :text => "click " }, { :text => "here", :link => "http://example.com" }, { :text => " to visit" }] @@ -499,8 +499,8 @@ end it "should be able to add destination links" do create_pdf - @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], - :Dest => "ToC") + expect(@pdf).to receive(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], + :Dest => "ToC") array = [{ :text => "Go to the " }, { :text => "Table of Contents", :anchor => "ToC" }] text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf) @@ -508,13 +508,13 @@ end it "should be able to add local actions" do create_pdf - @pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], - :A => { - :Type => :Action, - :S => :Launch, - :F => "../example.pdf", - :NewWindow => true - }) + expect(@pdf).to receive(:link_annotation).with(kind_of(Array), :Border => [0, 0, 0], + :A => { + :Type => :Action, + :S => :Launch, + :F => "../example.pdf", + :NewWindow => true + }) array = [{ :text => "click " }, { :text => "here", :local => "../example.pdf" }, { :text => " to open a local file" }] diff --git a/spec/graphics_spec.rb b/spec/graphics_spec.rb index 19f17047f..c3085b618 100644 --- a/spec/graphics_spec.rb +++ b/spec/graphics_spec.rb @@ -200,22 +200,22 @@ before(:each) { create_pdf } it "should default to the f operator (nonzero winding number rule)" do - @pdf.renderer.expects(:add_content).with("f") + expect(@pdf.renderer).to receive(:add_content).with("f") @pdf.fill end it "should use f* for :fill_rule => :even_odd" do - @pdf.renderer.expects(:add_content).with("f*") + expect(@pdf.renderer).to receive(:add_content).with("f*") @pdf.fill(:fill_rule => :even_odd) end it "should use b by default for fill_and_stroke (nonzero winding number)" do - @pdf.renderer.expects(:add_content).with("b") + expect(@pdf.renderer).to receive(:add_content).with("b") @pdf.fill_and_stroke end it "should use b* for fill_and_stroke(:fill_rule => :even_odd)" do - @pdf.renderer.expects(:add_content).with("b*") + expect(@pdf.renderer).to receive(:add_content).with("b*") @pdf.fill_and_stroke(:fill_rule => :even_odd) end end @@ -377,7 +377,7 @@ let(:opts) { {} } it "doesn't transform the gradient and displays a warning" do - @pdf.expects(:warn).twice + expect(@pdf).to receive(:warn).twice expect(subject).to eq([[1, 0, 0, 1, 0, 10]]) end end @@ -388,15 +388,15 @@ before(:each) { create_pdf } it "should convert stroke_some_method(args) into some_method(args); stroke" do - @pdf.expects(:line_to).with([100, 100]) - @pdf.expects(:stroke) + expect(@pdf).to receive(:line_to).with([100, 100]) + expect(@pdf).to receive(:stroke) @pdf.stroke_line_to [100, 100] end it "should convert fill_some_method(args) into some_method(args); fill" do - @pdf.expects(:line_to).with([100, 100]) - @pdf.expects(:fill) + expect(@pdf).to receive(:line_to).with([100, 100]) + expect(@pdf).to receive(:fill) @pdf.fill_line_to [100, 100] end @@ -411,22 +411,21 @@ before(:each) { create_pdf } it "should add the right content on save_graphics_state" do - @pdf.renderer.expects(:add_content).with('q') + expect(@pdf.renderer).to receive(:add_content).with('q') @pdf.save_graphics_state end it "should add the right content on restore_graphics_state" do - @pdf.renderer.expects(:add_content).with('Q') + expect(@pdf.renderer).to receive(:add_content).with('Q') @pdf.restore_graphics_state end it "should save and restore when save_graphics_state is used with a block" do - state = sequence "state" - @pdf.renderer.expects(:add_content).with('q').in_sequence(state) - @pdf.expects(:foo).in_sequence(state) - @pdf.renderer.expects(:add_content).with('Q').in_sequence(state) + expect(@pdf.renderer).to receive(:add_content).with('q').ordered + allow(@pdf).to receive(:foo).ordered + expect(@pdf.renderer).to receive(:add_content).with('Q').ordered @pdf.save_graphics_state do @pdf.foo @@ -542,14 +541,14 @@ # part is 5 (PDF Reference, Third Edition, p. 706) it "should send the right content on transformation_matrix" do - @pdf.renderer.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm') + expect(@pdf.renderer).to receive(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm') @pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20 end it "should use fixed digits with very small number" do values = Array.new(6, 0.000000000001) string = Array.new(6, "0.00000").join " " - @pdf.renderer.expects(:add_content).with("#{string} cm") + expect(@pdf.renderer).to receive(:add_content).with("#{string} cm") @pdf.transformation_matrix(*values) end @@ -562,12 +561,13 @@ it "should save the graphics state inside the given block" do values = Array.new(6, 0.000000000001) string = Array.new(6, "0.00000").join " " - process = sequence "process" - @pdf.expects(:save_graphics_state).with.in_sequence(process) - @pdf.renderer.expects(:add_content).with("#{string} cm").in_sequence(process) - @pdf.expects(:do_something).with.in_sequence(process) - @pdf.expects(:restore_graphics_state).with.in_sequence(process) + expect(@pdf).to receive(:save_graphics_state).with(no_args).ordered + allow(@pdf.renderer).to receive(:add_content).with(any_args).twice + expect(@pdf.renderer).to receive(:add_content).with("#{string} cm").ordered + allow(@pdf).to receive(:do_something).ordered + expect(@pdf).to receive(:restore_graphics_state).with(no_args).ordered + @pdf.transformation_matrix(*values) do @pdf.do_something end @@ -586,7 +586,7 @@ describe "#rotate" do it "should rotate" do - @pdf.expects(:transformation_matrix).with(@cos, @sin, -@sin, @cos, 0, 0) + expect(@pdf).to receive(:transformation_matrix).with(@cos, @sin, -@sin, @cos, 0, 0) @pdf.rotate(@angle) end end @@ -642,14 +642,14 @@ def reduce_precision(float) describe "#translate" do it "should translate" do x, y = 12, 54.32 - @pdf.expects(:transformation_matrix).with(1, 0, 0, 1, x, y) + expect(@pdf).to receive(:transformation_matrix).with(1, 0, 0, 1, x, y) @pdf.translate(x, y) end end describe "#scale" do it "should scale" do - @pdf.expects(:transformation_matrix).with(@factor, 0, 0, @factor, 0, 0) + expect(@pdf).to receive(:transformation_matrix).with(@factor, 0, 0, @factor, 0, 0) @pdf.scale(@factor) end end diff --git a/spec/image_handler_spec.rb b/spec/image_handler_spec.rb index 84555483b..b8a5d66cb 100644 --- a/spec/image_handler_spec.rb +++ b/spec/image_handler_spec.rb @@ -5,11 +5,11 @@ describe "ImageHandler" do let(:image_handler) { Prawn::ImageHandler.new } - let(:handler_a) { mock("Handler A") } - let(:handler_b) { mock("Handler B") } + let(:handler_a) { double("Handler A") } + let(:handler_b) { double("Handler B") } it "finds the image handler for an image" do - handler_a.expects(:can_render? => true) + allow(handler_a).to receive(:can_render?).and_return(true) image_handler.register(handler_a) image_handler.register(handler_b) @@ -19,7 +19,7 @@ end it "can prepend handlers" do - handler_b.expects(:can_render? => true) + allow(handler_b).to receive(:can_render?).and_return(true) image_handler.register(handler_a) image_handler.register!(handler_b) @@ -29,7 +29,7 @@ end it "can unregister a handler" do - handler_b.expects(:can_render? => true) + allow(handler_b).to receive(:can_render?).and_return(true) image_handler.register(handler_a) image_handler.register(handler_b) @@ -41,8 +41,8 @@ end it "raises an error when no matching handler is found" do - handler_a.expects(:can_render? => false) - handler_b.expects(:can_render? => false) + allow(handler_a).to receive(:can_render?).and_return(false) + allow(handler_b).to receive(:can_render?).and_return(false) image_handler.register(handler_a) image_handler.register(handler_b) diff --git a/spec/images_spec.rb b/spec/images_spec.rb index 4a7fadce0..a22e3628c 100644 --- a/spec/images_spec.rb +++ b/spec/images_spec.rb @@ -114,7 +114,7 @@ end it "should not start a new page just for a stretchy bounding box" do - @pdf.expects(:start_new_page).times(0) + expect(@pdf).to_not receive(:start_new_page) @pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do @pdf.image @filename end diff --git a/spec/repeater_spec.rb b/spec/repeater_spec.rb index 8d5b41ae5..d412ce2f2 100644 --- a/spec/repeater_spec.rb +++ b/spec/repeater_spec.rb @@ -7,7 +7,7 @@ orig_count = Prawn::Repeater.count doc = sample_document - doc.expects(:create_stamp).with("prawn_repeater(#{orig_count})") + expect(doc).to receive(:create_stamp).with("prawn_repeater(#{orig_count})") r = repeater(doc, :all) { :do_nothing } @@ -54,7 +54,7 @@ it "must try to run a stamp if the page number matches" do doc = sample_document - doc.expects(:stamp) + expect(doc).to receive(:stamp) repeater(doc, :odd).run(3) end @@ -62,28 +62,28 @@ it "must not try to run a stamp unless the page number matches" do doc = sample_document - doc.expects(:stamp).never + expect(doc).to_not receive(:stamp) repeater(doc, :odd).run(2) end it "must not try to run a stamp if dynamic is selected" do doc = sample_document - doc.expects(:stamp).never + expect(doc).to_not receive(:stamp) (1..10).each { |p| repeater(doc, :all, true){ :do_nothing }.run(p) } end it "must try to run a block if the page number matches" do doc = sample_document - doc.expects(:draw_text).twice + expect(doc).to receive(:draw_text).twice (1..10).each { |p| repeater(doc, [1, 2], true){ doc.draw_text "foo" }.run(p) } end it "must not try to run a block unless the page number matches" do doc = sample_document - doc.expects(:draw_text).never + expect(doc).to_not receive(:draw_text) repeater(doc, :odd, true){ doc.draw_text "foo" }.run(2) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9f6afa676..dd86f19dd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,7 +18,6 @@ Prawn::Font::AFM.hide_m17n_warning = true require "rspec" -require "mocha/api" require "pdf/reader" require "pdf/inspector" @@ -27,7 +26,6 @@ Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each { |f| require f } RSpec.configure do |config| - config.mock_framework = :mocha config.include EncodingHelpers end diff --git a/spec/text_box_spec.rb b/spec/text_box_spec.rb index bba703d72..864e64621 100644 --- a/spec/text_box_spec.rb +++ b/spec/text_box_spec.rb @@ -188,28 +188,30 @@ before(:each) { create_pdf } it "hits the callback whenever text is drawn" do - draw_block = stub - draw_block.expects(:kick).with("this text is long enough to") - draw_block.expects(:kick).with("span two lines") + draw_block = spy("Draw block") @pdf.text_box "this text is long enough to span two lines", :width => 150, :draw_text_callback => lambda { |text, _| draw_block.kick(text) } + + expect(draw_block).to have_received(:kick).with("this text is long enough to") + expect(draw_block).to have_received(:kick).with("span two lines") end it "hits the callback once per fragment for :inline_format" do - draw_block = stub - draw_block.expects(:kick).with("this text has ") - draw_block.expects(:kick).with("fancy") - draw_block.expects(:kick).with(" formatting") + draw_block = spy("Draw block") @pdf.text_box "this text has fancy formatting", :inline_format => true, :width => 500, :draw_text_callback => lambda { |text, _| draw_block.kick(text) } + + expect(draw_block).to have_received(:kick).with("this text has ") + expect(draw_block).to have_received(:kick).with("fancy") + expect(draw_block).to have_received(:kick).with(" formatting") end it "does not call #draw_text!" do - @pdf.expects(:draw_text!).never + expect(@pdf).to_not receive(:draw_text!) @pdf.text_box "some text", :width => 500, :draw_text_callback => lambda { |_, _| } end diff --git a/spec/text_spec.rb b/spec/text_spec.rb index 9df121ce2..2d3986d1f 100644 --- a/spec/text_spec.rb +++ b/spec/text_spec.rb @@ -480,25 +480,19 @@ describe "kerning" do it "should respect text kerning setting (document default)" do create_pdf - @pdf.font.expects(:compute_width_of).with do |str, options| - str == "VAT" && options[:kerning] == true - end.at_least_once.returns(10) + expect(@pdf.font).to receive(:compute_width_of).with("VAT", hash_including(kerning: true)).and_return(10) @pdf.text "VAT" end it "should respect text kerning setting (kerning=true)" do create_pdf - @pdf.font.expects(:compute_width_of).with do |str, options| - str == "VAT" && options[:kerning] == true - end.at_least_once.returns(10) + expect(@pdf.font).to receive(:compute_width_of).with("VAT", hash_including(kerning: true)).at_least(:once).and_return(10) @pdf.text "VAT", :kerning => true end it "should respect text kerning setting (kerning=false)" do create_pdf - @pdf.font.expects(:compute_width_of).with do |str, options| - str == "VAT" && options[:kerning] == false - end.at_least_once.returns(10) + expect(@pdf.font).to receive(:compute_width_of).with("VAT", hash_including(kerning: false)).at_least(:once).and_return(10) @pdf.text "VAT", :kerning => false end end diff --git a/spec/view_spec.rb b/spec/view_spec.rb index 0377ac81f..5e1f6c8ef 100644 --- a/spec/view_spec.rb +++ b/spec/view_spec.rb @@ -10,20 +10,20 @@ end it "delegates unhandled methods to object returned by document method" do - doc = mock("Document") - view_object.stubs(:document => doc) + doc = double("Document") + allow(view_object).to receive(:document).and_return(doc) - doc.expects(:some_delegated_method) + expect(doc).to receive(:some_delegated_method) view_object.some_delegated_method end it "allows a block-like DSL via the update method" do - doc = mock("Document") - view_object.stubs(:document => doc) + doc = double("Document") + allow(view_object).to receive(:document).and_return(doc) - doc.expects(:foo) - doc.expects(:bar) + expect(doc).to receive(:foo) + expect(doc).to receive(:bar) view_object.update do foo @@ -32,10 +32,10 @@ end it "aliases save_as() to document.render_file()" do - doc = mock("Document") - doc.expects(:render_file) + doc = double("Document") + expect(doc).to receive(:render_file) - view_object.stubs(:document => doc) + allow(view_object).to receive(:document).and_return(doc) view_object.save_as("foo.pdf") end