Class: Capybara::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey-patches/capybara-patches.rb

Constant Summary collapse

DTD_REFS =
{
"-//W3C//DTD XHTML 1.0 Strict//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml1-strict.dtd", :type => :strict},
"-//W3C//DTD XHTML 1.0 Transitional//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml1-transitional.dtd", :type => :transitional}, 
"-//W3C//DTD XHTML+RDFa 1.0//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml-rdfa-1.dtd", :type => :rdfa}}

Instance Method Summary collapse

Instance Method Details



77
78
79
# File 'lib/monkey-patches/capybara-patches.rb', line 77

def add_cookie(attribs)
  driver.add_cookie(attribs)
end

Get the cookie with the given name

Parameters:

  • name (String)

    the name of the cookie

Returns:

  • (Hash, nil)

    the cookie, or nil if it wasn’t found.



65
66
67
# File 'lib/monkey-patches/capybara-patches.rb', line 65

def cookie_named(name)    
  driver.cookie_named(name)
end

#cookiesArray<Hash>

Get all cookies

Returns:

  • (Array<Hash>)

    list of cookies



55
56
57
# File 'lib/monkey-patches/capybara-patches.rb', line 55

def cookies    
  driver.cookies
end

#delete_all_cookiesObject



73
74
75
# File 'lib/monkey-patches/capybara-patches.rb', line 73

def delete_all_cookies
  driver.delete_all_cookies
end


69
70
71
# File 'lib/monkey-patches/capybara-patches.rb', line 69

def delete_cookie(cookie)
  driver.delete_cookie(cookie)
end

#validate(source) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/monkey-patches/capybara-patches.rb', line 86

def validate(source)
  doctype = source.scan(/\"(.*?)\"/)[0].to_s 

  if(DTD_REFS[doctype])
    dtd = DTD_REFS[doctype][:dtd]
    type = DTD_REFS[doctype][:type]
  end

  raise "RDFA Validation not currently supported due to issues in Nokogiri" if type == :rdfa

  source = source.gsub(/PUBLIC \"-\/\/W3C\/\/DTD XHTML.*?\/\/EN\" \"http:\/\/www.w3.org.*?\"/, "SYSTEM \"#{dtd}\"")
  doc = Nokogiri::XML(source) { |cfg|
    cfg.noent.dtdload.dtdvalid
  }
  errors = doc.validate
  raise "Page (#{current_url}) failed XHTML vaidation (or Nokogiri Freaked out...please manually check against W3C), errors:#{errors.to_s}" unless errors == []
end