Instantly share code, notes, and snippets.

@luxflux /Gemfile
Last active Dec 11, 2015

Embed
What would you like to do?
Javascript tests with RSpec, Capybara and PhantomJS. An example.
group :test do
gem 'capybara'
gem 'poltergeist'
end
RSpec.configure do |config|
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
Capybara.javascript_driver = :poltergeist
end
config.before :each do
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
end
config.after :each do
DatabaseCleaner.clean
end
end
require 'spec_helper'
describe 'search for a movie' do
let(:tmdb_movie) { tmdb_result }
it 'searches for the given title', js: true do
visit new_movie_path
page.should_not have_content('Star Wars Episode VII')
fill_in 'title', with: 'Star Wars'
page.should have_content('Star Wars Episode VII')
end
end
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
require 'database_cleaner'
RSpec.configure do |config|
config.use_transactional_fixtures = false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment