Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:31:45+00:00 2026-05-27T22:31:45+00:00

I am using rspec and capybara for integration testing. Is their a way to

  • 0

I am using rspec and capybara for integration testing.

Is their a way to make session objects in request specs?

I have a view page in which I use a session object to check its value to display selective content.

The problem am facing is that I cannot create a session object in request spec.
Here is an example of the view:

<% if session[:role] == "Role" %>
---content---
<% else %>
--content--
<% end %>

And inside my request spec

session[:role] = "Role"
visit my_path

But it throws me an error “undefined method `session’ for nil:NilClass”.

I also tried looking into creating session objects of capybara.But couldnt find anything.

Is their any workaround for this? I can not find anything related to this, it seems that it is not possible.A little help is really appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:31:46+00:00Added an answer on May 27, 2026 at 10:31 pm

    The way you are supposed to do request specs is visit whatever URL the user would normally need to visit in order for that session variable to be set.

    I don’t know of any other way, other perhaps than setting the session cookie by hand. Capybara.current_session.driver.browser.set_cookie let’s you do this but you would have to create the cookie value by hand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using Capybara for integration/request testing, but have only just realised I can't
I have a set of request specs written using RSpec2 and Capybara. Here's one
Im using capybara for my integration/acceptance tests. They're in /spec/requests/ folder. Now I have
I'm using rspec, cucumber and capybara and I'm looking for a way to test
I´m testing my rails app using rspec and remarkable. I have the following spec
Configuration: Integration tests for Rails project using RSpec, Capybara, Selemium driver, SQLite database. Situation:
I'm setting up some integration tests using capybara and rspec. In a single test,
My project is using Rails 3 and RSpec and Capybara for testing. I want
I'm using RSpec/Capybara as my test suite. I have some javascript that dynamically appends
I'm using rails-rspec gem and I have several specs (models, controllers, etc). When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.