I suspect I just being very dumb with this and missing something obvious. But I fairly new to rspec and factory girl and cannot get this simple test to work.
Basically I have set up a model called page and am calling it in the controller like this:
@pages = Page.where(:page_type => "homepage").limit(2)
for in my test I do the following:
before do
@pages = [Factory(:page), Factory(:page, :title=> "Contact", :content=>"contact content", :meta=>"meta content", :page_type=>'homepage') ]
get 'index'
end
it 'should set the pages variable' do
assigns[:pages].should_not be_nil
assigns[:pages].length == 2;
end
yet all I get is:
Failure/Error: assigns[:pages].should_not be_nil
expected not nil, got nil
ANy help greatly appreciated
Your controller is setting its
@pagesinstance variable to nil. Most likely it’s not being assigned to at all. Are you sure the code snippet which you pasted:is being called in the
indexaction of your controller? If so, that code would set@pagesto the empty list, not nil.