Skip to content

Instantly share code, notes, and snippets.

@psahni
Forked from ahx/integration_test.rb
Created March 23, 2011 06:44
Show Gist options
  • Save psahni/882715 to your computer and use it in GitHub Desktop.
Save psahni/882715 to your computer and use it in GitHub Desktop.
# Example of how you can to use Capybara with plain Rails' integration tests and FactoryGirl (or plain MyModel.create…)
require 'test_helper'
require 'capybara'
require 'capybara/dsl'
require 'database_cleaner'
Capybara.app = Pardy::Application
Capybara.default_driver = :rack_test
DatabaseCleaner.strategy = :truncation
class GamingTest < ActionDispatch::IntegrationTest
include Capybara
# use_transactional_fixtures = false # DOES NOT WORK!
self.use_transactional_fixtures = false # DOES WORK! Damn it!
# … think this should be renamed and should definitely get some documentation love.
setup do
DatabaseCleaner.start
assert User.create! :name => 'player', :password => 'password', :password_confirmation => 'password', :email => 'player@example.com'
# or Factory(:user....)
end
teardown do
DatabaseCleaner.clean
end
test "login player" do
Capybara.current_driver = :selenium
visit login_path
fill_in 'user_email', :with => 'player@example.com'
fill_in 'user_password', :with => 'password'
click_button 'Sign in'
assert { current_path == root_path }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment