小编cod*_*oda的帖子

测试 rspec 中的字符串数组中是否存在子字符串

json[:errors] = ["Username can't be blank", "Email can't be blank"]
Run Code Online (Sandbox Code Playgroud)

en.yml 中的错误本身提供为:

username: "can't be blank",
email: "can't be blank"
Run Code Online (Sandbox Code Playgroud)

和测试:

expect(json[:errors]).to include t('activerecord.errors.messages.email')
Run Code Online (Sandbox Code Playgroud)

失败是因为它正在查看字符串“电子邮件不能为空”,而“不能为空”与它不匹配。

我的问题是测试子字符串是否包含在数组 json[:errors] 中包含的字符串中的最佳(我的意思是最佳实践)方法是什么

rspec ruby-on-rails

3
推荐指数
1
解决办法
2085
查看次数

标签 统计

rspec ×1

ruby-on-rails ×1