New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

test_session_manager

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test_session_manager

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Test Session Manager

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.

Installation, Configuration, and Usage

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

License

Test Session Manager is released under the MIT license (see MIT-LICENSE) by Jamis Buck (jamis@jamisbuck.org).

FAQs

Package last updated on 28 Nov 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc