I just got an existing application to support (unfortunately no tests at all) and I’m in the processing of specing out a new feature they want. Everything’s going along fine: I created the controller and the model and started my first tests on the controller but have run into what I guess is a head-slapper of a problem that I can’f figure out:
Controller spec
require 'spec_helper'
describe Manage::FeaturedCompaniesController do
describe "GET index" do
it "assigns @featured_companies" do
featured_company = FeaturedCompany.create
get :index
expect(assigns(:featured_companies)).to eq([featured_company])
end
it "renders the index template" do
get :index
expect(response).to render_template('index')
end
end
end
Controller
class Manage::FeaturedCompaniesController < Manage::BaseController
def index
@featured_companies = FeaturedCompany.find(:all)
end
end
Error Message
1) Manage::FeaturedCompaniesController GET index assigns @featured_companies
Failure/Error: expect(assigns(:featured_companies)).to eq([featured_company])
expected: [#<FeaturedCompany id: 1>]
got: nil
(compared using ==)