Skip to content

Commit

Permalink
Improve pattern of testing driver against a rack app
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jul 8, 2012
1 parent 259a38f commit 265a7da
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 437 deletions.
30 changes: 14 additions & 16 deletions spec/driver_rendering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
require 'mini_magick'

describe Capybara::Webkit::Driver, "rendering an image" do
include AppRunner

before(:all) do
# Set up the tmp directory and file name
tmp_dir = File.join(PROJECT_ROOT, 'tmp')
FileUtils.mkdir_p tmp_dir
@file_name = File.join(tmp_dir, 'render-test.png')

app = lambda do |env|
let(:driver) do
driver_for_app do |env|
body = <<-HTML
<html>
<body>
Expand All @@ -22,22 +18,25 @@
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
[body]]
end

@driver = Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
@driver.visit("/hello/world?success=true")
end

after(:all) { @driver.reset! }
before(:each) do
# Set up the tmp directory and file name
tmp_dir = File.join(PROJECT_ROOT, 'tmp')
FileUtils.mkdir_p tmp_dir
@file_name = File.join(tmp_dir, 'render-test.png')
driver.visit '/'
end

def render(options)
FileUtils.rm_f @file_name
@driver.render @file_name, options
driver.render @file_name, options

@image = MiniMagick::Image.open @file_name
end

context "with default options" do
before(:all){ render({}) }
before { render({}) }

it "should be a PNG" do
@image[:format].should == "PNG"
Expand All @@ -54,7 +53,7 @@ def render(options)
end

context "with dimensions set larger than necessary" do
before(:all){ render(:width => 500, :height => 400) }
before { render(:width => 500, :height => 400) }

it "width should match the width given" do
@image[:width].should == 500
Expand All @@ -66,7 +65,7 @@ def render(options)
end

context "with dimensions set smaller than the document's default" do
before(:all){ render(:width => 50, :height => 10) }
before { render(:width => 50, :height => 10) }

it "width should be greater than the width given" do
@image[:width].should > 50
Expand All @@ -76,5 +75,4 @@ def render(options)
@image[:height].should > 10
end
end

end
Loading

0 comments on commit 265a7da

Please sign in to comment.