ruby on rails-单元测试失败(自定义验证方法)



这是我的模型验证

validate :validate_mark_cheat
def validate_mark_cheat
  if (self.student_from_id == self.student_to_id)
    errors.add(:student_from_id, "a mark can't be self-asign")
    errors.add(:student_to_id, "a mark can't be self-asign")
  end
end

这是我的单元测试

test "Mark can't be self-given" do
  mark = Mark.new(:student_from_id => 1, :student_to_id =>1)
  assert mark.invalid?
  assert mark.errors[:sudent_from_id].any?
  assert mark.errors[:student_to_id].any?
end

我不明白为什么我的测试没有通过

感谢

你意识到你在测试中拼错了:student_from_id吗?

最新更新