十一 28

带着restful_authentication运行rspec时,貌似cookies无效的问题

起因:在未做自己开发rspec的时候,只是调试下安装完 restful_authentication 的rspec和部分test时候,出现了几个错误:

1、

Spec::Mocks::MockExpectationError in 'SessionsController Logging in by cookie fails cookie login with bad cookie'
fails cookie login with bad cookie(Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_4) expected :cookies with (any args) once, but received it 0 times
./spec/controllers/authenticated_system_spec.rb:85:

2、

'SessionsController Logging in by cookie logs in with cookie' FAILED
expected true, got false
./spec/controllers/authenticated_system_spec.rb:81:

3、

'AccessControlTestController requesting xml; I am logged in and Login is required succeeds' FAILED
expected "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <success>xml</success>\n</hash>\n", got "HTTP Basic: Access denied.\n"
./spec/controllers/access_control_spec.rb:65:

这是为什么呢?

经过N个小时的思考和google,还是没有发现问题,但是刚才检查 logged_in?.should be_true 一句时,发现我在application_helper.rb里 竟然定义了个同名的方法。就是这个同名方法,搞乱了正常的测试结果。so,改名后,一切都正常了。

经验:1、学习和使用TDD开发还是需要时间的,2、下次应该不会犯了吧。。。。

  • 标签 : 
  • 原文链接 : http://railser.cn/blog/restful_authentication-rspec-fails
  • 转载原创文章请注明 : 里克的自习室
  • 收藏到 : Google书签 新浪ViVi 365Key网摘 天极网摘 我摘 POCO网摘 博采网摘 YouNote网摘 和讯网摘 博拉网 igooi网摘 I2Key网摘 天下图摘 百特门网摘 Del.icio.us Yahoo书签 奇贴 QQ娱乐摘 添加到Digg! 添加到Facebook!
  •  “带着restful_authentication运行rspec时,貌似cookies无效的问题”才1条评论

    1. gravatar

      你得搞清楚 rails 的各个文件目录加载顺序

    发表留言