Integrating Capybara with RSpec

Let's turn our irb session into an RSpec spec to finish our initial tour of Capybara. We'll put the contents into a file called smithsonian_spec.rb that looks like this:

require 'capybara/rspec' Capybara.current_driver = :selenium # switch to chrome based on environment variable. e.g.: # $ BROWSER=chrome rspec smithsonian_spec.rb if ENV['BROWSER'] == 'chrome' Capybara.register_driver :selenium do |app|, browser: :chrome) end # use poltergeist headless driver/browser based on environment variable, e.g. # $ BROWSER=poltergeist rspec smithsonian_spec.rb elseif ENV['BROWSER'] == 'poltergeist' puts "Using poltergeist headless driver..." require 'capybara/poltergeist' Capybara.register_driver ...

Get RSpec Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.