【发布时间】:2021-10-01 16:55:16
【问题描述】:
我开始在 Rails 中使用 minitest 进行测试。目前,我第一次测试我的模型是否有效是返回 false。错误信息本身也很笼统Expected false to be truthy。我已经测试了其他所有东西,所有这些测试都运行良好。有人知道是什么原因造成的吗?
article_test.rb
require 'test_helper'
class ArticleTest < ActiveSupport::TestCase
def setup
@article = Article.new(title:"Avengers Endgame", body:"I am inevitable")
end
test "article should be valid" do
assert @article.valid?
end
test "title should be present" do
@article.title = " "
assert_not @article.valid?
end
test "body should not be too short" do
@article.body = "aa"
assert_not @article.valid?
end
end
article.rb
class Article < ApplicationRecord
include Visible
belongs_to :user
has_many :comments, dependent: :destroy
has_rich_text :body
validates :title, presence: true
validates :body, presence: true, length: { minimum: 10 }
end
【问题讨论】:
标签: ruby-on-rails ruby minitest