mileszs
5/6/2014 - 12:34 PM

capyconsole.rake

desc "Launch a Capybara session in a console"
task capyconsole: :environment do
  require "capybara"
  require "pry"

  driver = case ENV.fetch('DRIVER', 'phantomjs')
  when 'phantomjs'
    require "capybara/poltergeist"

    Capybara.register_driver :poltergeist_debug do |app|
      Capybara::Poltergeist::Driver.new(app, inspector: true)
    end

    :poltergeist_debug
  else
    raise "No idea what #{ENV['DRIVER']} is"
  end

  Capybara.run_server = false
  Capybara.javascript_driver = driver

  session = Capybara::Session.new(driver)
  session.visit("about:blank")

  pry(session)
end