4

I'm getting the following error:

undefined method `assign' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000010597f4b8>

When attempting to test per the docs.

Here's is what I have:

user_controller_spec.rb

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 => "post",
                                  :action => user_session_path
                                  ) do |form|
      form.should have_selector("input", :type => "submit")
    end
  end
end

Suggestions? Thanks

1 Answer 1

4

Rspec has changed a bit, it's now using assigns.

Doc here.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, would love to get your feedback on my follow-up question. I'm really lost on how to get started and right tests for devise: stackoverflow.com/questions/7223549/…
When changing to assigns it still errors with: Failure/Error: assigns(:user, user) ArgumentError: wrong number of arguments (2 for 1)
So I changed it to: assigns[:user] = user which causes it to now error on undefined local variable or method `render' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x000001051c5f38>
You use deprecated methods, browse the doc here: rspec.info/rails/writing/controllers.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.