问题描述
您将如何使用 rSpec 在 Rails 3 中存根设计.我有一个 UsersController
和一个 User
模型.目前这两者都与 Devise 相关,我正在编写控制器规范,我真的很难满足我的期望,因为 Devise sign_in
真的很忙.
How would you stub Devise in Rails 3 with rSpec. I have a UsersController
and a User
model. Both of which are associated with Devise at the moment, I'm writing controller specs and I really am having a hard time with my expectations as the Devise sign_in
is really jamming up the works.
任何事情都会有所帮助.
Any thing will help.
推荐答案
我发现现在很容易做到这一点.rspec2 和设计存在问题,但现在已解决.我想你需要更新你的宝石.然后你就可以写
I found that it is now pretty easy to do this. There was a problem with rspec2 and devise, but is now solved. I guess you would need to update your gems. Then you can write
require 'spec_helper'
describe DoStuffController do
include Devise::TestHelpers
before (:each) do
@user = Factory.create(:user)
sign_in @user
end
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end
end
[更新] 在设计维基上,现在有一个详细的(可能是最新的)描述.
[UPDATE] On the devise wiki there is now a detailed (and probably more up-to-date) description.
这篇关于rSpec 和 Rails3 中的存根设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!