首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails教程9.25测试失败,预期“”为零

Rails教程9.25测试失败,预期“”为零
EN

Stack Overflow用户
提问于 2021-04-03 08:30:52
回答 1查看 36关注 0票数 1

我重发这个问题是因为我在rails教程的这一部分也遇到了问题。我发现了一种不同的解决方法,现在测试通过了,但我想知道,因为我在这方面是如此新手,它是否有相同的效果?

user_login_test.rb

代码语言:javascript
复制
 require 'test_helper'

class UsersLoginTest < ActionDispatch::IntegrationTest

  # I deleted most of the file as Stack kept telling me I was posting too much code and not enough problem.

  test 'Login with remember' do
    log_in_as(@user, remember_me: '1')
    assert_not_nil cookies['remember_token']
  end

  test 'Login without remember' do
    # Log in to set the cookie.
    log_in_as(@user, remember_me: '1')
    # log in again and verify that the cookie is deleted.
    log_in_as(@user, remember_me: '0')

** This seems to be the problem line of code **
    assert_nil cookies['remember_token']

  end
end ```

I replaced it with 

断言cookies“‘remember_token”。空白吗?

代码语言:javascript
复制
test now passes, but am I allowing a bug by not forcing nil or as long as the cookie is blank then its functionality is the same? 

I can add sessions_controller.rb and test_helper.rb if it helps, or any other files that would be helpful. 
EN

回答 1

Stack Overflow用户

发布于 2021-04-03 10:57:41

如果将cookies键值设置为nil,则会被解释为空字符串。

因此,您必须问问自己,应用程序中cookies['remember_token'] = ""的定义是什么。如果在您的上下文中""等同于nil,那么使用#blank?进行断言将是很好的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66926689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档