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 7018961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:07:12+00:00 2026-05-27T23:07:12+00:00

I want to stub out a logged in user (with Devise/Warden) using rspec mocks

  • 0

I want to stub out a logged in user (with Devise/Warden) using rspec mocks in a Capybara test suite in my Rails app. This would save a ton of time, and would mean that my test suite can/will be run regularly.

Previously I was able to do this using authlogic by stubbing out my session model with some code like this:

def login(user)
  user_session = mock_model(UserSession, {:user => user})
  UserSession.stub(:find).and_return(user_session)
end

Now that i’m using Devise, i no longer have access to a UserSession object. And since i’m using capybara to test my code, i don’t have direct access to the request object to use devise’s built in sign_in test helper.

My question is: how can I simulate a logged in user with capybara, devise, and spec mocks without requiring every scenario with a logged in user to first go to the sign up path, fill in the form, submit, wait for response, and then go to the desired page?

  • 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-27T23:07:13+00:00Added an answer on May 27, 2026 at 11:07 pm

    Warden comes with built in test helpers. It allows you to login without having to use the UI in your cucumber tests. Just add the files below into your project.

    # features/support/warden.rb

    Warden.test_mode!
    World Warden::Test::Helpers
    After { Warden.test_reset! }
    

    # features/step_definitions/user_steps.rb

    Given /^I am logged in as a user$/ do
      @current_user = User.create!(:username => 'user', :password => 'password')
      login_as(@current_user, :scope => :user)
    end
    

    Use Wardens.test_mode! with Capybara

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

Sidebar

Related Questions

I want to find out that the screen is OFF when user locked a
I want to stub out the space_available_mb method in SubmissionsController so that it returns
I want to use RSpec mocks to provide canned input to a block. Ruby:
I want to use stub entities but it seems I cannot use TryGetObjectStateEntry without
want to know why String behaves like value type while using ==. String s1
want to ask user to input something but not want to wait forever. There
I want to call haskell functions out of C++ and did use the tutorial
I am currently struggling with stubbing out a helper method of my Sinatra app
I want to make an SMS scheduling app, that sends SMS at predefined time.
Background: So I have roughly (Ruby on Rails app) class A def calculate_input_datetimes #

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.