class Capybara::Poltergeist::Browser

Public Instance Methods

__command(name, *args)
Alias for: command
base_dir_for_url(url) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 13
def base_dir_for_url(url)
  dir = File.join(VCR::Archive::Persister.storage_location, URI(url).host)
  FileUtils.mkdir_p(dir)
  dir
end
command(name, *args) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 52
def command(name, *args)
  result = __command(name, *args)
  # we skip these methods because they are called a lot, don't cause the page
  # to change and having record round them slows things down quite a bit.
  return result if %w(tag_name visible property find body set_js_errors current_url status_code response_headers).include?(name)
  scraped_page_archive.record do
    save_request(body, get_details(current_url), current_url)
  end
  result
end
Also aliased as: __command
get_details(url) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 25
def get_details(url)
  {
    'request'  => {
      'method' => 'get', # assume this as no way to access it
      'uri'    => url,
    },
    'response' => {
      'status' => {
        'message' => status_code == 200 ? 'OK' : 'NOT OK',
        'code'    => status_code,
      },
      'date'   => [response_headers['Date']],
    },
  }
end
get_paths(url) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 19
def get_paths(url)
  base_path = File.join(base_dir_for_url(url), sha_url(url))

  ['.html', '.yml'].map { |x| base_path + x }
end
save_request(html, details, url) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 41
def save_request(html, details, url)
  html_path, yaml_path = get_paths(url)

  File.open(html_path, 'w') do |f|
    f.write(html)
  end
  File.open(yaml_path, 'w') do |f|
    f.write(YAML.dump(details))
  end
end
scraped_page_archive() click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 63
def scraped_page_archive
  @scraped_page_archive ||= ScrapedPageArchive.new(ScrapedPageArchive::GitStorage.new)
end
sha_url(url) click to toggle source
# File lib/scraped_page_archive/capybara.rb, line 9
def sha_url(url)
  Digest::SHA1.hexdigest url
end