public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
Surprise!  Kids, you're going to need to learn test-spec and mocha.  If you hate 
this idea, we can head back to Test::Unit entirely, but I'm not going to be 
jimmied around by Ruby 1.9 incompatibilities in RSpec.  Alternative testing 
frameworks FTW
sandal (author)
Thu Aug 07 10:13:05 -0700 2008
commit  e1dde4995687392bcf3c43c23e07a05abbc85644
tree    0cb8ba51e5e17c050b5ef43560b9574f077e4556
parent  66fd2f19be6455199939d1b5db65fbcc7ea0c661
...
101
102
103
104
105
 
 
106
107
108
...
101
102
103
 
 
104
105
106
107
108
0
@@ -101,8 +101,8 @@ module Prawn
0
               end
0
             end
0
           else
0
-            string.unpack("U*").inject(0) do |s,r|
0
-              s + latin_glyphs_table[r]
0
+            string.unpack("U*").inject(0) do |s,r| 
0
+              s + latin_glyphs_table[r].to_i
0
             end * scale
0
           end
0
         end
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ describe "A bounding box" do
0
       @pdf.text "The rain in Spain falls mainly on the plains."
0
     end
0
     
0
-    @pdf.y.should be_close(458.384, 0.001)
0
+    @pdf.y.should.be.close 458.384, 0.001 
0
   end
0
 
0
 end
...
49
50
51
52
 
53
54
55
...
65
66
67
68
 
69
70
71
...
77
78
79
80
81
 
 
82
83
84
...
89
90
91
92
93
 
 
94
95
96
...
156
157
158
159
160
 
 
161
162
163
...
170
171
172
173
 
174
175
176
...
49
50
51
 
52
53
54
55
...
65
66
67
 
68
69
70
71
...
77
78
79
 
 
80
81
82
83
84
...
89
90
91
 
 
92
93
94
95
96
...
156
157
158
 
 
159
160
161
162
163
...
170
171
172
 
173
174
175
176
0
@@ -49,7 +49,7 @@ describe "When beginning each new page" do
0
   it "should execute the lambda specified by on_page_start" do
0
     on_start = mock("page_start_proc")
0
 
0
-    on_start.should_receive(:[]).exactly(3).times
0
+    on_start.expects(:[]).times(3)
0
    
0
     pdf = Prawn::Document.new(:on_page_start => on_start)
0
     pdf.start_new_page 
0
@@ -65,7 +65,7 @@ describe "When ending each page" do
0
 
0
     on_end = mock("page_end_proc")
0
 
0
-    on_end.should_receive(:[]).exactly(3).times
0
+    on_end.expects(:[]).times(3)
0
 
0
     pdf = Prawn::Document.new(:on_page_stop => on_end)
0
     pdf.start_new_page
0
@@ -77,8 +77,8 @@ describe "When ending each page" do
0
 
0
     pdf = Prawn::Document.new(:compress => false)
0
     content_stub = pdf.ref({})
0
-    content_stub.stub!(:compress_stream).and_return(true)
0
-    content_stub.should_not_receive(:compress_stream)
0
+    content_stub.stubs(:compress_stream).returns(true)
0
+    content_stub.expects(:compress_stream).never
0
 
0
     pdf.instance_variable_set("@page_content", content_stub)
0
     pdf.text "Hi There" * 20
0
@@ -89,8 +89,8 @@ describe "When ending each page" do
0
 
0
     pdf = Prawn::Document.new(:compress => true)
0
     content_stub = pdf.ref({})
0
-    content_stub.stub!(:compress_stream).and_return(true)
0
-    content_stub.should_receive(:compress_stream).exactly(1).times
0
+    content_stub.stubs(:compress_stream).returns(true)
0
+    content_stub.expects(:compress_stream).once
0
 
0
     pdf.instance_variable_set("@page_content", content_stub)
0
     pdf.text "Hi There" * 20
0
@@ -156,8 +156,8 @@ describe "The mask() feature" do
0
     @pdf.mask(:y, :line_width) do
0
       @pdf.y = y + 1
0
       @pdf.line_width = line_width + 1
0
-      @pdf.y.should_not == y
0
-      @pdf.line_width.should_not == line_width
0
+      @pdf.y.should.not == y
0
+      @pdf.line_width.should.not == line_width
0
     end
0
     @pdf.y.should == y
0
     @pdf.line_width.should == line_width 
0
@@ -170,7 +170,7 @@ describe "The render() feature" do
0
       @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
0
       @pdf.line [100,100], [200,200]
0
       str = @pdf.render
0
-      str.encoding.to_s.should eql("ASCII-8BIT")
0
+      str.encoding.to_s.should == "ASCII-8BIT"
0
     end
0
   end
0
 end
...
230
231
232
233
234
 
 
235
236
237
238
239
240
241
 
 
242
243
244
245
246
247
248
 
249
250
...
230
231
232
 
 
233
234
235
236
237
238
239
 
 
240
241
242
243
244
245
246
247
 
248
249
250
0
@@ -230,21 +230,21 @@ describe "When using painting shortcuts" do
0
   before(:each) { create_pdf }
0
  
0
   it "should convert stroke_some_method(args) into some_method(args); stroke" do
0
-    @pdf.should_receive(:line_to).with([100,100])
0
-    @pdf.should_receive(:stroke)
0
+    @pdf.expects(:line_to).with([100,100])
0
+    @pdf.expects(:stroke)
0
     
0
     @pdf.stroke_line_to [100,100]
0
   end  
0
   
0
   it "should convert fill_some_method(args) into some_method(args); fill" do
0
-    @pdf.should_receive(:line_to).with([100,100]) 
0
-    @pdf.should_receive(:fill)
0
+    @pdf.expects(:line_to).with([100,100]) 
0
+    @pdf.expects(:fill)
0
     
0
     @pdf.fill_line_to [100,100]
0
   end
0
   
0
   it "should not break method_missing" do
0
     lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
0
-      should raise_error(NoMethodError) 
0
+      should.raise(NoMethodError) 
0
   end
0
 end
...
33
34
35
36
 
37
38
39
 
40
41
42
...
33
34
35
 
36
37
38
 
39
40
41
42
0
@@ -33,10 +33,10 @@ describe "the image() function" do
0
     images = observer(ImageObserver)
0
 
0
     # there should be 2 images in the page resources
0
-    images.page_xobjects.first.size.should eql(2)
0
+    images.page_xobjects.first.size.should == 2
0
 
0
     # but only 1 image xobject
0
-    @output.scan(/\/Type \/XObject/).size.should eql(1)
0
+    @output.scan(/\/Type \/XObject/).size.should == 1
0
   end  
0
 end
0
 
...
16
17
18
19
20
21
22
 
 
 
 
23
24
25
...
16
17
18
 
 
 
 
19
20
21
22
23
24
25
0
@@ -16,10 +16,10 @@ describe "When reading a JPEG file" do
0
   it "should read the basic attributes correctly" do
0
     jpg = Prawn::Images::JPG.new(@img_data)
0
     
0
-    jpg.width.should eql(604)
0
-    jpg.height.should eql(453)
0
-    jpg.bits.should eql(8)
0
-    jpg.channels.should eql(3)
0
+    jpg.width.should == 604
0
+    jpg.height.should == 453
0
+    jpg.bits.should == 8
0
+    jpg.channels.should == 3
0
   end
0
 end
0
 
...
48
49
50
51
 
52
53
54
...
91
92
93
94
 
95
96
97
...
48
49
50
 
51
52
53
54
...
91
92
93
 
94
95
96
97
0
@@ -48,7 +48,7 @@ describe "PDF Object Serialization" do
0
  
0
   it "should not convert a whitespace containing Ruby symbol to a PDF name" do
0
     lambda { Prawn::PdfObject(:"My Symbol With Spaces") }.
0
-      should raise_error(Prawn::Errors::FailedObjectConversion)
0
+      should.raise(Prawn::Errors::FailedObjectConversion)
0
   end    
0
   
0
   it "should convert a Ruby array to PDF Array when inside a content stream" do
0
@@ -91,7 +91,7 @@ describe "PDF Object Serialization" do
0
   
0
   it "should not allow keys other than strings or symbols for PDF dicts" do
0
     lambda { Prawn::PdfObject(:foo => :bar, :baz => :bang, 1 => 4) }.
0
-      should raise_error(Prawn::Errors::FailedObjectConversion) 
0
+      should.raise(Prawn::Errors::FailedObjectConversion) 
0
   end  
0
   
0
   it "should convert a Prawn::Reference to a PDF indirect object reference" do
...
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
27
28
29
30
31
32
 
33
34
35
...
17
18
19
 
 
 
 
 
 
 
20
21
22
23
24
25
26
27
28
29
30
31
 
32
33
34
35
0
@@ -17,19 +17,19 @@ describe "When reading an RGB PNG file" do
0
   it "should read the attributes from the header chunk correctly" do
0
     png = Prawn::Images::PNG.new(@img_data)
0
     
0
-    png.width.should eql(258)
0
-    png.height.should eql(105)
0
-    png.bits.should eql(8)
0
-    png.color_type.should eql(2)
0
-    png.compression_method.should eql(0)
0
-    png.filter_method.should eql(0)
0
-    png.interlace_method.should eql(0)
0
+    png.width.should == 258
0
+    png.height.should == 105
0
+    png.bits.should == 8
0
+    png.color_type.should == 2
0
+    png.compression_method.should == 0
0
+    png.filter_method.should == 0
0
+    png.interlace_method.should == 0
0
   end
0
 
0
   it "should read the image data chunk correctly" do
0
     png = Prawn::Images::PNG.new(@img_data)
0
     data = File.open(@data_filename, "rb") { |f| f.read }
0
-    png.img_data.should eql(data)
0
+    png.img_data.should == data
0
   end  
0
 end
0
 
...
35
36
37
38
39
 
 
 
40
41
...
35
36
37
 
 
38
39
40
41
42
0
@@ -35,7 +35,8 @@ describe "A Reference object" do
0
     cref << "Hi There " * 20
0
     cref.compress_stream
0
 
0
-    (cref.stream.size < ref.stream.size).should be_true
0
-    cref.data[:Filter].should eql(:FlateDecode)
0
+    assert cref.stream.size < ref.stream.size, 
0
+      "compressed stream expected to be smaller than source but wasn't"
0
+    cref.data[:Filter].should == :FlateDecode
0
   end
0
 end
...
3
4
5
6
 
 
7
8
9
...
3
4
5
 
6
7
8
9
10
0
@@ -3,7 +3,8 @@
0
 puts "Prawn specs: Running on Ruby Version: #{RUBY_VERSION}"
0
 
0
 require "rubygems"
0
-require "spec"
0
+require "test/spec"                                                
0
+require "mocha"
0
 $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') 
0
 require "prawn"
0
 gem 'pdf-reader', ">=0.7.3"
...
72
73
74
75
 
76
77
78
...
139
140
141
142
 
143
144
145
...
72
73
74
 
75
76
77
78
...
139
140
141
 
142
143
144
145
0
@@ -72,7 +72,7 @@ describe "A table's width" do
0
 
0
     font_height = pdf.font_metrics.font_height(12)
0
 
0
-    table_height.should be_close(num_rows*font_height + 2*vpad*num_rows + vpad, 0.001)
0
+    table_height.should.be.close(num_rows*font_height + 2*vpad*num_rows + vpad, 0.001)
0
   end
0
 
0
 end
0
@@ -139,7 +139,7 @@ describe "A table's content" do
0
       data = [["foo","bar"],["baz",""]]
0
       @pdf = Prawn::Document.new
0
       @pdf.table(data)
0
-    }.should_not raise_error
0
+    }.should.not.raise
0
   end
0
     
0
 end
...
71
72
73
74
 
75
76
77
78
79
 
80
81
82
...
154
155
156
157
158
159
 
 
 
160
161
162
163
 
164
165
166
...
168
169
170
171
 
172
173
174
175
176
 
 
177
178
179
180
181
182
 
183
184
185
186
 
187
188
189
...
71
72
73
 
74
75
76
77
78
 
79
80
81
82
...
154
155
156
 
 
 
157
158
159
160
161
162
 
163
164
165
166
...
168
169
170
 
171
172
173
174
 
 
175
176
177
178
179
180
181
 
182
183
184
185
 
186
187
188
189
0
@@ -71,12 +71,12 @@ describe "when drawing text" do
0
      position = @pdf.y
0
      @pdf.text "Foo"
0
 
0
-     @pdf.y.should be_close(position - @pdf.font_metrics.font_height(12),
0
+     @pdf.y.should.be.close(position - @pdf.font_metrics.font_height(12),
0
                             0.0001)
0
 
0
      position = @pdf.y
0
      @pdf.text "Foo\nBar\nBaz"
0
-     @pdf.y.should be_close(position - 3*@pdf.font_metrics.font_height(12),
0
+     @pdf.y.should.be.close(position - 3*@pdf.font_metrics.font_height(12),
0
                             0.0001)
0
    end
0
    
0
@@ -154,13 +154,13 @@ describe "when drawing text" do
0
      @pdf.text "Blaz", :at => [150,150]
0
      text = observer(FontObserver)
0
 
0
-     text.page_fonts.size.should eql(2)
0
-     text.page_fonts[0][0].should eql(:Helvetica)
0
-     text.page_fonts[1][0].should eql(:Helvetica)
0
+     text.page_fonts.size.should  == 2
0
+     text.page_fonts[0][0].should == :Helvetica
0
+     text.page_fonts[1][0].should == :Helvetica
0
    end
0
    
0
    it "should raise an exception when an unknown font is used" do
0
-     lambda { @pdf.font "Pao bu" }.should raise_error(Prawn::Errors::UnknownFont)
0
+     lambda { @pdf.font "Pao bu" }.should.raise(Prawn::Errors::UnknownFont)
0
    end
0
 
0
    if "spec".respond_to?(:encode!)
0
@@ -168,22 +168,22 @@ describe "when drawing text" do
0
      it "should raise an exception when a utf-8 incompatible string is rendered" do
0
        str = "Blah \xDD"
0
        str.force_encoding("ASCII-8BIT")
0
-       lambda { @pdf.text str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
0
+       lambda { @pdf.text str }.should.raise(Prawn::Errors::IncompatibleStringEncoding)
0
      end
0
      it "should not raise an exception when a shift-jis string is rendered" do 
0
        datafile = "#{Prawn::BASEDIR}/data/shift_jis_text.txt"  
0
-       sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets } 
0
-       lambda { @pdf.text sjis_str }.should_not raise_error(Prawn::Errors::IncompatibleStringEncoding)
0
+       sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }        
0
+       lambda { @pdf.text sjis_str }.should.not.raise(Prawn::Errors::IncompatibleStringEncoding)
0
      end
0
    else
0
      # Handle non utf-8 string encodings in a sane way on non-M17N aware VMs
0
      it "should raise an exception when a corrupt utf-8 string is rendered" do
0
        str = "Blah \xDD"
0
-       lambda { @pdf.text str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
0
+       lambda { @pdf.text str }.should.raise(Prawn::Errors::IncompatibleStringEncoding)
0
      end
0
      it "should raise an exception when a shift-jis string is rendered" do
0
        sjis_str = File.read("#{Prawn::BASEDIR}/data/shift_jis_text.txt")
0
-       lambda { @pdf.text sjis_str }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
0
+       lambda { @pdf.text sjis_str }.should.raise(Prawn::Errors::IncompatibleStringEncoding)
0
      end
0
    end
0
 

Comments

tmm1 Thu Aug 07 11:30:05 -0700 2008
sandal Thu Aug 07 11:39:41 -0700 2008

tmm1: have you tried them on Ruby 1.9.0_3 ?

The reason I went for test/spec is that at its core, it’s just Test::Unit, so I didn’t expect it to break because of that.

The reason I went for Mocha is because I’m familiar with it :)

raggi Thu Aug 07 15:34:23 -0700 2008

Bacon + Facon + Autotest FTW! :)

I haven’t tested on 1.9 though, but give me a few :)

raggi Thu Aug 07 15:34:55 -0700 2008

Oh, and bacon for autotest just needs a .bacon in your test/ or spec/ dir.

raggi Thu Aug 07 15:37:00 -0700 2008

Seems to work on 1.9 in a few of my packages…

sandal Thu Aug 07 22:49:41 -0700 2008

raggi, if you want to fork and see if you can get things working, I’d be happy to look at it. I can’t really make any promises, but I’d consider moving to Bacon/Facon if that’s what ya’ll want.

Still, I see the benefit of Test::Unit compatibility… some of my friends are anti-BDD curmudgeons :)

raggi Fri Aug 08 03:54:07 -0700 2008

Understood re. BDD, the thing I love about bacon is it’s so light, and fast.

tmm1 Fri Aug 08 05:08:59 -0700 2008

We switched from rspec to bacon when we wanted to make Ramaze 1.9 compatible. IIRC, our bacon suite passes successfully on rubinius, jruby, mri and ruby 1.9.

thorny-sun Fri Aug 08 08:32:56 -0700 2008

tmm1—why did y’all make the switch—and how would you compare the two now?

tmm1 Fri Aug 08 14:30:35 -0700 2008

Because rspec was horribly broken on 1.9. I am a huge fan of bacon- its compact (only 300 lines!), simple (no magic, so it works on all the ruby implementations) and I prefer its syntax over rspec’s (imho, rspec is confusing and unintuitive)

raggi Sat Aug 09 01:52:51 -0700 2008

rspec is huge. moving to bacon cut a few of our test run times significantly.

There may be other reasons too, but the whole lightweight nature of bacon is very appealing.

Since patching for autotest support (now upstream), I’m using it all the time.

WRT this discussion, I have made a Prawn fork yesterday that uses bacon and facon. It did highlight a couple of areas where facon still needs work, some of which I completed in my facon fork.