以下控制器测试失败,我不知道为什么:
describe "GET 'index'" do
before(:each) do
@outings = FactoryGirl.create_list(:outing, 30)
@user = FactoryGirl.create(:user)
end
it "should be successful" do
get :index
response.should be_success
end
end
Rspec 提供了(相当无用的)错误:
Failure/Error: response.should be_success
expected success? to return true, got false
这也是实际控制器的代码:
def index
if @user
@outings = Outing.where(:user_id => @user.id)
@outing_invites = OutingGuest.where(:user_id => @user.id)
else
flash[:warning] = "You must log in to view your Outings!"
redirect_to root_path
end
end
任何人都知道是什么导致我的测试失败?我认为它可能与 Outing Controller 中的条件有关,但我不知道通过测试会是什么样子......