github上有一些资源How To: Test (devise) with Rails 3 and RSpec。但是如何做是非常高级的,我不能让它在我的上下文中工作。将所有这些部分插入或配置在一起以设法测试需要登录用户的控制器的正确方法是什么(before_filter:authenticate_user!)???
现在我尝试在单个控制器上运行 rspec ..
require File.dirname(__FILE__) + '/../spec_helper'
describe ArticlesController do
fixtures :all
render_views
before (:each) do
@user = Factory.create(:user)
sign_in @user
end
it "index action should render index template" do
get :index
response.should render_template(:index)
end
end
这是我运行 rspec 时的输出
Failures:
1) ArticlesController index action should render index template
Failure/Error: Unable to find matching line from backtrace
SQLite3::ConstraintException: articles.user_id may not be NULL