-
-
Save 1gor/b592e7f6fad8be4549c32fcad6e719dc to your computer and use it in GitHub Desktop.
example integration test using rack-cas, capybara, and minitest
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
# to do integration tests with rack-cas, you have to use the FakeCas middleware, which intercepts CAS redirects and | |
# displays a "fake CAS" login form. This form will give a token to anything, but it has to be a user that's in the | |
# DB for the application to log the user in. | |
# To set this up, add | |
# config/environments/test.rb : | |
# config.rack_cas.fake_attributes = { 'admin': { "admin": true, "cas_directory_id": "admin", "name": "admin" } } | |
# test/test_helper.rb: | |
# require 'capybara/rails' | |
# require 'capybara/minitest' | |
# class ActionDispatch::IntegrationTest | |
# | |
# include Capybara::DSL | |
# include Capybara::Minitest::Assertions | |
# | |
# def teardown | |
# Capybara.reset_sessions! | |
# Capybara.use_default_driver | |
# end | |
# end | |
# test/integration/login_test.rb | |
require 'test_helper' | |
class LoginTest < ActionDispatch::IntegrationTest | |
test 'should be able to log in' do | |
visit "/" | |
fill_in 'username', with: 'admin' | |
fill_in 'password', with: 'any password' | |
click_button 'Login' | |
assert page.has_content?("Annual Staffing") | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment