1

I am new on Rails and Rspec. My Rspec file is not taking a Controller's property(as-instance variable)

assigns[:portal_news].should be_new_record

It always gives the error:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.new_record?

Can anyone find the solution to this problem?

2 Answers 2

2

You're treating assigns as a hash, but it is a method that takes an argument: assigns(:portal_news).

More info: http://guides.rubyonrails.org/testing.html

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

Comments

0

Your controller method should be creating a new instance of your model and assigning it to @portal_news`, maybe something like this:

@portal_news = MyModel.new

We'll need to see the contents of the relevant controller method, and of the failing spec, to be able to help you figure this out.

4 Comments

In controller code : @portal_news=PortalNews.new is mentioned .but portal_news variable could not access in portal_news_controller_spec file. Please find the solution
There are several possibilities. Do you have any before_filters that could be preventing the assignment statement from being reached? Do you get the same error when trying to access the page in your browser?
thanks for reply. In controller i already commented all filters.but After that it still not working.I installed rspec(2.1.0) and rspec-rails(2.1.0) on rails 2.3.5
Please anyone find the solution

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.