如何使用 rSpec 在 Rails 3 中存根 Devise。我有一个UsersController
and a User
模型。目前,这两者都与 Devise 相关,我正在编写控制器规格,但我真的很难实现作为 Devise 的期望sign_in
实在是太耽误工作了。
任何事情都会有所帮助。
我发现现在做到这一点非常容易。 rspec2 和 devise 存在问题,但现已解决。我猜你需要更新你的宝石。然后你可以写
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
[更新] 在设计维基上现在有一个详细的(并且可能是最新的)描述 https://github.com/plataformatec/devise/wiki/How-To:-Controllers-tests-with-Rails-3-(and-rspec).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)