Skip to content

Instantly share code, notes, and snippets.

@ahx
Created November 12, 2010 16:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ahx/674284 to your computer and use it in GitHub Desktop.
Save ahx/674284 to your computer and use it in GitHub Desktop.
gaming_test.rb
# 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