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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:08:23+00:00 2026-05-31T13:08:23+00:00

In my (Rails 3.2) Test::Unit controller/functional tests, assert_routing is failing with this error: 1)

  • 0

In my (Rails 3.2) Test::Unit controller/functional tests, assert_routing is failing with this error:

  1) Error:
test: with an admin user routing should route GET /admin/contracts to/from {:action=>"index", :controller=>"admin/contracts"}. (Admin::ContractsControllerTest):
NoMethodError: undefined method `authenticate!' for nil:NilClass

with route:

authenticate :admin do
  namespace :admin do
    resources :contracts
  end
end

I’m setting up Devise 2.0 authentication in my controller tests:

admin = Factory.create(:admin)
admin.confirm!
@request.env["devise.mapping"] = Devise.mappings[:admin]
sign_in :admin, admin

This answer Stubbing Warden on Controller Tests indicates that rack may be authenticating even before my application runs. Which is strange, because my controller tests are running and should have already setup the env variable. But at the time authenticate is called, request.env["warden"] is nil.

Is that the case, that rack is running before the Devise helper sets up the env variable? And if so, how do I setup authentication before rack checks my routing file? My other asserts pass, but assert_routing seems to be a special case.

edit:

I verified that my setup is running before the call to #authenticate and Devise is indeed initializing request.env[‘warden’] with a Warden::Proxy object, but when #authenticate is called, `request.env[‘warden’] is nil. Does that mean that rack is running in a separate thread or something. So confusing, I’m sure I’m doing something wrong. -_-

  • 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-31T13:08:24+00:00Added an answer on May 31, 2026 at 1:08 pm

    Controller (functional) tests are supposed to remain at the controller level and do not have access to the lower level environment state. So request.env['warden'] is mocked in Devise::TestHelper so that controller level tests can pass, but when Rack runs the request.env hash is nil and the route fails with the above error.

    This is the beauty and the beast of authenticating in routes.rb: we don’t have to worry about authentication at the controller level, but neither can we test our routes at the controller level. At least not at this point (in Rails 3.2) as it’s a limitation of Rails.

    See the closed issue https://github.com/plataformatec/devise/issues/1670

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

Sidebar

Related Questions

I am getting this error when running some unit tests (using the Test::Unit module
Ruby 1.8.6, Rails 2.2.2, OS X Tiger My Test::Unit tests started returning the error
I am running my tests for a rails application using test/unit and capybara. I
I have a set of Test::Unit tests for a Rails application. It was developed
I'm writing some ruby (not Rails) and using test/unit with shoulda to write tests.
Looking at the Rails Guides http://guides.rubyonrails.org/testing.html#integration-testing-examples and this SO question Rails Functional Test of
I am using RSpec, but Rails insists on generating Test::Unit tests. Maybe there is
I'm new to rails and I'm trying to test a controller with rspec. My
When I execute a Rails unit test from the command line (as suggested here
my Ruby On Rails unit-test fails in a simple string comparison and I can't

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.