
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
test_session_manager
Advanced tools
Have you ever wanted to inject session information into a request in your Rails tests? Sure, best practices recommend you do so by first making a request to a resource that sets the desired session information for you, but sometimes...well, sometimes you just want a shortcut.
That's what the Test Session Manager gem does for you: lets your tests specify the contents of the session explicitly before making a request.
Add the "test_session_manager" gem to your Gemfile:
group :test do
gem 'test_session_manager'
end
Add the Test Session Manager middleware to config/application.rb
:
if Rails.env.test?
# initialize the manager that your tests will use
manager = TestSessionManager.new
# set it in your application's config, so your tests can find it
config.test_session_manager = manager
# install the middleware
config.middleware.use TestSessionManager::Middleware, manager
end
Add a minimal helper to your tests:
class ActiveSupport::TestCase
# ...
def next_request
Rails.application.config.test_session_manager
end
end
Then, use the next_request
helper to set session and flash values in your tests!
test 'show that session and flash can be set in tests' do
next_request.flash[:error] = "Something died!"
next_request.session[:favorite_color] = "green"
get '/path/to/test'
assert_select '.alert-error', 'Something died!'
assert_select '.favorite-color', 'green'
end
Test Session Manager is released under the MIT license (see MIT-LICENSE) by Jamis Buck (jamis@jamisbuck.org).
FAQs
Unknown package
We found that test_session_manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.