在我的代码中,我使用了Shoulda匹配器进行以下验证,它运行良好:
在我的模型中,我已经添加了验证条件:
it { should validate_presence_of(:name) }
在我的模型中,我已经添加了验证条件:
validates_presence_of :name, :if => eligible?
你能否在验证中反映它?
我已经尝试查看 shoulda matchers 的 documentation, 但还没有找到解决方案。
非常感谢!
before { allow(subject).to receive(: eligible?).and_return(true) }
的意思是在测试运行之前,将对subject
的eligible?
方法的调用替换为返回true
。 - Raf