Skip to content

Commit

Permalink
Merge remote branch 'robholland/headers'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Mar 22, 2010
2 parents aa8adc3 + 64d115a commit bc688be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
20 changes: 13 additions & 7 deletions lib/capybara/driver/rack_test_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def merge_param!(params, key, value)
end

include ::Rack::Test::Methods
attr_reader :app, :html, :body
attr_reader :app

alias_method :response, :last_response
alias_method :request, :last_request
Expand All @@ -190,7 +190,6 @@ def visit(path, attributes = {})
return if path.gsub(/^#{current_path}/, '') =~ /^#/
get(path, attributes, env)
follow_redirects!
cache_body
end

def current_url
Expand All @@ -205,13 +204,20 @@ def submit(method, path, attributes)
path = current_path if not path or path.empty?
send(method, path, attributes, env)
follow_redirects!
cache_body
end

def find(selector)
html.xpath(selector).map { |node| Node.new(self, node) }
end


def body
@body ||= response.body
end

def html
@html ||= Nokogiri::HTML(body)
end

private

def build_rack_mock_session # :nodoc:
Expand Down Expand Up @@ -242,9 +248,9 @@ def env
env
end

def cache_body
@body = response.body
@html = Nokogiri::HTML(body)
def reset_cache
@body = nil
@html = nil
end

end
31 changes: 8 additions & 23 deletions lib/capybara/session.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'forwardable'
require 'capybara/wait_until'

module Capybara
class Session
extend Forwardable
include Searchable

DSL_METHODS = [
Expand Down Expand Up @@ -30,21 +32,12 @@ def driver
end
end

def cleanup!
driver.cleanup!
end

def current_url
driver.current_url
end

def response_headers
driver.response_headers
end

def visit(path)
driver.visit(path)
end
def_delegator :driver, :cleanup!
def_delegator :driver, :current_url
def_delegator :driver, :response_headers
def_delegator :driver, :visit
def_delegator :driver, :body
def_delegator :driver, :source

def click(locator)
msg = "no link or button '#{locator}' found"
Expand Down Expand Up @@ -102,14 +95,6 @@ def attach_file(locator, path)
locate(:xpath, XPath.file_field(locator), msg).set(path)
end

def body
driver.body
end

def source
driver.source
end

def within(kind, scope=nil)
kind, scope = Capybara.default_selector, kind unless scope
scope = XPath.from_css(scope) if kind == :css
Expand Down

0 comments on commit bc688be

Please sign in to comment.