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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:02:39+00:00 2026-05-19T10:02:39+00:00

Im still trying to figure out rspec and right now I am using authlogic

  • 0

Im still trying to figure out rspec and right now I am using authlogic to handle my users and sessions. I did the usual authlogic stuff like adding the def current_user method to applciation controller, and as a helper method, but how do I access that in my rspec controller file?

Here is my user_sessions_controller_spec.rb:

require 'spec_helper'
require 'authlogic'

describe UserSessionsController do

  context "user is already logged in" do

    before(:each) do
      include Authlogic::TestCase
      activate_authlogic
      UserSession.create Factory.build(:user)
    end

    it "should redirect the user to the home page" do
      get 'new'
      response.should redirect_to(home_path)
    end

  end

  describe "#create" do
    context "when the user is not logged in" do    
      before(:each) do
        current_user = nil
      end

      it "correct authorization should create a new session" do
        post 'create', {:login => "afactoryuser", :password => "apass", :password_confirmation => "apass"}
        current_user.should_not be_nil
      end
    end
  end

end

when i run rspec it just tells me:

correct authorization should create a new session
undefined local variable or method `current_user' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1:0x000001017d3410>

so im guessing it is in the rspec context…but how do i know it should be in user-sessions_controller? And am I even testing it correctly?

  • 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-19T10:02:39+00:00Added an answer on May 19, 2026 at 10:02 am

    Insted of current_user in your RSpec, try controller.current_user

    If you want to stub current_user method use: controller.stub!(:current_user).and_return(whatever) in before :each
    block, but then you will always get whatever if you stub it.

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

Sidebar

Related Questions

I am still trying to figure out the right architecture for a complex ASP.NET
I'm using EF 4.1 and still trying to figure out some of the details.
After so many years using ASP.Net, I’m still trying to figure out how to
Still trying to figure this out from yesterday. I am trying to scroll an
In trying to figure out this problem (which is still unsolved and I still
I am still trying to figure out frame animation, but I need to use
I'm new to haml, so I'm still trying to figure out the formatting. I
I'm trying to figure out how to capture data from a form using EditText
Still trying to figure out date with PHP. I have this: $fri_end_date = date('Y-m-d',strtotime('Friday'));
I am still trying to figure out, why i cannot apply HTML formatting in

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.