Skip to content
Newer
Older
100644 74 lines (58 sloc) 1.66 KB
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
1 require 'spec_helper'
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored Jul 8, 2012
2 require 'capybara/webkit/driver'
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
3 require 'mini_magick'
4
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored Jul 8, 2012
5 describe Capybara::Webkit::Driver, "rendering an image" do
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
6 include AppRunner
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
7
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
8 let(:driver) do
327ae85 @jferris Use sinatra for test apps
jferris authored Jul 8, 2012
9 driver_for_html(<<-HTML)
10 <html>
11 <body>
12 <h1>Hello World</h1>
13 </body>
14 </html>
15 HTML
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
16 end
17
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
18 before(:each) do
19 # Set up the tmp directory and file name
20 tmp_dir = File.join(PROJECT_ROOT, 'tmp')
21 FileUtils.mkdir_p tmp_dir
22 @file_name = File.join(tmp_dir, 'render-test.png')
23 driver.visit '/'
24 end
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
25
26 def render(options)
27 FileUtils.rm_f @file_name
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
28 driver.render @file_name, options
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
29
30 @image = MiniMagick::Image.open @file_name
31 end
32
33 context "with default options" do
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
34 before { render({}) }
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
35
36 it "should be a PNG" do
37 @image[:format].should == "PNG"
38 end
39
40 it "width default to 1000px (with 15px less for the scrollbar)" do
09b6940 @mike-burns Fuzzier width checking for the PNG rendering, to handle inconsistenci…
mike-burns authored Jul 5, 2011
41 @image[:width].should be < 1001
42 @image[:width].should be > 1000-17
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
43 end
44
45 it "height should be at least 10px" do
46 @image[:height].should >= 10
47 end
48 end
49
50 context "with dimensions set larger than necessary" do
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
51 before { render(:width => 500, :height => 400) }
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
52
53 it "width should match the width given" do
54 @image[:width].should == 500
55 end
56
57 it "height should match the height given" do
58 @image[:height].should > 10
59 end
60 end
61
62 context "with dimensions set smaller than the document's default" do
265a7da @jferris Improve pattern of testing driver against a rack app
jferris authored Jul 8, 2012
63 before { render(:width => 50, :height => 10) }
1787324 @nicholaides Adding ability to render webpage to a PNG
nicholaides authored May 26, 2011
64
65 it "width should be greater than the width given" do
66 @image[:width].should > 50
67 end
68
69 it "height should be greater than the height given" do
70 @image[:height].should > 10
71 end
72 end
73 end
Something went wrong with that request. Please try again.