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

Oliver Jesus oliverjesus2008 at yahoo.com
Fri Jun 7 10:02:43 UTC 2013


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 }       
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130607/833281b3/attachment-0001.html>


More information about the rspec-users mailing list