Class: Capybara::Apparition::CookieJar

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/apparition/cookie_jar.rb

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ CookieJar

Returns a new instance of CookieJar.



7
8
9
# File 'lib/capybara/apparition/cookie_jar.rb', line 7

def initialize(browser)
  @browser = browser
end

Instance Method Details

#find(name, domain = URI.parse(@browser.current_url).host, path = URI.parse(@browser.current_url).path) ⇒ Object Also known as: []

def find(name, domain = nil, path = ‘/’)



12
13
14
15
16
17
18
19
# File 'lib/capybara/apparition/cookie_jar.rb', line 12

def find(name, domain = URI.parse(@browser.current_url).host, path = URI.parse(@browser.current_url).path)
  # sort by path length because more specific take precendence
  cookies.sort_by { |c| -c.path.length }.find do |cookie|
    cookie.name.casecmp(name).zero? &&
      (domain.nil? || match_domain?(cookie, domain)) &&
      (path.nil? || match_path?(cookie, path))
  end
end