title: Rails 3 + Devise + Rspec - undefined method error in Controller test
body: <p>I have such <strong>spec</strong> (spec/controllers/stats_controller_spec.rb) to test my controller:</p>
  
  <pre><code>require 'spec_helper'
  
  describe StatsController do
    render_views
  
    before(:each){ @user = FactoryGirl.create( :user ) }
  
    describe "GET 'users_in_system'" do
      describe "for non-signed users" do
        it "should deny access" do
          get :users_in_system, :locale =&gt; :en
          #...
        end
      end
    end
  end
  </code></pre>
  
  <p>When i run this spec i get such <strong>error</strong>:</p>
  
  <pre><code>1) StatsController GET 'users_in_system' for non-signed users should deny access
       Failure/Error: get :users_in_system, :locale =&gt; :en
       ActionView::Template::Error:
         undefined method `authenticate' for nil:NilClass
       # ./app/views/layouts/_navbar_template.html.haml:16:in `_app_views_layouts__navbar_template_html_haml__2938837959272005060_70149962955560'
       # ./app/views/layouts/application.html.haml:12:in `_app_views_layouts_application_html_haml__243298846079092947_70149956982200'
       # ./spec/controllers/stats_controller_spec.rb:12:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>I tried to solve this error by adding this line to (spec/spec_helper.rb):</p>
  
  <pre><code>#...
  
  RSpec.configure do |config|
    config.include Devise::TestHelpers, :type =&gt; :controller
    #...
  end
  </code></pre>
  
  <p>Then i started to get such error:</p>
  
  <pre><code>1) StatsController GET 'users_in_system' for non-signed users should deny access
       Failure/Error: Unable to find matching line from backtrace
       NoMethodError:
         undefined method `env' for nil:NilClass
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/devise-2.1.0/lib/devise/test_helpers.rb:33:in `warden'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-rails-2.10.0/lib/rspec/rails/adapters.rb:15:in `block (2 levels) in setup'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:178:in `instance_eval'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:178:in `instance_eval'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/hooks.rb:23:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/hooks.rb:63:in `block in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/hooks.rb:63:in `each'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/hooks.rb:63:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/hooks.rb:400:in `run_hook'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:298:in `run_before_each_hooks'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:239:in `run_before_each'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:86:in `block in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:195:in `with_around_each_hooks'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:84:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:353:in `block in run_examples'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:349:in `map'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:349:in `run_examples'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:335:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `block in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `map'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `block in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `map'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:336:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `map'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `block in run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/reporter.rb:34:in `report'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:25:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
       # /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'
  </code></pre>
  
  <p>I tried to add that (spec/controllers/stats_controller_spec.rb):</p>
  
  <pre><code>describe StatsController do
    render_views
    include Devise::TestHelpers
    #...
  end
  </code></pre>
  
  <p>But that changed nothing. How can i repair that?</p>
  
  <p><strong>UPD</strong>:
  My stats controller:</p>
  
  <pre><code>class StatsController &lt; ApplicationController
    def users_in_system
      @users = User.all
    end
  end
  </code></pre>
  
  <p>My navbar:</p>
  
  <pre><code>%div{ :class =&gt; "navbar navbar-inverse navbar-fixed-top" }
    %div{ :class =&gt; "navbar-inner" }
      %a{:class =&gt; "btn btn-navbar", "data-toggle" =&gt; "collapse", "data-target" =&gt; ".nav-collapse"}
        %span{:class=&gt;"icon-bar"}
        %span{:class=&gt;"icon-bar"}
        %span{:class=&gt;"icon-bar"}
  
      = link_to t(".brand_name"), root_path, { :class =&gt; "brand" }
      %div{ :class =&gt; "nav-collapse" }
        -# Left navigation.
        %ul{ :class =&gt; "nav" }
          %li=link_to "About", about_path
  
        -# Right navigation.
        %ul{ :class =&gt; "nav pull-right" }
          - if user_signed_in?
            %li=link_to t(".settings"), edit_user_registration_path
            %li{ :class =&gt; "divider-vertical" }
            %li=link_to t(".logout_link"), destroy_user_session_path, :method =&gt; :delete
  </code></pre>