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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:56:19+00:00 2026-06-11T04:56:19+00:00

I’m using padrino and rspec and I’d like to be able to test a

  • 0

I’m using padrino and rspec and I’d like to be able to test a helper method that I wrote.

I have

spec/app/controllers/sessions_controller_spec.rb

    describe "POST /sessions" do
    it "should populate current_user after posting correct user/pass" do

      u = User.create({:email=>"john@gmail.com", :password=>"helloworld", :password_confirmation=>"helloworld"})

      user = { 
        email:"john@gmail.com",
        password:"hellowolrd"
      }   
      post '/sessions/new', user
      current_user.should_not == "null"
    end 
  end 

app/controllers/sessions_controller.rb

  post "/new" do
    user = User.authenticate(params[:email], params[:password])
    if user
      session[:user_id] = user.id
      redirect '/' 
    else
      render "sessions/new"
    end 
  end 

app/helpers/sessions_helper.rb

Testing.helpers do
  def current_user
    @current_user ||= User.find(:id=>session[:user_id]) if session[:user_id]
  end 
end

So this is really a two-part question. First part is that my method current_user is not even found. Second, I believe if it were found, it might throw errors as to session not being defined. But first things first, why am i getting undefined_method current_user?

Failures:

  1) SessionsController POST /users should populate current_user after posting correct user/pass
     Failure/Error: current_user.should_not == "null"
     NameError:
       undefined local variable or method `current_user' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x0000000313c0d8>
     # ./spec/app/controllers/sessions_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
  • 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-06-11T04:56:20+00:00Added an answer on June 11, 2026 at 4:56 am

    This was answered in their issue tracker: https://github.com/padrino/padrino-framework/issues/930#issuecomment-8448579

    Cut and paste from there:

    Shorthand helpers (this is a Sinatra, not a Padrino feature, by the way) are hard to test for a reason:

    MyApp.helpers do
      def foo
    
      end
    end
    

    is a shorthand for:

    helpers = Module.new do
      def foo
      end
    end
    
    MyApp.helpers helpers
    

    So the problem for testability is obvious: the helpers are an anonymous module and its hard to reference something that is anonymous. The solution is easy: make the module explicit:

    module MyHelpers
      def foo
      end
    end
    
    MyApp.helpers MyHelpers
    

    and then test it in any fashion you want, for example:

    describe MyHelpers do
      subject do
        Class.new { include MyHelpers } 
      end
    
      it "should foo" do
        subject.new.foo.should == nil
      end
    end
    

    Also, your example doesn’t work because it assumes that helpers are global, which they are not: they are scoped by application.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.