我编写了一个断言失败的单元测试——我想找出原因,而不必检查模型的每个属性。
这是我的测试:
test "a correct document should be saved" do
document = documents(:one)
document.pdf = File.new("test/files/document_test_file.pdf")
assert document.save
end
这是夹具:
one:
user_id: 1
title: MyString
published_on: 2012-12-06
tags: MyText
language: MyString
显然,缺少某些内容并且无法保存文档。但是我如何找出究竟缺少什么?是否有任何高级断言方法可以做到这一点?
我的模型:
class Document < ActiveRecord::Base
attr_accessible :language, :pdf, :pdf_file_name, :published_on, :tags, :title, :user_id
# Validations
validates_presence_of :language, :published_on, :tags, :title, :user
validates_date :published_on, on_or_before: Date.current,
on_or_before_message: "must be today or earlier"
validates :user_id, numericality: { only_integer: true, greater_than: 0 }
validates :pdf, attachment_presence: true
# Relations
belongs_to :user
# Paperclip
has_attached_file :pdf
end