Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created February 17, 2012 20:15
Show Gist options
  • Save chebyte/1855206 to your computer and use it in GitHub Desktop.
Save chebyte/1855206 to your computer and use it in GitHub Desktop.
test integrations with capybara, selenium and devise on RAILS
#test_helper.rb
....code....
class ActionController::TestCase
include Devise::TestHelpers
end
....code....
#test_integration_helper.rb
require File.expand_path("../../helper/test_helper", __FILE__)
require 'capybara/rails'
### capybara configuration ###
DatabaseCleaner.strategy = :truncation
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
include Warden::Test::Helpers
Warden.test_mode!
# Stop ActiveRecord from wrapping tests in transactions
self.use_transactional_fixtures = false
teardown do
DatabaseCleaner.clean # Truncate the database
Capybara.reset_sessions! # Forget the (simulated) browser state
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
# seed_file = File.join(Rails.root, "db", "seeds.rb")
# load(seed_file)
Warden.test_reset!
end
end
#test example
require File.expand_path("../../helper/test_integration_helper", __FILE__)
class AdvisorsTest < ActionDispatch::IntegrationTest
setup do
@user = Factory(:user)
sign_in(@user)
end
test 'shows users' do
visit "/users"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment