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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:20:12+00:00 2026-05-28T01:20:12+00:00

Here is my little problem that makes me feel stupid. I’m testing my rails

  • 0

Here is my little problem that makes me feel stupid. I’m testing my rails application with RSpec and I also have devise controller helper (grabbed from the Devise wiki, note user default parameter):

module ControllerMacros
  module ControllerHelpers
    def sign_in(user=mock_model(User))
      if user.nil?
        request.env['warden'].stub(:authenticate!).
          and_throw(:warden, {:scope => :user})
        controller.stub :current_user => nil
      else
        # Lots of user.stub here
        controller.stub :current_user => user
      end
    end
  end

  RSpec.configure do |config|
    config.include Devise::TestHelpers, :type => :controller
    config.include ControllerHelpers, :type => :controller
  end
end

Now when I use sign_in in one context of my controller test everything works fine:

context "Authorized access" do
    before(:each) do
      mocked_user = mock_model(User)
      mocked_user.stub(:is?).with(:admin).and_return(true)
      sign_in(mocked_user)
      # some checks 
    end
end

But in another context (in the same spec) I’m getting “wrong number of arguments (2 for 1)“:

context "Unauthorized access" do
 before(:each) do
   sign_in(nil)
 end

# test cases
end

And it’s rather confusing for me, because I’m passing only one(nil) argument. I’ll be glad to hear any suggestions, because these two calls look the same for me. Maybe I`m missing something.

UPDATE:

  1. Rails 3.1.0
  2. ruby 1.9.3p0 (2011-10-30 revision 33570)
  3. RSpec 2.7.1

UPDATE 2(error example):

 Failure/Error: sign_in(nil)
   ArgumentError:
   wrong number of arguments (2 for 1)
   # ./spec/support/controller_macros.rb:5:in `sign_in'
   # ./spec/controllers/forum/topics_controller_spec.rb:93: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-05-28T01:20:13+00:00Added an answer on May 28, 2026 at 1:20 am

    The error will be coming from the line

    request.env['warden'].stub(:authenticate!).and_throw(:warden, {:scope => :user})
    

    RSpec versions lower than 2.8 did not support parameters for and_throw. Update the Gemfile to use RSpec 2.8.0 and let me know how you get on.

    I remember I used a simpler method for controller tests

    before do
      controller.stub(:authenticate!).and_return(mock_model('user'))
    end
    

    That way you are bypassing Devise altogether which is well tested

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

Sidebar

Related Questions

I have a little problem with javascript form submit issue, here is the script
I need a little push in the right direction. Here's my problem: I have
I'm new around here and i have a little problems with a C# application.
I'm having a little problem here, I'm new to Actionscript 3, and what I'm
I'm having a little bit of trouble understanding what the problem is here. I
I have a litte problem here. I want to join twice from the same
A little stuck here. I have a simple question I guess. Given the following
Just a little confused here... I have a function in postgres, and when I'm
First things first, here is a little snippet code to help explain my problem:
Here is an interesting optimization problem that I think about for some days now:

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.