Parent

Included Modules

Webrat::Session

Attributes

adapter[RW]
current_url[R]
elements[R]

Public Class Methods

new(adapter = nil) click to toggle source
# File lib/webrat/core/session.rb, line 72
def initialize(adapter = nil)
  @adapter         = adapter
  @http_method     = :get
  @data            = {}
  @default_headers = {}
  @custom_headers  = {}
  @current_url     = nil
  reset
end

Public Instance Methods

automate() click to toggle source
# File lib/webrat/core/session.rb, line 248
def automate
  return unless Webrat.configuration.mode == :selenium
  yield
end
basic_auth(user, pass) click to toggle source
# File lib/webrat/core/session.rb, line 104
def basic_auth(user, pass)
  encoded_login = ["#{user}:#{pass}"].pack("m*").gsub(/\n/, '')
  header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
end
check_for_infinite_redirects() click to toggle source
# File lib/webrat/core/session.rb, line 138
def check_for_infinite_redirects
  if current_url == response_location
    @_identical_redirect_count ||= 0
    @_identical_redirect_count += 1
  end

  if infinite_redirect_limit_exceeded?
    raise InfiniteRedirectError.new("#{Webrat.configuration.infinite_redirect_limit} redirects to the same URL (#{current_url.inspect})")
  end
end
dom() click to toggle source
# File lib/webrat/core/session.rb, line 235
def dom
  page_scope.dom
end
header(key, value) click to toggle source
# File lib/webrat/core/session.rb, line 96
def header(key, value)
  @custom_headers[key] = value
end
http_accept(mime_type) click to toggle source
# File lib/webrat/core/session.rb, line 100
def http_accept(mime_type)
  header('Accept', Webrat::MIME.mime_type(mime_type))
end
infinite_redirect_limit_exceeded?() click to toggle source
# File lib/webrat/core/session.rb, line 149
def infinite_redirect_limit_exceeded?
   Webrat.configuration.infinite_redirect_limit &&
   (@_identical_redirect_count || 0) > Webrat.configuration.infinite_redirect_limit
end
internal_redirect?() click to toggle source
# File lib/webrat/core/session.rb, line 162
def internal_redirect?
  return false unless redirect?
  #should keep internal_redirects if the subdomain changes
  current_host_domain = current_host.split('.')[-2..-1].join('.') rescue current_host
  response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host
  current_host_domain == response_location_host_domain
end
redirected_to() click to toggle source

easy helper to pull out where we were redirected to

# File lib/webrat/core/session.rb, line 171
def redirected_to
  redirect? ? response_location : nil
end
reload() click to toggle source

Reloads the last page requested. Note that this will resubmit forms and their data.

# File lib/webrat/core/session.rb, line 185
def reload
  request_page(@current_url, @http_method, @data)
end
simulate() click to toggle source
# File lib/webrat/core/session.rb, line 243
def simulate
  return if Webrat.configuration.mode == :selenium
  yield
end
visit(url = nil, http_method = :get, data = {}) click to toggle source

Issues a GET request for a page, follows any redirects, and verifies the final page load was successful.

Example:

visit "/"
# File lib/webrat/core/session.rb, line 216
def visit(url = nil, http_method = :get, data = {})
  request_page(url, http_method, data)
end
within(selector) click to toggle source
# File lib/webrat/core/session.rb, line 204
def within(selector)
  scopes.push(Scope.from_scope(self, current_scope, selector))
  ret = yield(current_scope)
  scopes.pop
  return ret
end
xml_content_type?() click to toggle source
# File lib/webrat/core/session.rb, line 239
def xml_content_type?
  false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.