Skip to content

Commit

Permalink
Merge pull request #932 from prawnpdf/drop-mocha
Browse files Browse the repository at this point in the history
Drop Mocha
  • Loading branch information
pointlessone committed Jan 24, 2016
2 parents 53d6786 + 002b68e commit 68c9530
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 189 deletions.
1 change: 0 additions & 1 deletion prawn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
99 changes: 47 additions & 52 deletions spec/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,20 @@ 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 }

5.times { @pdf.start_new_page }
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 }

Expand All @@ -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 }

Expand All @@ -231,17 +231,17 @@ 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
end

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -575,31 +570,31 @@ def self.format(string)

it "replaces the '<page>' 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 "<page>, test", :page_filter => :all
end

it "replaces the '<total>' 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, <total>", :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

Expand All @@ -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 "<page> <total>", options
end
end
Expand All @@ -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 "<page> <total>", options
end
end
Expand All @@ -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> <total>", :page_filter => :all, :total_pages => 10
end
end
Expand All @@ -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> <total>", :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> <total>", :page_filter => nil
end
end
Expand All @@ -662,23 +657,23 @@ 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> <total>", :page_filter => :odd, :start_count_at => 5
end
end
context "some crazy proc and 2" do
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 "<page> <total>", options
end
end
Expand All @@ -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 "<page> <total>", :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 "<page> <total>", :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 "<page> <total>"
end
end
Expand Down
45 changes: 0 additions & 45 deletions spec/extensions/mocha.rb

This file was deleted.

46 changes: 23 additions & 23 deletions spec/formatted_text_box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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 " },
Expand All @@ -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)
)

Expand Down Expand Up @@ -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" }]
Expand All @@ -499,22 +499,22 @@
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)
text_box.render
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" }]
Expand Down
Loading

0 comments on commit 68c9530

Please sign in to comment.