rspec - shoulda-matchers 不匹配
问题描述
我正在创建一个 TextMessage 模型来管理通信。我正在使用shoulda-matchers进行测试
我的模型
class TextMessage < ApplicationRecord
validates :message, presence: true
end
现在我的测试
RSpec.describe TextMessage, type: :model do
subject { FactoryBot.create(:text_message) }
it { is_expected.to validate_presence_of :message }
end
我可以在控制台上运行 FactoryBot.create(:text_message) 来创建一条没有任何问题的文本消息。但是当我运行我的测试时,我得到了这个错误
TextMessage
is expected to validate that :message cannot be empty/falsy (FAILED - 1)
Failures:
1) TextMessage is expected to validate that :message cannot be empty/falsy
Failure/Error: self.message = message.gsub("\u0000", '')
NoMethodError:
undefined method `gsub' for nil:NilClass
解决方案
推荐阅读
- excel - microsoft excel 运行时错误 1004 - 兼容性问题
- javascript - 动态访问 Vuex store 的一个 prop
- python - 将变量从烧瓶传递到html时我做错了什么
- celery - 在 Apache Airflow 中从 Sequential executor 升级到 Celery executor
- php - Laravel AUTH() - 添加其他用户(无需注册)
- javascript - 如何正确隐藏 CSS 网格中的单元格?
- java - 使用 PayPal Java 完成支付过程并获取是否成功完成的状态
- sql - 错误 - 函数中包含的 Select 语句无法将数据返回给客户端
- angular - 如何在模板中共享函数结果?
- swift - iOS View 中的 MVC 设计与模型对话 - Swift - 以编程方式