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] 中包含的字符串中的最佳(我的意思是最佳实践)方法是什么