Skip to content

Instantly share code, notes, and snippets.

@luxflux
Last active December 11, 2015 08:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxflux/4573914 to your computer and use it in GitHub Desktop.
Save luxflux/4573914 to your computer and use it in GitHub Desktop.
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