Skip to content

Instantly share code, notes, and snippets.

@skamithi
Created June 4, 2013 12:14
Show Gist options
  • Save skamithi/5705473 to your computer and use it in GitHub Desktop.
Save skamithi/5705473 to your computer and use it in GitHub Desktop.
Capybara 2.0 / Rspec. Ability to launch browser when testing view specs. Not integration test..just regular view specs
#spec/support/capybara.rb
require 'capybara/rspec'
# Using chrome as browser to test in capybara.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
# Works with Capybara 2.0
def show_page(str)
path ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
path = File.expand_path(path, Capybara.save_and_open_page_path) if Capybara.save_and_open_page_path
FileUtils.mkdir_p(File.dirname(path))
File.open(path,'w') { |f| f.write(str) }
Launchy.open(path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment