Last active
December 11, 2015 08:29
-
-
Save luxflux/4573914 to your computer and use it in GitHub Desktop.
Javascript tests with RSpec, Capybara and PhantomJS. An example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group :test do | |
gem 'capybara' | |
gem 'poltergeist' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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