lib/capybara/driver/terminus.rb in terminus-0.3.0 vs lib/capybara/driver/terminus.rb in terminus-0.4.0
- old
+ new
@@ -1,26 +1,37 @@
class Capybara::Driver::Terminus < Capybara::Driver::Base
attr_reader :options
+ NULL_APP = lambda do |env|
+ [200, {'Content-Type' => 'text/html'}, ['']]
+ end
+
def initialize(app = nil, options = {})
- raise ArgumentError.new if app.nil?
-
- @app = Terminus::Proxy[app]
+ @app = Terminus::Proxy[app || NULL_APP]
@options = options
@rack_server = Capybara::Server.new(@app)
@rack_server.boot
+ sleep(0.1) until Terminus.server_running?(@rack_server)
end
def find(xpath)
browser.find(xpath, self)
end
+ def invalid_element_errors
+ [::Terminus::ObsoleteElementError]
+ end
+
def visit(path)
browser.visit(@rack_server.url(path))
end
+ def wait?
+ true
+ end
+
extend Forwardable
def_delegators :browser, :body,
:current_url,
:evaluate_script,
:execute_script,
@@ -33,34 +44,34 @@
current_browser = browser
Terminus.browser = browser.id + '/' + name
yield
Terminus.browser = current_browser
end
+ alias :within_frame :within_window
- def within_frame(name)
- frame_src = browser.frame_src(name)
- frame = browser.frames.find do |frame|
- frame.current_url == frame_src or
- frame.current_path == frame_src
- end
- current_browser = browser
- Terminus.browser = frame
- yield
- Terminus.browser = current_browser
- end
-
private
def browser
Terminus.ensure_browsers
Terminus.browser
end
end
-# Capybara 0.3.9 looks in the Capybara::Driver namespace for
-# appropriate drivers. 0.4 uses this registration API instead.
+# Capybara 0.3.9 looks in the Capybara::Driver namespace for appropriate
+# drivers. 0.4 uses this registration API instead.
if Capybara.respond_to?(:register_driver)
Capybara.register_driver :terminus do |app|
Capybara::Driver::Terminus.new(app)
end
+end
+
+# We use WEBrick to boot the test app, because if we use Thin (the default) the
+# slow response used to test Ajax resynchronization blocks the event loop. This
+# stops Terminus receiving messages and causes false positives: the client is
+# not really waiting for Ajax to complete, it's just having its messages blocked
+# because EventMachine is frozen.
+
+Capybara.server do |app, port|
+ handler = Rack::Handler.get('webrick')
+ handler.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
end