specs/graphics_spec.rb in pdf-wrapper-0.1.3 vs specs/graphics_spec.rb in pdf-wrapper-0.2.0
- old
+ new
@@ -1,18 +1,21 @@
# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
context "The PDF::Wrapper class" do
+
+ before(:each) { create_pdf }
+
specify "should be able to draw a single line onto the canvas" do
x0 = y0 = 100
x1 = y1 = 200
- pdf = PDF::Wrapper.new
- pdf.line(x0,y0,x1,y1)
+ @pdf.line(x0,y0,x1,y1)
+ @pdf.finish
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@output.string, receiver)
# the begin_new_subpath command specifies the start of the line, append line specifies the end
receiver.count(:begin_new_subpath).should eql(1)
receiver.count(:append_line).should eql(1)
receiver.first_occurance_of(:begin_new_subpath)[:args].should eql([x0.to_f, 741.89])
@@ -21,15 +24,15 @@
specify "should be able to draw a single line onto the canvas with a width of 5" do
x0 = y0 = 100
x1 = y1 = 200
width = 5
- pdf = PDF::Wrapper.new
- pdf.line(x0,y0,x1,y1, :line_width => width)
+ @pdf.line(x0,y0,x1,y1, :line_width => width)
+ @pdf.finish
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@output.string, receiver)
# the begin_new_subpath command specifies the start of the line, append line specifies the end
receiver.count(:set_line_width).should eql(1)
receiver.count(:begin_new_subpath).should eql(1)
receiver.count(:append_line).should eql(1)
@@ -41,15 +44,15 @@
specify "should be able to draw a cubic bezier spline onto the canvas"
specify "should be able to draw an empty rectangle onto the canvas" do
x = y = 100
w = h = 200
- pdf = PDF::Wrapper.new
- pdf.rectangle(x,y,w,h)
+ @pdf.rectangle(x,y,w,h)
+ @pdf.finish
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@output.string, receiver)
# the begin_new_subpath command specifies the start of the line, append line specifies the end
callbacks = receiver.all(:append_rectangle)
callbacks.size.should eql(2)
# don't care about the first rectangel, it just goes around the outside of the page
@@ -59,15 +62,15 @@
specify "should be able to draw an empty rectangle onto the canvas with a line width of 5" do
x = y = 100
w = h = 200
width = 5
- pdf = PDF::Wrapper.new
- pdf.rectangle(x,y,w,h, :line_width => width)
+ @pdf.rectangle(x,y,w,h, :line_width => width)
+ @pdf.finish
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@output.string, receiver)
# ensure the line width was set correctly
receiver.count(:set_line_width).should eql(1)
receiver.first_occurance_of(:set_line_width)[:args].should eql([width.to_f])
@@ -83,14 +86,14 @@
=begin
do
x = y = 100
w = h = 200
pdf = PDF::Wrapper.new
- pdf.rectangle(x,y,w,h, :fill_color => :red)
+ @pdf.rectangle(x,y,w,h, :fill_color => :red)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -99,14 +102,14 @@
do
x = y = 100
w = h = 200
r = 5
pdf = PDF::Wrapper.new
- pdf.rectangle(x,y,w,h,:radius => r)
+ @pdf.rectangle(x,y,w,h,:radius => r)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -116,14 +119,14 @@
x = y = 100
w = h = 200
r = 5
w = 5
pdf = PDF::Wrapper.new
- pdf.rounded_rectangle(x,y,w,h, :radius => r, :line_width => w)
+ @pdf.rounded_rectangle(x,y,w,h, :radius => r, :line_width => w)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -132,14 +135,14 @@
do
x = y = 100
w = h = 200
r = 5
pdf = PDF::Wrapper.new
- pdf.rounded_rectangle(x,y,w,h, :radius => r, :fill_color => :red)
+ @pdf.rounded_rectangle(x,y,w,h, :radius => r, :fill_color => :red)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -148,14 +151,14 @@
do
x = 100
y = 200
r = 5
pdf = PDF::Wrapper.new
- pdf.circle(x,y,r)
+ @pdf.circle(x,y,r)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -165,14 +168,14 @@
x = 100
y = 200
r = 5
w = 5
pdf = PDF::Wrapper.new
- pdf.circle(x,y,r, :line_width => w)
+ @pdf.circle(x,y,r, :line_width => w)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
@@ -181,13 +184,13 @@
do
x = 100
y = 200
r = 5
pdf = PDF::Wrapper.new
- pdf.circle(x,y,r, :fill_color => :red)
+ @pdf.circle(x,y,r, :fill_color => :red)
receiver = PDF::Reader::RegisterReceiver.new
- reader = PDF::Reader.string(pdf.render, receiver)
+ reader = PDF::Reader.string(@pdf.render, receiver)
# TODO: test for the appropriate pattern of callbacks
end
=end
end