Move stderr option to config
This is another option we missed when moving things into the Configuration object. I had to make substantial changes to the tests, because many of them were using the stderr option for new connections. However, I think the end result is actually cleaner.
This commit is contained in:
parent
e465afba05
commit
15fe888069
|
@ -27,6 +27,7 @@ module Capybara
|
||||||
attr_accessor :debug
|
attr_accessor :debug
|
||||||
attr_writer :ignore_ssl_errors
|
attr_writer :ignore_ssl_errors
|
||||||
attr_accessor :proxy
|
attr_accessor :proxy
|
||||||
|
attr_accessor :stderr
|
||||||
attr_accessor :timeout
|
attr_accessor :timeout
|
||||||
attr_writer :skip_image_loading
|
attr_writer :skip_image_loading
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ module Capybara
|
||||||
@ignore_ssl_errors = false
|
@ignore_ssl_errors = false
|
||||||
@proxy = nil
|
@proxy = nil
|
||||||
@skip_image_loading = false
|
@skip_image_loading = false
|
||||||
|
@stderr = $stderr
|
||||||
@timeout = -1
|
@timeout = -1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,6 +92,7 @@ module Capybara
|
||||||
ignore_ssl_errors: ignore_ssl_errors?,
|
ignore_ssl_errors: ignore_ssl_errors?,
|
||||||
proxy: proxy,
|
proxy: proxy,
|
||||||
skip_image_loading: skip_image_loading?,
|
skip_image_loading: skip_image_loading?,
|
||||||
|
stderr: stderr,
|
||||||
timeout: timeout
|
timeout: timeout
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1826,13 +1826,14 @@ describe Capybara::Webkit::Driver do
|
||||||
|
|
||||||
context "no response app" do
|
context "no response app" do
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
driver_for_html(<<-HTML, browser: browser)
|
driver_for_html(<<-HTML)
|
||||||
<html><body>
|
<html><body>
|
||||||
<form action="/error"><input type="submit"/></form>
|
<form action="/error"><input type="submit"/></form>
|
||||||
</body></html>
|
</body></html>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let!(:connection) { fork_connection }
|
||||||
before { visit("/") }
|
before { visit("/") }
|
||||||
|
|
||||||
it "raises a webkit error for the requested url" do
|
it "raises a webkit error for the requested url" do
|
||||||
|
@ -1855,9 +1856,6 @@ describe Capybara::Webkit::Driver do
|
||||||
connection.stub(:puts)
|
connection.stub(:puts)
|
||||||
connection.stub(:print)
|
connection.stub(:print)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
|
||||||
let(:connection) { Capybara::Webkit::Connection.new }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "custom font app" do
|
context "custom font app" do
|
||||||
|
@ -2727,7 +2725,7 @@ CACHE MANIFEST
|
||||||
describe "url whitelisting", skip_if_offline: true do
|
describe "url whitelisting", skip_if_offline: true do
|
||||||
it_behaves_like "output writer" do
|
it_behaves_like "output writer" do
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
driver_for_html(<<-HTML, browser: browser)
|
driver_for_html(<<-HTML)
|
||||||
<<-HTML
|
<<-HTML
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
|
@ -2890,7 +2888,7 @@ CACHE MANIFEST
|
||||||
describe "logger app" do
|
describe "logger app" do
|
||||||
it_behaves_like "output writer" do
|
it_behaves_like "output writer" do
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
driver_for_html("<html><body>Hello</body></html>", browser: browser)
|
driver_for_html("<html><body>Hello</body></html>")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "logs nothing in normal mode" do
|
it "logs nothing in normal mode" do
|
||||||
|
@ -3071,7 +3069,7 @@ CACHE MANIFEST
|
||||||
it_behaves_like "output writer" do
|
it_behaves_like "output writer" do
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
count = 0
|
count = 0
|
||||||
driver_for_app browser: browser do
|
driver_for_app do
|
||||||
get "/" do
|
get "/" do
|
||||||
count += 1
|
count += 1
|
||||||
<<-HTML
|
<<-HTML
|
||||||
|
@ -3116,17 +3114,15 @@ CACHE MANIFEST
|
||||||
|
|
||||||
context "when the driver process crashes" do
|
context "when the driver process crashes" do
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
driver_for_app browser: browser do
|
driver_for_app do
|
||||||
get "/" do
|
get "/" do
|
||||||
"<html><body>Relaunched</body></html>"
|
"<html><body>Relaunched</body></html>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
|
||||||
let(:connection) { Capybara::Webkit::Connection.new }
|
|
||||||
|
|
||||||
it "reports and relaunches on reset" do
|
it "reports and relaunches on reset" do
|
||||||
|
connection = fork_connection
|
||||||
Process.kill "KILL", connection.pid
|
Process.kill "KILL", connection.pid
|
||||||
expect { driver.reset! }.to raise_error(Capybara::Webkit::CrashError)
|
expect { driver.reset! }.to raise_error(Capybara::Webkit::CrashError)
|
||||||
visit "/"
|
visit "/"
|
||||||
|
@ -3162,6 +3158,8 @@ CACHE MANIFEST
|
||||||
conn.close
|
conn.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fork_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
@ -3195,9 +3193,7 @@ CACHE MANIFEST
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:driver) { driver_for_html("", browser: browser) }
|
let(:driver) { driver_for_html("") }
|
||||||
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
|
||||||
let(:connection) { Capybara::Webkit::Connection.new }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "skip image loading" do
|
context "skip image loading" do
|
||||||
|
@ -3300,6 +3296,8 @@ CACHE MANIFEST
|
||||||
config.use_proxy host: @host, port: @port, user: @user, pass: @pass
|
config.use_proxy host: @host, port: @port, user: @user, pass: @pass
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fork_connection
|
||||||
|
|
||||||
driver.visit @url
|
driver.visit @url
|
||||||
@proxy_requests.size.should eq 2
|
@proxy_requests.size.should eq 2
|
||||||
@request = @proxy_requests[-1]
|
@request = @proxy_requests[-1]
|
||||||
|
@ -3311,7 +3309,7 @@ CACHE MANIFEST
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:driver) do
|
let(:driver) do
|
||||||
driver_for_html("", browser: nil)
|
driver_for_html("")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses the HTTP proxy correctly" do
|
it "uses the HTTP proxy correctly" do
|
||||||
|
|
|
@ -5,7 +5,7 @@ require 'sinatra/base'
|
||||||
|
|
||||||
module AppRunner
|
module AppRunner
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :app, :app_host, :configuration
|
attr_accessor :app, :app_host, :browser, :configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.boot
|
def self.boot
|
||||||
|
@ -20,6 +20,8 @@ module AppRunner
|
||||||
[200, { 'Content-Type' => 'html', 'Content-Length' => 0 }, []]
|
[200, { 'Content-Type' => 'html', 'Content-Length' => 0 }, []]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.browser = $webkit_browser
|
||||||
|
|
||||||
self.configuration = Capybara::Webkit::Configuration.new
|
self.configuration = Capybara::Webkit::Configuration.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,15 +33,25 @@ module AppRunner
|
||||||
yield AppRunner.configuration
|
yield AppRunner.configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
def driver_for_app(*driver_args, &body)
|
def fork_connection
|
||||||
app = Class.new(ExampleApp, &body)
|
AppRunner.fork_connection
|
||||||
run_application app
|
|
||||||
build_driver(*driver_args)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def driver_for_html(html, *driver_args)
|
def self.fork_connection
|
||||||
|
connection = Capybara::Webkit::Connection.new(options)
|
||||||
|
AppRunner.browser = Capybara::Webkit::Browser.new(connection)
|
||||||
|
connection
|
||||||
|
end
|
||||||
|
|
||||||
|
def driver_for_app(&body)
|
||||||
|
app = Class.new(ExampleApp, &body)
|
||||||
|
run_application app
|
||||||
|
AppRunner.build_driver
|
||||||
|
end
|
||||||
|
|
||||||
|
def driver_for_html(html)
|
||||||
run_application_for_html html
|
run_application_for_html html
|
||||||
build_driver(*driver_args)
|
AppRunner.build_driver
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_for_app(&body)
|
def session_for_app(&body)
|
||||||
|
@ -54,16 +66,15 @@ module AppRunner
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.build_driver
|
||||||
|
Capybara::Webkit::Driver.new(app, options.merge(browser: browser))
|
||||||
def build_driver(overrides = {})
|
|
||||||
options = AppRunner.configuration.
|
|
||||||
to_hash.
|
|
||||||
merge(browser: $webkit_browser).
|
|
||||||
merge(overrides)
|
|
||||||
Capybara::Webkit::Driver.new(AppRunner.app, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.options
|
||||||
|
configuration.to_hash
|
||||||
|
end
|
||||||
|
private_class_method :options
|
||||||
|
|
||||||
def self.included(example_group)
|
def self.included(example_group)
|
||||||
example_group.class_eval do
|
example_group.class_eval do
|
||||||
before { AppRunner.reset }
|
before { AppRunner.reset }
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
shared_examples_for "output writer" do
|
shared_examples_for "output writer" do
|
||||||
before do
|
before do
|
||||||
@read, @write = IO.pipe
|
@read, @write = IO.pipe
|
||||||
end
|
configure { |config| config.stderr = @write }
|
||||||
|
fork_connection
|
||||||
let(:browser) do
|
|
||||||
connection = Capybara::Webkit::Connection.new(:stderr => @write)
|
|
||||||
Capybara::Webkit::Browser.new(connection)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:stderr) do
|
let(:stderr) do
|
||||||
|
|
Loading…
Reference in New Issue