title: How to test Devise in a Controller RSpec, error: undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>
body: <p>I'm getting the following error:</p>
  
  <pre><code>undefined method `assign' for #&lt;RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8&gt;
  </code></pre>
  
  <p>When attempting to test per <a href="https://github.com/plataformatec/devise/wiki/How-To%3a-Controllers-and-Views-tests-with-Rails-3-%28and-rspec%29" rel="nofollow">the docs</a>. </p>
  
  <p>Here's is what I have:</p>
  
  <p><strong>user_controller_spec.rb</strong></p>
  
  <pre><code>require 'spec_helper'
  
  describe "devise/sessions/new.html.erb" do
    let(:user) do
      stub_model(User).as_new_record
    end
  
    before do
      assign(:user, user)
      # Devise provides resource and resource_name helpers and
      # mappings so stub them here.
      @view.stub(:resource).and_return(user)
      @view.stub(:resource_name).and_return('user')
      @view.stub(:devise_mapping).and_return(Devise.mappings[:user])
    end
  
    it "renders a form to sign the user in" do
      render
      rendered.should have_selector("form",
                                    :method =&gt; "post",
                                    :action =&gt; user_session_path
                                    ) do |form|
        form.should have_selector("input", :type =&gt; "submit")
      end
    end
  end
  </code></pre>
  
  <p>Suggestions? Thanks</p>