RSpec-2 和设计
我创建了一个定制的设备注册控制器,我想用 rspec 来测试它。
我已经尝试过一个非常简单的测试:
it "creates a new parent" do
Parent.should receive(:new)
post :create
end
但我得到了这个例外:
Failures:
1) Parent::RegistrationsController POST create creates a new parent
Failure/Error: post :create, { :commit => "Daftar",
uncaught throw `warden'
# /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16:in `throw'
# /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16
我已经将这一行放入我的测试中:
describe Parent::RegistrationsController do
include Devise::TestHelpers
end
我也已经将这一行放入:
request.env["devise_mapping"] = Devise.mappings[:parent]
有人有解决这个问题的想法吗?
i create a customized devise registration controller and i want to test it with rspec.
I've tried it with a very simple test :
it "creates a new parent" do
Parent.should receive(:new)
post :create
end
but i get this exception:
Failures:
1) Parent::RegistrationsController POST create creates a new parent
Failure/Error: post :create, { :commit => "Daftar",
uncaught throw `warden'
# /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16:in `throw'
# /home/starqle/.rvm/gems/ree-1.8.7-2010.02/gems/devise-1.1.3/lib/devise/hooks/timeoutable.rb:16
I already put this line within my test:
describe Parent::RegistrationsController do
include Devise::TestHelpers
end
I also already put this line:
request.env["devise_mapping"] = Devise.mappings[:parent]
anybody have ideas to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我之前的回答有点令人困惑。对不起。
更新的答案:根本原因是用户在“登录”之前未“确认”。
那么一切都很好。
My previous answer is a little confusing. sorry.
Updated answer: root cause is user is not "confirmed" before "sign in".
then everything is fine.
我对红宝石比较陌生。
我正在将 Rails 3 与 devise 和 Factory Girl 一起使用。
我正在寻找如何对 rspec 的用户进行身份验证。
我被困在 before_filter:authenticate_user!在控制器中。
终于找到解决方案了(感谢沉思伟)
我正在做的是
2 中。
I am fresher in ruby.
I am using rails 3 with devise and factory girl.
I was searching for how to authenticate user for rspec.
I was stucked at before_filter: authenticate_user! in controller.
Finally I got solution (thanks to Siwei Shen)
What I am doing is
2.