Skip to content

Instantly share code, notes, and snippets.

@cfitz
Last active September 22, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfitz/c65f6ff6fd0674a50c34e93afffce834 to your computer and use it in GitHub Desktop.
Save cfitz/c65f6ff6fd0674a50c34e93afffce834 to your computer and use it in GitHub Desktop.
example integration test using rack-cas, capybara, and minitest
# 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