简体   繁体   English

rspec密码测试失败

[英]rspec password test failing

I've been racking my brain trying to figure this out. 我一直在绞尽脑汁想办法解决这个问题。 I'm not sure why, but for some reason my password digest hash isn't matching up. 我不确定为什么,但是由于某种原因,我的密码摘要哈希值不匹配。 When I run the test I get this error: 当我运行测试时,出现以下错误:

expected: password_digest: "$2a$04$cDKhuWzsZuW8Gm4t5fJjpu6rmbwh10ZAt2Yae.BO0iuD...">
got: password_digest:      "$2a$04$jwfHjoLI0RpDIAEr9SMKGOZqeH.J5ILOkzalKCYQdDW4...">

I should note that the application code works just fine. 我应该注意,应用程序代码可以正常工作。 I can call create a user and authenticate it with user.authenticate('foobar') in the console and it'll work as expected. 我可以在控制台中调用create user并使用user.authenticate('foobar')对其进行身份验证,它将按预期工作。 I have dropped and redone my database numerous times with the same results. 我删除并重做数据库多次,但结果相同。

Here's my test: https://gist.github.com/DavidVII/f190d1f1e114234bb7d7#file-user_spec-rb-L107 这是我的测试: https : //gist.github.com/DavidVII/f190d1f1e114234bb7d7#file-user_spec-rb-L107

The part that is failing is the line 107. I'm using bcrypt with has_secure_password . 发生故障的部分是第107行。我将bcrypt与has_secure_password

I'm really new to testing and would really appreciate some details on how to go about getting this test to pass. 我真的是测试的新手,并且非常感谢有关如何通过此测试的一些详细信息。

My password hash just keep being recreated each time and I don't know how to get it to stop. 每次都会重新创建我的密码哈希,但我不知道如何停止它。

Any help would be much appreciated. 任何帮助将非常感激。

Thnx! 谢谢!

As it turns out @user was being generated with each run. 事实证明,每次运行都会生成@user。 I installed the database_cleaner gem and now I've got it working wonderfully. 我安装了database_cleaner gem,现在我可以正常运行了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM