[rspec-users] Error uccored while evaluating nil.collect

David Chelimsky dchelimsky at gmail.com
Fri Jun 7 12:51:27 UTC 2013


On Fri, Jun 7, 2013 at 5:02 AM, Oliver Jesus <oliverjesus2008 at yahoo.com>wrote:

> Hello, I am new to RSpec and I've got error something like this:
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.collect
>
> In my controller:
>
> def new
>     @employee_mst = EmployeeMst.new
>     @branch_mst = BranchMst.all(:group => "branch_code")
>     @department_mst = DepartmentMst.all
>
>     respond_to do |format|
>       format.html # new.html.erb
>       format.xml  { render :xml => @employee_mst }
>       format.xml  { render :xml => @branch_mst }
>       format.xml  { render :xml => @department_mst }


I've never seen more than one use of the same format in a respond_to block
like this. I don't know if it's related to your issue, but I'm curious if
you saw this documented somewhere as being supported.


>     end
>   end
>
> In my RSpec controller:
>
>   describe "GET new" do
>     it "assigns a new employee_mst as @employee_mst" do
>       get :new
>       assigns(:employee_mst).should be_a_new(EmployeeMst)
>     end
>   end
>
>
> I think something is missing in RSpec controller, because I've add 4 lines
> of codes:
>      @branch_mst = BranchMst.all(:group => "branch_code")
>      @department_mst = DepartmentMst.all
>       format.xml  { render :xml => @branch_mst }
>       format.xml  { render :xml => @department_mst }
>
> Please help me regarding this error. I greatly appreciated all those
> answers.


Please run the example with the backtrace flag:

    rspec spec/controllers --backtrace

and then post the full backtrace so we can see where that error is being
raised.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130607/0103801d/attachment.html>


More information about the rspec-users mailing list