lib/capybara/driver/terminus.rb in terminus-0.2.0 vs lib/capybara/driver/terminus.rb in terminus-0.3.0

- old
+ new

@@ -1,39 +1,58 @@ -require 'forwardable' - class Capybara::Driver::Terminus < Capybara::Driver::Base - def initialize(app = nil) + attr_reader :options + + def initialize(app = nil, options = {}) raise ArgumentError.new if app.nil? - @app = app + + @app = Terminus::Proxy[app] + @options = options @rack_server = Capybara::Server.new(@app) - @rack_server.boot if Capybara.run_server + + @rack_server.boot end + def find(xpath) + browser.find(xpath, self) + end + def visit(path) - browser.visit @rack_server.url(path) + browser.visit(@rack_server.url(path)) end extend Forwardable def_delegators :browser, :body, - :current_path, :current_url, :evaluate_script, :execute_script, - :find, :reset!, - :source + :response_headers, + :source, + :status_code def within_window(name) current_browser = browser - Terminus.browser = {:name => name} + Terminus.browser = browser.id + '/' + name yield Terminus.browser = current_browser end + 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_browser + Terminus.ensure_browsers Terminus.browser end end # Capybara 0.3.9 looks in the Capybara::Driver namespace for